Browse Source

Fixes stashing staged changes

main
ShafinKhadem 1 year ago
committed by Keith Daulton
parent
commit
dc02b2357a
10 changed files with 49 additions and 19 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +2
    -1
      src/commands/git/stash.ts
  3. +16
    -10
      src/commands/stashSave.ts
  4. +12
    -1
      src/env/node/git/git.ts
  5. +1
    -1
      src/env/node/git/localGitProvider.ts
  6. +9
    -2
      src/git/actions/stash.ts
  7. +1
    -1
      src/git/gitProvider.ts
  8. +1
    -1
      src/git/gitProviderService.ts
  9. +5
    -1
      src/git/models/repository.ts
  10. +1
    -1
      src/plus/github/githubGitProvider.ts

+ 1
- 0
CHANGELOG.md View File

@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Fixes [#2549](https://github.com/gitkraken/vscode-gitlens/issues/2549) - toggle code lens does not work with gitlens.codeLens.enabled == false
- Fixes [#2553](https://github.com/gitkraken/vscode-gitlens/issues/2553) - Can't add remote url with git@ format
- Fixes [#2083](https://github.com/gitkraken/vscode-gitlens/issues/2083), [#2539](https://github.com/gitkraken/vscode-gitlens/issues/2539) - Fix stashing staged changes; thanks to [PR #2540](https://github.com/gitkraken/vscode-gitlens/pull/2540) by Nafiur Rahman Khadem ([@ShafinKhadem](https://github.com/ShafinKhadem))
## [13.3.2] - 2023-03-06

+ 2
- 1
src/commands/git/stash.ts View File

@ -75,7 +75,7 @@ interface PopState {
reference: GitStashReference;
}
type PushFlags = '--include-untracked' | '--keep-index';
export type PushFlags = '--include-untracked' | '--keep-index' | '--staged';
interface PushState {
subcommand: 'push';
@ -519,6 +519,7 @@ export class StashGitCommand extends QuickCommand {
await state.repo.stashSave(state.message, state.uris, {
includeUntracked: state.flags.includes('--include-untracked'),
keepIndex: state.flags.includes('--keep-index'),
onlyStaged: state.flags.includes('--staged'),
});
} catch (ex) {
Logger.error(ex, context.title);

+ 16
- 10
src/commands/stashSave.ts View File

@ -19,6 +19,7 @@ export interface StashSaveCommandArgs {
repoPath?: string;
uris?: Uri[];
keepStaged?: boolean;
onlyStaged?: boolean;
}
@command()
@ -55,16 +56,21 @@ export class StashSaveCommand extends Command {
}
} else if (context.type === 'scm-groups') {
args = { ...args };
args.uris = context.scmResourceGroups.reduce<Uri[]>(
(a, b) => a.concat(b.resourceStates.map(s => s.resourceUri)),
[],
);
args.repoPath = (await this.container.git.getOrOpenRepository(args.uris[0]))?.path;
const status = await this.container.git.getStatusForRepo(args.repoPath);
if (status?.computeWorkingTreeStatus().staged) {
if (!context.scmResourceGroups.some(g => g.id === 'index')) {
args.keepStaged = true;
if (context.scmResourceGroups.every(g => g.id === 'index')) {
args.onlyStaged = true;
} else {
args.uris = context.scmResourceGroups.reduce<Uri[]>(
(a, b) => a.concat(b.resourceStates.map(s => s.resourceUri)),
[],
);
args.repoPath = (await this.container.git.getOrOpenRepository(args.uris[0]))?.path;
const status = await this.container.git.getStatusForRepo(args.repoPath);
if (status?.computeWorkingTreeStatus().staged) {
if (!context.scmResourceGroups.some(g => g.id === 'index')) {
args.keepStaged = true;
}
}
}
}
@ -73,6 +79,6 @@ export class StashSaveCommand extends Command {
}
execute(args?: StashSaveCommandArgs) {
return push(args?.repoPath, args?.uris, args?.message, args?.keepStaged);
return push(args?.repoPath, args?.uris, args?.message, args?.keepStaged, args?.onlyStaged);
}
}

+ 12
- 1
src/env/node/git/git.ts View File

@ -1811,9 +1811,16 @@ export class Git {
{
includeUntracked,
keepIndex,
onlyStaged,
pathspecs,
stdin,
}: { includeUntracked?: boolean; keepIndex?: boolean; pathspecs?: string[]; stdin?: boolean } = {},
}: {
includeUntracked?: boolean;
keepIndex?: boolean;
onlyStaged?: boolean;
pathspecs?: string[];
stdin?: boolean;
} = {},
): Promise<void> {
const params = ['stash', 'push'];
@ -1825,6 +1832,10 @@ export class Git {
params.push('-k');
}
if (onlyStaged) {
params.push('--staged');
}
if (message) {
params.push('-m', message);
}

+ 1
- 1
src/env/node/git/localGitProvider.ts View File

@ -4691,7 +4691,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
repoPath: string,
message?: string,
uris?: Uri[],
options?: { includeUntracked?: boolean; keepIndex?: boolean },
options?: { includeUntracked?: boolean; keepIndex?: boolean; onlyStaged?: boolean },
): Promise<void> {
if (uris == null) {
await this.git.stash__push(repoPath, message, options);

+ 9
- 2
src/git/actions/stash.ts View File

@ -1,4 +1,5 @@
import type { Uri } from 'vscode';
import type { PushFlags } from '../../commands/git/stash';
import { Container } from '../../container';
import { executeGitCommand } from '../actions';
import type { GitStashCommit } from '../models/commit';
@ -26,7 +27,13 @@ export function pop(repo?: string | Repository, ref?: GitStashReference) {
});
}
export function push(repo?: string | Repository, uris?: Uri[], message?: string, keepStaged: boolean = false) {
export function push(
repo?: string | Repository,
uris?: Uri[],
message?: string,
keepStaged: boolean = false,
onlyStaged: boolean = false,
) {
return executeGitCommand({
command: 'stash',
state: {
@ -34,7 +41,7 @@ export function push(repo?: string | Repository, uris?: Uri[], message?: string,
repo: repo,
uris: uris,
message: message,
flags: keepStaged ? ['--keep-index'] : undefined,
flags: [...(keepStaged ? ['--keep-index'] : []), ...(onlyStaged ? ['--staged'] : [])] as PushFlags[],
},
});
}

+ 1
- 1
src/git/gitProvider.ts View File

@ -451,7 +451,7 @@ export interface GitProvider extends Disposable {
repoPath: string,
message?: string,
uris?: Uri[],
options?: { includeUntracked?: boolean | undefined; keepIndex?: boolean | undefined },
options?: { includeUntracked?: boolean | undefined; keepIndex?: boolean | undefined; onlyStaged?: boolean },
): Promise<void>;
createWorktree?(

+ 1
- 1
src/git/gitProviderService.ts View File

@ -2534,7 +2534,7 @@ export class GitProviderService implements Disposable {
repoPath: string | Uri,
message?: string,
uris?: Uri[],
options?: { includeUntracked?: boolean; keepIndex?: boolean },
options?: { includeUntracked?: boolean; keepIndex?: boolean; onlyStaged?: boolean },
): Promise<void> {
const { provider, path } = this.getProvider(repoPath);
return provider.stashSave(path, message, uris, options);

+ 5
- 1
src/git/models/repository.ts View File

@ -1014,7 +1014,11 @@ export class Repository implements Disposable {
@gate()
@log()
async stashSave(message?: string, uris?: Uri[], options?: { includeUntracked?: boolean; keepIndex?: boolean }) {
async stashSave(
message?: string,
uris?: Uri[],
options?: { includeUntracked?: boolean; keepIndex?: boolean; onlyStaged?: boolean },
) {
await this.container.git.stashSave(this.path, message, uris, options);
this.fireChange(RepositoryChange.Stash);

+ 1
- 1
src/plus/github/githubGitProvider.ts View File

@ -2933,7 +2933,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
_repoPath: string,
_message?: string,
_uris?: Uri[],
_options?: { includeUntracked?: boolean; keepIndex?: boolean },
_options?: { includeUntracked?: boolean; keepIndex?: boolean; onlyStaged?: boolean },
): Promise<void> {}
@gate()

Loading…
Cancel
Save