Skip to content

Commit 9219bf5

Browse files
authored
Git - use first commit as common ancestor if the repository has not been published to a remote (microsoft#223476)
1 parent 1b9da61 commit 9219bf5

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

extensions/git/src/api/git.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export interface LogOptions {
146146
readonly shortStats?: boolean;
147147
readonly author?: string;
148148
readonly refNames?: string[];
149+
readonly maxParents?: number;
149150
}
150151

151152
export interface CommitOptions {

extensions/git/src/git.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,10 @@ export class Repository {
11651165
args.push(`--author="${options.author}"`);
11661166
}
11671167

1168+
if (typeof options?.maxParents === 'number') {
1169+
args.push(`--max-parents=${options.maxParents}`);
1170+
}
1171+
11681172
if (options?.refNames) {
11691173
args.push('--topo-order');
11701174
args.push('--decorate=full');

extensions/git/src/historyProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,11 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
274274
return ancestor;
275275
}
276276

277-
// TODO@lszomoru - Return first commit
277+
// First commit
278+
const commits = await this.repository.log({ maxParents: 0, refNames: ['HEAD'] });
279+
if (commits.length > 0) {
280+
return commits[0].hash;
281+
}
278282
} else if (historyItemGroupIds.length > 1) {
279283
const ancestor = await this.repository.getMergeBase(historyItemGroupIds[0], historyItemGroupIds[1], ...historyItemGroupIds.slice(2));
280284
return ancestor;

0 commit comments

Comments
 (0)