Skip to content

Commit

Permalink
Fixes #589 - Bad revision for stash
Browse files Browse the repository at this point in the history
Stops error logging as stash@{0}^3 is valid if there are untracked files
  • Loading branch information
eamodio committed Dec 13, 2018
1 parent 0799fab commit b1a5a53
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/git/git.ts
Expand Up @@ -205,6 +205,14 @@ function defaultExceptionHandler(ex: Error, options: GitCommandOptions, ...args:
}
}

const match = GitErrors.badRevision.exec(msg);
if (match != null && match) {
const [, ref] = match;

// Since looking up a ref with ^3 (e.g. looking for untracked files in a stash) can error on some versions of git just ignore it
if (ref != null && ref.endsWith('^3')) return '';
}

Logger.error(ex, 'git', ...args, ` cwd='${options.cwd}'\n\n `);
throw ex;
}
Expand Down Expand Up @@ -519,7 +527,7 @@ export class Git {
const [, ref] = match;

// If the bad ref is trying to find a parent ref, assume we hit to the last commit, so try again using the root sha
if (ref === ref1 && ref.endsWith('^')) {
if (ref === ref1 && ref != null && ref.endsWith('^')) {
return Git.diff(repoPath, fileName, rootSha, ref2, options);
}
}
Expand Down Expand Up @@ -735,10 +743,10 @@ export class Git {
static async revparse_currentBranch(repoPath: string): Promise<[string, string | undefined] | undefined> {
const params = ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@', '@{u}'];

const opts = {
const opts: GitCommandOptions = {
cwd: repoPath,
errors: GitErrorHandling.Throw
} as GitCommandOptions;
};

try {
const data = await git<string>(opts, ...params);
Expand Down Expand Up @@ -789,7 +797,9 @@ export class Git {
repoPath: string | undefined,
fileName: string,
ref: string,
options: { encoding?: string } = {}
options: {
encoding?: 'binary' | 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64' | 'latin1' | 'hex' | 'buffer';
} = {}
): Promise<TOut | undefined> {
const [file, root] = Git.splitPath(fileName, repoPath);

Expand All @@ -798,11 +808,11 @@ export class Git {
}
if (Git.isUncommitted(ref)) throw new Error(`ref=${ref} is uncommitted`);

const opts = {
const opts: GitCommandOptions = {
cwd: root,
encoding: options.encoding || 'utf8',
errors: GitErrorHandling.Throw
} as GitCommandOptions;
};
const args = ref.endsWith(':') ? `${ref}./${file}` : `${ref}:./${file}`;

try {
Expand Down

0 comments on commit b1a5a53

Please sign in to comment.