Browse Source

Fixes title issue with newly added files

main
Eric Amodio 6 years ago
parent
commit
c4483b1b91
4 changed files with 14 additions and 9 deletions
  1. +1
    -1
      src/commands/diffWith.ts
  2. +6
    -4
      src/git/git.ts
  3. +1
    -1
      src/git/models/commit.ts
  4. +6
    -3
      src/gitService.ts

+ 1
- 1
src/commands/diffWith.ts View File

@ -136,7 +136,7 @@ export class DiffWithCommand extends ActiveEditorCommand {
args.lhs.title = `${path.basename(args.lhs.uri.fsPath)}${suffix !== '' ? ` (${lhsPrefix}${suffix})` : ''}`; args.lhs.title = `${path.basename(args.lhs.uri.fsPath)}${suffix !== '' ? ` (${lhsPrefix}${suffix})` : ''}`;
} }
if (args.rhs.title === undefined && args.rhs.sha !== GitService.deletedSha) { if (args.rhs.title === undefined && args.rhs.sha !== GitService.deletedSha) {
const suffix = GitService.shortenSha(args.rhs.sha) || '';
const suffix = GitService.shortenSha(args.rhs.sha, { uncommitted: 'working tree' }) || '';
args.rhs.title = `${path.basename(args.rhs.uri.fsPath)}${suffix !== '' ? ` (${rhsPrefix}${suffix})` : rhsPrefix}`; args.rhs.title = `${path.basename(args.rhs.uri.fsPath)}${suffix !== '' ? ` (${rhsPrefix}${suffix})` : rhsPrefix}`;
} }

+ 6
- 4
src/git/git.ts View File

@ -183,7 +183,7 @@ export class Git {
ref = ''; ref = '';
} }
const suffix = Strings.truncate(Strings.sanitizeForFileSystem(Git.isSha(ref) ? Git.shortenSha(ref) : ref), 50, '');
const suffix = Strings.truncate(Strings.sanitizeForFileSystem(Git.isSha(ref) ? Git.shortenSha(ref)! : ref), 50, '');
const ext = path.extname(fileName); const ext = path.extname(fileName);
const tmp = await import('tmp'); const tmp = await import('tmp');
@ -224,9 +224,11 @@ export class Git {
return sha === undefined ? false : Git.uncommittedRegex.test(sha); return sha === undefined ? false : Git.uncommittedRegex.test(sha);
} }
static shortenSha(sha: string) {
if (Git.isStagedUncommitted(sha)) return 'index';
if (Git.isUncommitted(sha)) return '';
static shortenSha(sha: string, strings: { deleted?: string, stagedUncommitted?: string, uncommitted?: string } = {}) {
strings = { uncommitted: '', stagedUncommitted: 'index', ...strings };
if (Git.isStagedUncommitted(sha)) return strings.stagedUncommitted;
if (Git.isUncommitted(sha)) return strings.uncommitted;
const index = sha.indexOf('^'); const index = sha.indexOf('^');
if (index > 6) { if (index > 6) {

+ 1
- 1
src/git/models/commit.ts View File

@ -122,7 +122,7 @@ export abstract class GitCommit {
protected _resolvedPreviousFileSha: string | undefined; protected _resolvedPreviousFileSha: string | undefined;
get previousFileShortSha(): string { get previousFileShortSha(): string {
return Git.shortenSha(this.previousFileSha);
return Git.shortenSha(this.previousFileSha)!;
} }
get previousSha(): string | undefined { get previousSha(): string | undefined {

+ 6
- 3
src/gitService.ts View File

@ -1452,12 +1452,15 @@ export class GitService extends Disposable {
return Git.isUncommitted(sha); return Git.isUncommitted(sha);
} }
static shortenSha(sha: string | undefined) {
static shortenSha(sha: string | undefined, strings: { deleted?: string, stagedUncommitted?: string, uncommitted?: string } = {}) {
if (sha === undefined) return undefined; if (sha === undefined) return undefined;
if (sha === GitService.deletedSha) return '(deleted)';
strings = { deleted: '(deleted)', ...strings };
if (sha === GitService.deletedSha) return strings.deleted;
return Git.isSha(sha) || Git.isStagedUncommitted(sha) return Git.isSha(sha) || Git.isStagedUncommitted(sha)
? Git.shortenSha(sha)
? Git.shortenSha(sha, strings)
: sha; : sha;
} }

Loading…
Cancel
Save