Browse Source

Fixes issue with no merge base

main
Eric Amodio 4 years ago
parent
commit
eee3b72110
3 changed files with 23 additions and 9 deletions
  1. +12
    -2
      src/git/git.ts
  2. +2
    -0
      src/git/gitService.ts
  3. +9
    -7
      src/views/nodes/statusFilesNode.ts

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

@ -32,6 +32,7 @@ const rootSha = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
export const GitErrors = {
badRevision: /bad revision '(.*?)'/i,
noFastForward: /\(non-fast-forward\)/i,
noMergeBase: /no merge base/i,
notAValidObjectName: /Not a valid object name/i,
invalidLineCount: /file .+? has only \d+ lines/i,
};
@ -610,13 +611,22 @@ export namespace Git {
return git<string>({ cwd: repoPath, configs: ['-c', 'color.diff=false'] }, ...params, '--');
}
export function diff__shortstat(repoPath: string, ref?: string) {
export async function diff__shortstat(repoPath: string, ref?: string) {
const params = ['diff', '--shortstat', '--no-ext-diff'];
if (ref) {
params.push(ref);
}
return git<string>({ cwd: repoPath, configs: ['-c', 'color.diff=false'] }, ...params, '--');
try {
return await git<string>({ cwd: repoPath, configs: ['-c', 'color.diff=false'] }, ...params, '--');
} catch (ex) {
const msg: string = ex?.toString() ?? '';
if (GitErrors.noMergeBase.test(msg)) {
return undefined;
}
throw ex;
}
}
export function difftool(

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

@ -1291,6 +1291,8 @@ export class GitService implements Disposable {
@log()
async getChangedFilesCount(repoPath: string, ref?: string): Promise<GitDiffShortStat | undefined> {
const data = await Git.diff__shortstat(repoPath, ref);
if (!data) return undefined;
return GitDiffParser.parseShortStat(data);
}

+ 9
- 7
src/views/nodes/statusFilesNode.ts View File

@ -56,9 +56,9 @@ export class StatusFilesNode extends ViewNode {
const repoPath = this.repoPath;
let log: GitLog | undefined;
if (this.range !== undefined) {
if (this.range != null) {
log = await Container.git.getLog(repoPath, { limit: 0, ref: this.range });
if (log !== undefined) {
if (log != null) {
files = [
...Iterables.flatMap(log.commits.values(), c =>
c.files.map(s => {
@ -75,7 +75,7 @@ export class StatusFilesNode extends ViewNode {
0,
0,
...Iterables.flatMap(this.status.files, s => {
if (s.workingTreeStatus !== undefined && s.indexStatus !== undefined) {
if (s.workingTreeStatus != null && s.indexStatus != null) {
// Decrements the date to guarantee this entry will be sorted after the previous entry (most recent first)
const older = new Date();
older.setMilliseconds(older.getMilliseconds() - 1);
@ -84,7 +84,7 @@ export class StatusFilesNode extends ViewNode {
this.toStatusFile(s, GitRevision.uncommitted, GitRevision.uncommittedStaged),
this.toStatusFile(s, GitRevision.uncommittedStaged, 'HEAD', older),
];
} else if (s.indexStatus !== undefined) {
} else if (s.indexStatus != null) {
return [this.toStatusFile(s, GitRevision.uncommittedStaged, 'HEAD')];
}
@ -139,7 +139,7 @@ export class StatusFilesNode extends ViewNode {
if (files > 0) {
const aheadFiles = await Container.git.getDiffStatus(this.repoPath, `${this.status.upstream}...`);
if (aheadFiles !== undefined) {
if (aheadFiles != null) {
const uniques = new Set();
for (const f of this.status.files) {
uniques.add(f.fileName);
@ -152,13 +152,15 @@ export class StatusFilesNode extends ViewNode {
}
} else {
const stats = await Container.git.getChangedFilesCount(this.repoPath, `${this.status.upstream}...`);
if (stats !== undefined) {
if (stats != null) {
files += stats.files;
} else {
files = -1;
}
}
}
const label = `${Strings.pluralize('file', files)} changed`;
const label = files === -1 ? '?? files changed' : `${Strings.pluralize('file', files)} changed`;
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
item.id = this.id;
item.contextValue = ContextValues.StatusFiles;

Loading…
Cancel
Save