Browse Source

Adds staged changes to file/line history

main
Eric Amodio 4 years ago
parent
commit
31f4ab7e45
3 changed files with 172 additions and 69 deletions
  1. +1
    -1
      src/git/models/status.ts
  2. +74
    -33
      src/views/nodes/fileHistoryNode.ts
  3. +97
    -35
      src/views/nodes/lineHistoryNode.ts

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

@ -148,7 +148,7 @@ export class GitStatusFile implements GitFile {
) {}
get status(): GitFileStatus {
return this.indexStatus || this.workingTreeStatus || '?';
return this.indexStatus ?? this.workingTreeStatus ?? '?';
}
get staged() {

+ 74
- 33
src/views/nodes/fileHistoryNode.ts View File

@ -43,41 +43,82 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
if (this.uri.sha === undefined) {
const status = await Container.git.getStatusForFile(this.uri.repoPath!, this.uri.fsPath);
if (status !== undefined && (status.indexStatus !== undefined || status.workingTreeStatus !== undefined)) {
let sha;
let previousSha;
if (status.workingTreeStatus !== undefined) {
sha = GitService.uncommittedSha;
if (status.indexStatus !== undefined) {
previousSha = GitService.uncommittedStagedSha;
} else if (status.workingTreeStatus !== '?') {
previousSha = 'HEAD';
}
if (status?.workingTreeStatus !== undefined || status?.indexStatus !== undefined) {
const user = await Container.git.getCurrentUser(this.uri.repoPath!);
if (status.workingTreeStatus !== undefined && status.indexStatus !== undefined) {
let commit = new GitLogCommit(
GitCommitType.LogFile,
this.uri.repoPath!,
GitService.uncommittedSha,
'You',
user !== undefined ? user.email : undefined,
new Date(),
new Date(),
'',
status.fileName,
[status],
status.status,
status.originalFileName,
GitService.uncommittedStagedSha,
status.originalFileName || status.fileName
);
children.push(
new CommitFileNode(this.view, this, status, commit, {
displayAsCommit: true,
inFileHistory: true
})
);
commit = new GitLogCommit(
GitCommitType.LogFile,
this.uri.repoPath!,
GitService.uncommittedStagedSha,
'You',
user !== undefined ? user.email : undefined,
new Date(),
new Date(),
'',
status.fileName,
[status],
status.status,
status.originalFileName,
'HEAD',
status.originalFileName || status.fileName
);
children.push(
new CommitFileNode(this.view, this, status, commit, {
displayAsCommit: true,
inFileHistory: true
})
);
} else {
sha = GitService.uncommittedStagedSha;
previousSha = 'HEAD';
const commit = new GitLogCommit(
GitCommitType.LogFile,
this.uri.repoPath!,
status.workingTreeStatus !== undefined
? GitService.uncommittedSha
: GitService.uncommittedStagedSha,
'You',
user !== undefined ? user.email : undefined,
new Date(),
new Date(),
'',
status.fileName,
[status],
status.status,
status.originalFileName,
'HEAD',
status.originalFileName || status.fileName
);
children.push(
new CommitFileNode(this.view, this, status, commit, {
displayAsCommit: true,
inFileHistory: true
})
);
}
const user = await Container.git.getCurrentUser(this.uri.repoPath!);
const commit = new GitLogCommit(
GitCommitType.LogFile,
this.uri.repoPath!,
sha,
'You',
user !== undefined ? user.email : undefined,
new Date(),
new Date(),
'',
status.fileName,
[status],
status.status,
status.originalFileName,
previousSha,
status.originalFileName || status.fileName
);
children.push(
new CommitFileNode(this.view, this, status, commit, { displayAsCommit: true, inFileHistory: true })
);
}
}

+ 97
- 35
src/views/nodes/lineHistoryNode.ts View File

@ -59,32 +59,6 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
for (const commit of blame.commits.values()) {
if (!commit.isUncommitted) continue;
const file: GitFile = {
fileName: commit.fileName,
indexStatus: '?',
originalFileName: commit.originalFileName,
repoPath: this.uri.repoPath!,
status: 'M',
workingTreeStatus: '?'
};
const uncommitted = new GitLogCommit(
GitCommitType.LogFile,
this.uri.repoPath!,
commit.sha,
'You',
commit.email,
commit.authorDate,
commit.committerDate,
commit.message,
commit.fileName,
[file],
'M',
commit.originalFileName,
commit.previousSha,
commit.originalFileName || commit.fileName
);
const firstLine = blame.lines[0];
const lastLine = blame.lines[blame.lines.length - 1];
@ -97,15 +71,103 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
selection.active.character
);
children.splice(
0,
0,
new CommitFileNode(this.view, this, file, uncommitted, {
displayAsCommit: true,
inFileHistory: true,
selection: selection
})
);
const status = await Container.git.getStatusForFile(this.uri.repoPath!, this.uri.fsPath);
const file: GitFile = {
fileName: commit.fileName,
indexStatus: status?.indexStatus ?? '?',
originalFileName: commit.originalFileName,
repoPath: this.uri.repoPath!,
status: 'M',
workingTreeStatus: status?.workingTreeStatus ?? '?'
};
if (status?.workingTreeStatus !== undefined && status?.indexStatus !== undefined) {
let uncommitted = new GitLogCommit(
GitCommitType.LogFile,
this.uri.repoPath!,
GitService.uncommittedStagedSha,
'You',
commit.email,
commit.authorDate,
commit.committerDate,
commit.message,
commit.fileName,
[file],
'M',
commit.originalFileName,
commit.previousSha,
commit.originalFileName || commit.fileName
);
children.splice(
0,
0,
new CommitFileNode(this.view, this, file, uncommitted, {
displayAsCommit: true,
inFileHistory: true,
selection: selection
})
);
uncommitted = new GitLogCommit(
GitCommitType.LogFile,
this.uri.repoPath!,
GitService.uncommittedSha,
'You',
commit.email,
commit.authorDate,
commit.committerDate,
commit.message,
commit.fileName,
[file],
'M',
commit.originalFileName,
GitService.uncommittedStagedSha,
commit.originalFileName || commit.fileName
);
children.splice(
0,
0,
new CommitFileNode(this.view, this, file, uncommitted, {
displayAsCommit: true,
inFileHistory: true,
selection: selection
})
);
} else {
const uncommitted = new GitLogCommit(
GitCommitType.LogFile,
this.uri.repoPath!,
status?.workingTreeStatus !== undefined
? GitService.uncommittedSha
: status?.indexStatus !== undefined
? GitService.uncommittedStagedSha
: commit.sha,
'You',
commit.email,
commit.authorDate,
commit.committerDate,
commit.message,
commit.fileName,
[file],
'M',
commit.originalFileName,
commit.previousSha,
commit.originalFileName || commit.fileName
);
children.splice(
0,
0,
new CommitFileNode(this.view, this, file, uncommitted, {
displayAsCommit: true,
inFileHistory: true,
selection: selection
})
);
}
break;
}

Loading…
Cancel
Save