mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Fixes issues with merge commits
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
- Fixes various other quick pick command issues when a file was renamed
|
- Fixes various other quick pick command issues when a file was renamed
|
||||||
- Fixes various issues when caching is disabled
|
- Fixes various issues when caching is disabled
|
||||||
- Fixes issues with parsing commits history
|
- Fixes issues with parsing commits history
|
||||||
|
- Fixes various issues with merge commits
|
||||||
|
|
||||||
### 2.12.2
|
### 2.12.2
|
||||||
- Fixes [#50](https://github.com/eamodio/vscode-gitlens/issues/50) - excludes container-level CodeLens from `html` and `vue` language files
|
- Fixes [#50](https://github.com/eamodio/vscode-gitlens/issues/50) - excludes container-level CodeLens from `html` and `vue` language files
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ export * from './remotes/provider';
|
|||||||
|
|
||||||
let git: IGit;
|
let git: IGit;
|
||||||
|
|
||||||
//`--format=%H -%nauthor %an%nauthor-date %ai%ncommitter %cn%ncommitter-date %ci%nparent %P%nsummary %B%nfilename ?`
|
// `--format=%H -%nauthor %an%nauthor-date %ai%ncommitter %cn%ncommitter-date %ci%nparents %P%nsummary %B%nfilename ?`
|
||||||
const defaultLogParams = [`log`, `--name-status`, `--full-history`, `-M`, `--date=iso8601-strict`, `--format=%H -%nauthor %an%nauthor-date %ai%nsummary %B%nfilename ?`];
|
const defaultLogParams = [`log`, `--name-status`, `--full-history`, `-M`, `--date=iso8601-strict`, `--format=%H -%nauthor %an%nauthor-date %ai%nparents %P%nsummary %B%nfilename ?`];
|
||||||
|
|
||||||
async function gitCommand(cwd: string, ...args: any[]) {
|
async function gitCommand(cwd: string, ...args: any[]) {
|
||||||
try {
|
try {
|
||||||
@@ -166,7 +166,7 @@ export class Git {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static log(repoPath: string, sha?: string, maxCount?: number, reverse: boolean = false) {
|
static log(repoPath: string, sha?: string, maxCount?: number, reverse: boolean = false) {
|
||||||
const params = [...defaultLogParams];
|
const params = [...defaultLogParams, `-m`];
|
||||||
if (maxCount && !reverse) {
|
if (maxCount && !reverse) {
|
||||||
params.push(`-n${maxCount}`);
|
params.push(`-n${maxCount}`);
|
||||||
}
|
}
|
||||||
@@ -186,10 +186,19 @@ export class Git {
|
|||||||
static log_file(repoPath: string, fileName: string, sha?: string, maxCount?: number, reverse: boolean = false, startLine?: number, endLine?: number) {
|
static log_file(repoPath: string, fileName: string, sha?: string, maxCount?: number, reverse: boolean = false, startLine?: number, endLine?: number) {
|
||||||
const [file, root] = Git.splitPath(fileName, repoPath);
|
const [file, root] = Git.splitPath(fileName, repoPath);
|
||||||
|
|
||||||
const params = [...defaultLogParams, `--no-merges`, `--follow`];
|
const params = [...defaultLogParams, `--follow`];
|
||||||
if (maxCount && !reverse) {
|
if (maxCount && !reverse) {
|
||||||
params.push(`-n${maxCount}`);
|
params.push(`-n${maxCount}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are looking for a specific sha don't exclude merge commits
|
||||||
|
if (!sha || maxCount > 2) {
|
||||||
|
params.push(`--no-merges`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
params.push(`-m`);
|
||||||
|
}
|
||||||
|
|
||||||
if (sha) {
|
if (sha) {
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
params.push(`--reverse`);
|
params.push(`--reverse`);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export class GitLogCommit extends GitCommit {
|
|||||||
fileStatuses: { status: GitStatusFileStatus, fileName: string, originalFileName?: string }[];
|
fileStatuses: { status: GitStatusFileStatus, fileName: string, originalFileName?: string }[];
|
||||||
nextSha?: string;
|
nextSha?: string;
|
||||||
nextFileName?: string;
|
nextFileName?: string;
|
||||||
|
parentShas: string[];
|
||||||
status: GitStatusFileStatus;
|
status: GitStatusFileStatus;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -43,6 +44,10 @@ export class GitLogCommit extends GitCommit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isMerge() {
|
||||||
|
return this.parentShas && this.parentShas.length > 1;
|
||||||
|
}
|
||||||
|
|
||||||
get nextShortSha() {
|
get nextShortSha() {
|
||||||
return this.nextSha && this.nextSha.substring(0, 8);
|
return this.nextSha && this.nextSha.substring(0, 8);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ interface ILogEntry {
|
|||||||
// committer?: string;
|
// committer?: string;
|
||||||
// committerDate?: string;
|
// committerDate?: string;
|
||||||
|
|
||||||
// parentSha?: string;
|
parentShas?: string[];
|
||||||
|
|
||||||
fileName?: string;
|
fileName?: string;
|
||||||
originalFileName?: string;
|
originalFileName?: string;
|
||||||
@@ -75,9 +75,9 @@ export class GitLogParser {
|
|||||||
// entry.committerDate = lineParts.slice(1).join(' ').trim();
|
// entry.committerDate = lineParts.slice(1).join(' ').trim();
|
||||||
// break;
|
// break;
|
||||||
|
|
||||||
// case 'parent':
|
case 'parents':
|
||||||
// entry.parentSha = lineParts.slice(1).join(' ').trim();
|
entry.parentShas = lineParts.slice(1);
|
||||||
// break;
|
break;
|
||||||
|
|
||||||
case 'summary':
|
case 'summary':
|
||||||
entry.summary = lineParts.slice(1).join(' ').trim();
|
entry.summary = lineParts.slice(1).join(' ').trim();
|
||||||
@@ -227,6 +227,7 @@ export class GitLogParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
commit = new GitLogCommit(type, repoPath, entry.sha, relativeFileName, entry.author, moment(entry.authorDate).toDate(), entry.summary, entry.status, entry.fileStatuses, undefined, entry.originalFileName);
|
commit = new GitLogCommit(type, repoPath, entry.sha, relativeFileName, entry.author, moment(entry.authorDate).toDate(), entry.summary, entry.status, entry.fileStatuses, undefined, entry.originalFileName);
|
||||||
|
commit.parentShas = entry.parentShas;
|
||||||
|
|
||||||
if (relativeFileName !== entry.fileName) {
|
if (relativeFileName !== entry.fileName) {
|
||||||
commit.originalFileName = entry.fileName;
|
commit.originalFileName = entry.fileName;
|
||||||
|
|||||||
@@ -229,13 +229,13 @@ export class GitService extends Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findNextCommit(repoPath: string, fileName: string, sha?: string): Promise<GitLogCommit> {
|
async findNextCommit(repoPath: string, fileName: string, sha?: string): Promise<GitLogCommit> {
|
||||||
let log = await this.getLogForFile(repoPath, fileName, sha, 1, undefined, { follow: true, reverse: true });
|
let log = await this.getLogForFile(repoPath, fileName, sha, 1, undefined, true);
|
||||||
let commit = log && Iterables.first(log.commits.values());
|
let commit = log && Iterables.first(log.commits.values());
|
||||||
if (commit) return commit;
|
if (commit) return commit;
|
||||||
|
|
||||||
fileName = await this.findNextFileName(repoPath, fileName, sha);
|
fileName = await this.findNextFileName(repoPath, fileName, sha);
|
||||||
if (fileName) {
|
if (fileName) {
|
||||||
log = await this.getLogForFile(repoPath, fileName, sha, 1, undefined, { follow: true, reverse: true });
|
log = await this.getLogForFile(repoPath, fileName, sha, 1, undefined, true);
|
||||||
commit = log && Iterables.first(log.commits.values());
|
commit = log && Iterables.first(log.commits.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,11 +551,11 @@ export class GitService extends Disposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogForFile(repoPath: string, fileName: string, sha?: string, maxCount?: number, range?: Range, options: { follow?: boolean, reverse?: boolean } = {}): Promise<IGitLog | undefined> {
|
getLogForFile(repoPath: string, fileName: string, sha?: string, maxCount?: number, range?: Range, reverse: boolean = false): Promise<IGitLog | undefined> {
|
||||||
Logger.log(`getLogForFile('${repoPath}', '${fileName}', ${sha}, ${maxCount}, ${range && `[${range.start.line}, ${range.end.line}]`}, ${options})`);
|
Logger.log(`getLogForFile('${repoPath}', '${fileName}', ${sha}, ${maxCount}, ${range && `[${range.start.line}, ${range.end.line}]`}, ${reverse})`);
|
||||||
|
|
||||||
let entry: GitCacheEntry | undefined;
|
let entry: GitCacheEntry | undefined;
|
||||||
if (this.UseGitCaching && !sha && !range && !maxCount && !options.reverse) {
|
if (this.UseGitCaching && !sha && !range && !maxCount && !reverse) {
|
||||||
const cacheKey = this.getCacheEntryKey(fileName);
|
const cacheKey = this.getCacheEntryKey(fileName);
|
||||||
entry = this._gitCache.get(cacheKey);
|
entry = this._gitCache.get(cacheKey);
|
||||||
|
|
||||||
@@ -565,7 +565,7 @@ export class GitService extends Disposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const promise = this._getLogForFile(repoPath, fileName, sha, range, maxCount, options, entry);
|
const promise = this._getLogForFile(repoPath, fileName, sha, range, maxCount, reverse, entry);
|
||||||
|
|
||||||
if (entry) {
|
if (entry) {
|
||||||
Logger.log(`Add log cache for '${entry.key}'`);
|
Logger.log(`Add log cache for '${entry.key}'`);
|
||||||
@@ -581,7 +581,7 @@ export class GitService extends Disposable {
|
|||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _getLogForFile(repoPath: string, fileName: string, sha: string, range: Range, maxCount: number, options: { follow?: boolean, reverse?: boolean } = {}, entry: GitCacheEntry | undefined): Promise<IGitLog> {
|
private async _getLogForFile(repoPath: string, fileName: string, sha: string, range: Range, maxCount: number, reverse: boolean, entry: GitCacheEntry | undefined): Promise<IGitLog> {
|
||||||
const [file, root] = Git.splitPath(fileName, repoPath, false);
|
const [file, root] = Git.splitPath(fileName, repoPath, false);
|
||||||
|
|
||||||
const ignore = await this._gitignore;
|
const ignore = await this._gitignore;
|
||||||
@@ -591,8 +591,8 @@ export class GitService extends Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await Git.log_file(root, file, sha, maxCount, options.reverse, range && range.start.line + 1, range && range.end.line + 1);
|
const data = await Git.log_file(root, file, sha, maxCount, reverse, range && range.start.line + 1, range && range.end.line + 1);
|
||||||
return GitLogParser.parse(data, 'file', root || file, sha, maxCount, !!root, options.reverse, range);
|
return GitLogParser.parse(data, 'file', root || file, sha, maxCount, !!root, reverse, range);
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
// Trap and cache expected log errors
|
// Trap and cache expected log errors
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Arrays } from '../system';
|
import { Arrays, Iterables } from '../system';
|
||||||
import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
|
import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
|
||||||
import { Commands, Keyboard, KeyNoopCommand } from '../commands';
|
import { Commands, Keyboard, KeyNoopCommand } from '../commands';
|
||||||
import { GitCommit, GitLogCommit, GitService, GitUri, IGitLog } from '../gitService';
|
import { GitCommit, GitLogCommit, GitService, GitUri, IGitLog } from '../gitService';
|
||||||
@@ -118,6 +118,10 @@ export class CommitFileDetailsQuickPick {
|
|||||||
if (!c || !c.previousSha) {
|
if (!c || !c.previousSha) {
|
||||||
log = await git.getLogForFile(commit.repoPath, uri.fsPath, commit.sha, git.config.advanced.maxQuickHistory);
|
log = await git.getLogForFile(commit.repoPath, uri.fsPath, commit.sha, git.config.advanced.maxQuickHistory);
|
||||||
c = log && log.commits.get(commit.sha);
|
c = log && log.commits.get(commit.sha);
|
||||||
|
// Since we exclude merge commits in file log, just grab the first returned commit
|
||||||
|
if (!c && commit.isMerge) {
|
||||||
|
c = Iterables.first(log.commits.values());
|
||||||
|
}
|
||||||
|
|
||||||
if (c) {
|
if (c) {
|
||||||
// Copy over next info, since it is trustworthy at this point
|
// Copy over next info, since it is trustworthy at this point
|
||||||
|
|||||||
Reference in New Issue
Block a user