Browse Source

Ensure stash drop matches desired ref

main
Eric Amodio 4 years ago
parent
commit
f949f4da7d
4 changed files with 20 additions and 6 deletions
  1. +1
    -1
      src/commands/git/stash.ts
  2. +15
    -1
      src/git/git.ts
  3. +2
    -2
      src/git/gitService.ts
  4. +2
    -2
      src/git/models/repository.ts

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

@ -386,7 +386,7 @@ export class StashGitCommand extends QuickCommand {
QuickCommand.endSteps(state);
try {
// drop can only take a stash index, e.g. `stash@{1}`
void (await state.repo.stashDelete(`stash@{${state.reference.number}}`));
void (await state.repo.stashDelete(`stash@{${state.reference.number}}`, state.reference.ref));
} catch (ex) {
Logger.error(ex, context.title);

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

@ -1144,8 +1144,22 @@ export namespace Git {
return git<string>({ cwd: repoPath }, 'stash', deleteAfter ? 'pop' : 'apply', stashName);
}
export function stash__delete(repoPath: string, stashName: string) {
export async function stash__delete(repoPath: string, stashName: string, ref?: string) {
if (!stashName) return undefined;
if (ref) {
const stashRef = await git<string>(
{ cwd: repoPath, errors: GitErrorHandling.Ignore },
'show',
'--format=%H',
'--no-patch',
stashName,
);
if (stashRef?.trim() !== ref) {
throw new Error('Unable to delete stash; mismatch with stash number');
}
}
return git<string>({ cwd: repoPath }, 'stash', 'drop', stashName);
}

+ 2
- 2
src/git/gitService.ts View File

@ -3286,8 +3286,8 @@ export class GitService implements Disposable {
}
@log()
stashDelete(repoPath: string, stashName: string) {
return Git.stash__delete(repoPath, stashName);
stashDelete(repoPath: string, stashName: string, ref?: string) {
return Git.stash__delete(repoPath, stashName, ref);
}
@log()

+ 2
- 2
src/git/models/repository.ts View File

@ -589,8 +589,8 @@ export class Repository implements Disposable {
@gate(() => '')
@log()
async stashDelete(stashName: string) {
void (await Container.git.stashDelete(this.path, stashName));
async stashDelete(stashName: string, ref?: string) {
void (await Container.git.stashDelete(this.path, stashName, ref));
if (!this.supportsChangeEvents) {
this.fireChange(RepositoryChange.Stash);
}

Loading…
Cancel
Save