mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-17 01:35:37 -05:00
Adds status information to log commits
Adds status info to commit details quick pick
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
import Git, { GitCommit, IGitAuthor, IGitEnricher, IGitLog } from './../git';
|
||||
import Git, { GitFileStatus, GitLogCommit, IGitAuthor, IGitEnricher, IGitLog } from './../git';
|
||||
import * as moment from 'moment';
|
||||
import * as path from 'path';
|
||||
|
||||
@@ -13,7 +13,9 @@ interface ILogEntry {
|
||||
committerDate?: string;
|
||||
|
||||
fileName?: string;
|
||||
fileNames?: string[];
|
||||
fileStatuses?: { status: GitFileStatus, fileName: string }[];
|
||||
|
||||
status?: GitFileStatus;
|
||||
|
||||
summary?: string;
|
||||
}
|
||||
@@ -78,22 +80,25 @@ export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
|
||||
break;
|
||||
}
|
||||
|
||||
if (entry.fileNames == null) {
|
||||
entry.fileNames = [lineParts[0]];
|
||||
}
|
||||
else {
|
||||
entry.fileNames.push(lineParts[0]);
|
||||
if (entry.fileStatuses == null) {
|
||||
entry.fileStatuses = [];
|
||||
}
|
||||
entry.fileStatuses.push({
|
||||
status: lineParts[0][0] as GitFileStatus,
|
||||
fileName: lineParts[0].substring(2)
|
||||
});
|
||||
}
|
||||
entry.fileName = entry.fileNames.join(', ');
|
||||
entry.fileName = entry.fileStatuses.filter(_ => !!_.fileName).map(_ => _.fileName).join(', ');
|
||||
}
|
||||
else {
|
||||
position += 2;
|
||||
lineParts = lines[position].split(' ');
|
||||
if (lineParts.length === 1) {
|
||||
entry.fileName = lineParts[0];
|
||||
entry.status = lineParts[0][0] as GitFileStatus;
|
||||
entry.fileName = lineParts[0].substring(2);
|
||||
}
|
||||
else {
|
||||
entry.status = lineParts[3][0] as GitFileStatus;
|
||||
entry.fileName = lineParts[3].substring(2);
|
||||
position += 4;
|
||||
}
|
||||
@@ -116,11 +121,11 @@ export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
|
||||
if (!entries) return undefined;
|
||||
|
||||
const authors: Map<string, IGitAuthor> = new Map();
|
||||
const commits: Map<string, GitCommit> = new Map();
|
||||
const commits: Map<string, GitLogCommit> = new Map();
|
||||
|
||||
let repoPath: string;
|
||||
let relativeFileName: string;
|
||||
let recentCommit: GitCommit;
|
||||
let recentCommit: GitLogCommit;
|
||||
|
||||
if (isRepoPath) {
|
||||
repoPath = fileNameOrRepoPath;
|
||||
@@ -151,7 +156,7 @@ export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
|
||||
authors.set(entry.author, author);
|
||||
}
|
||||
|
||||
commit = new GitCommit(repoPath, entry.sha, relativeFileName, entry.author, moment(entry.authorDate).toDate(), entry.summary);
|
||||
commit = new GitLogCommit(repoPath, entry.sha, relativeFileName, entry.author, moment(entry.authorDate).toDate(), entry.summary, entry.status, entry.fileStatuses);
|
||||
|
||||
if (relativeFileName !== entry.fileName) {
|
||||
commit.originalFileName = entry.fileName;
|
||||
|
||||
@@ -13,7 +13,7 @@ export * from './enrichers/logParserEnricher';
|
||||
let git: IGit;
|
||||
const UncommittedRegex = /^[0]+$/;
|
||||
|
||||
const DefaultLogParams = [`log`, `--name-only`, `--full-history`, `-m`, `--date=iso8601-strict`, `--format=%H -%nauthor %an%nauthor-date %ai%ncommitter %cn%ncommitter-date %ci%nsummary %s%nfilename ?`];
|
||||
const DefaultLogParams = [`log`, `--name-status`, `--full-history`, `-m`, `--date=iso8601-strict`, `--format=%H -%nauthor %an%nauthor-date %ai%ncommitter %cn%ncommitter-date %ci%nsummary %s%nfilename ?`];
|
||||
|
||||
async function gitCommand(cwd: string, ...args: any[]) {
|
||||
try {
|
||||
|
||||
@@ -72,6 +72,8 @@ export class GitCommit implements IGitCommit {
|
||||
previousSha?: string,
|
||||
previousFileName?: string
|
||||
) {
|
||||
this.fileName = this.fileName.replace(/, ?$/, '');
|
||||
|
||||
this.lines = lines || [];
|
||||
this.originalFileName = originalFileName;
|
||||
this.previousSha = previousSha;
|
||||
@@ -101,6 +103,37 @@ export class GitCommit implements IGitCommit {
|
||||
}
|
||||
}
|
||||
|
||||
export class GitLogCommit extends GitCommit {
|
||||
|
||||
fileStatuses: { status: GitFileStatus, fileName: string }[];
|
||||
status: GitFileStatus;
|
||||
|
||||
constructor(
|
||||
repoPath: string,
|
||||
sha: string,
|
||||
fileName: string,
|
||||
author: string,
|
||||
date: Date,
|
||||
message: string,
|
||||
status?: GitFileStatus,
|
||||
fileStatuses?: { status: GitFileStatus, fileName: string }[],
|
||||
lines?: IGitCommitLine[],
|
||||
originalFileName?: string,
|
||||
previousSha?: string,
|
||||
previousFileName?: string
|
||||
) {
|
||||
super(repoPath, sha, fileName, author, date, message, lines, originalFileName, previousSha, previousFileName);
|
||||
this.status = status;
|
||||
|
||||
if (fileStatuses) {
|
||||
this.fileStatuses = fileStatuses.filter(_ => !!_.fileName);
|
||||
}
|
||||
else {
|
||||
this.fileStatuses = [{ status: status, fileName: fileName }];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface IGitCommitLine {
|
||||
sha: string;
|
||||
previousSha?: string;
|
||||
@@ -115,14 +148,7 @@ export interface IGitLog {
|
||||
commits: Map<string, GitCommit>;
|
||||
}
|
||||
|
||||
export enum GitFileStatus {
|
||||
Unknown,
|
||||
Untracked,
|
||||
Added,
|
||||
Modified,
|
||||
Deleted,
|
||||
Renamed
|
||||
}
|
||||
export declare type GitFileStatus = '?' | 'A' | 'C' | 'D' | 'M' | 'R' | 'U';
|
||||
|
||||
export class GitFileStatusItem {
|
||||
|
||||
@@ -136,36 +162,10 @@ export class GitFileStatusItem {
|
||||
}
|
||||
|
||||
private parseStatus(status: string) {
|
||||
const indexStatus = status[0];
|
||||
const workTreeStatus = status[1];
|
||||
const indexStatus = status[0].trim();
|
||||
const workTreeStatus = status[1].trim();
|
||||
|
||||
this.staged = workTreeStatus === ' ';
|
||||
|
||||
if (indexStatus === '?' && workTreeStatus === '?') {
|
||||
this.status = GitFileStatus.Untracked;
|
||||
return;
|
||||
}
|
||||
|
||||
if (indexStatus === 'A') {
|
||||
this.status = GitFileStatus.Added;
|
||||
return;
|
||||
}
|
||||
|
||||
if (indexStatus === 'M' || workTreeStatus === 'M') {
|
||||
this.status = GitFileStatus.Modified;
|
||||
return;
|
||||
}
|
||||
|
||||
if (indexStatus === 'D' || workTreeStatus === 'D') {
|
||||
this.status = GitFileStatus.Deleted;
|
||||
return;
|
||||
}
|
||||
|
||||
if (indexStatus === 'R') {
|
||||
this.status = GitFileStatus.Renamed;
|
||||
return;
|
||||
}
|
||||
|
||||
this.status = GitFileStatus.Unknown;
|
||||
this.staged = !!indexStatus;
|
||||
this.status = (indexStatus || workTreeStatus || 'U') as GitFileStatus;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user