Ver código fonte

Fixes issues with showing deleted file changes

Fixes issues with added files in diff title
main
Eric Amodio 6 anos atrás
pai
commit
f547487e41
3 arquivos alterados com 32 adições e 3 exclusões
  1. +13
    -2
      src/commands/diffWith.ts
  2. +4
    -0
      src/git/git.ts
  3. +15
    -1
      src/git/gitService.ts

+ 13
- 2
src/commands/diffWith.ts Ver arquivo

@ -109,7 +109,18 @@ export class DiffWithCommand extends ActiveEditorCommand {
lhsSha = args.lhs.sha;
}
if (args.rhs.sha !== GitService.deletedOrMissingSha) {
rhsSha = args.rhs.sha;
// Ensure that the file still exists in this commit
const status = await Container.git.getFileStatusForCommit(
args.repoPath,
args.rhs.uri.fsPath,
args.rhs.sha
);
if (status !== undefined && status.status === 'D') {
args.rhs.sha = GitService.deletedOrMissingSha;
}
else {
rhsSha = args.rhs.sha;
}
}
const [lhs, rhs] = await Promise.all([
@ -133,7 +144,7 @@ export class DiffWithCommand extends ActiveEditorCommand {
rhsSuffix = `added in ${rhsSuffix}`;
}
let lhsSuffix = GitService.shortenSha(lhsSha) || '';
let lhsSuffix = args.lhs.sha !== GitService.deletedOrMissingSha ? GitService.shortenSha(lhsSha) || '' : '';
if (lhs === undefined && args.rhs.sha === '') {
if (rhs !== undefined) {
lhsSuffix = `not in ${lhsSuffix}`;

+ 4
- 0
src/git/git.ts Ver arquivo

@ -712,6 +712,10 @@ export class Git {
}
}
static show_status(repoPath: string, fileName: string, ref: string) {
return git<string>({ cwd: repoPath }, 'show', '--name-status', '--format=', ref, '--', fileName);
}
static stash_apply(repoPath: string, stashName: string, deleteAfter: boolean) {
if (!stashName) return undefined;
return git<string>({ cwd: repoPath }, 'stash', deleteAfter ? 'pop' : 'apply', stashName);

+ 15
- 1
src/git/gitService.ts Ver arquivo

@ -1102,6 +1102,20 @@ export class GitService implements Disposable {
}
}
async getFileStatusForCommit(repoPath: string, fileName: string, ref: string): Promise<GitFile | undefined> {
if (ref === GitService.deletedOrMissingSha || GitService.isUncommitted(ref)) return undefined;
Logger.log(`getFileStatusForCommit('${repoPath}', '${fileName}', '${ref}')`);
const data = await Git.show_status(repoPath, fileName, ref);
if (!data) return undefined;
const files = GitDiffParser.parseNameStatus(data, repoPath);
if (files === undefined || files.length === 0) return undefined;
return files[0];
}
async getRecentLogCommitForFile(repoPath: string | undefined, fileName: string): Promise<GitLogCommit | undefined> {
return this.getLogCommitForFile(repoPath, fileName, undefined);
}
@ -1125,7 +1139,7 @@ export class GitService implements Disposable {
options: { ref?: string; firstIfNotFound?: boolean; reverse?: boolean } = {}
): Promise<GitLogCommit | undefined> {
Logger.log(
`getFileLogCommit('${repoPath}', '${fileName}', '${options.ref}', ${options.firstIfNotFound}, ${
`getLogCommitForFile('${repoPath}', '${fileName}', '${options.ref}', ${options.firstIfNotFound}, ${
options.reverse
})`
);

Carregando…
Cancelar
Salvar