Browse Source

Adds an isMaybeWorktree to Repository

main
Eric Amodio 2 years ago
parent
commit
1b20e4a756
2 changed files with 19 additions and 7 deletions
  1. +3
    -1
      src/commands/quickCommand.steps.ts
  2. +16
    -6
      src/git/models/repository.ts

+ 3
- 1
src/commands/quickCommand.steps.ts View File

@ -97,7 +97,9 @@ export function appendReposToTitle<
Context extends { repos: Repository[] },
>(title: string, state: State, context: Context, additionalContext?: string) {
if (context.repos.length === 1) {
return `${title}${truncate(additionalContext ?? '', quickPickTitleMaxChars - title.length)}`;
return additionalContext
? `${title}${truncate(additionalContext, quickPickTitleMaxChars - title.length)}`
: title;
}
let repoContext;

+ 16
- 6
src/git/models/repository.ts View File

@ -178,7 +178,11 @@ export class Repository implements Disposable {
return this._onDidChangeFileSystem.event;
}
readonly formattedName: string;
get formattedName(): string {
// return this.isMaybeWorktree() === true ? `${this.name} (worktree)` : this.name;
return this.name;
}
readonly id: string;
readonly index: number;
readonly name: string;
@ -232,7 +236,6 @@ export class Repository implements Disposable {
// index: container.git.repositoryCount,
// };
}
this.formattedName = this.name;
this.index = folder?.index ?? container.git.repositoryCount;
this.id = asRepoComparisonKey(uri);
@ -613,12 +616,13 @@ export class Repository implements Disposable {
return this.container.git.getContributors(this.path, options);
}
private _gitDir: Promise<GitDir | undefined> | undefined;
private _gitDir: GitDir | undefined;
private _gitDirPromise: Promise<GitDir | undefined> | undefined;
private getGitDir(): Promise<GitDir | undefined> {
if (this._gitDir == null) {
this._gitDir = this.container.git.getGitDir(this.path);
if (this._gitDirPromise == null) {
this._gitDirPromise = this.container.git.getGitDir(this.path).then(gd => (this._gitDir = gd));
}
return this._gitDir;
return this._gitDirPromise;
}
private _lastFetched: number | undefined;
@ -751,6 +755,12 @@ export class Repository implements Disposable {
return branch?.upstream != null;
}
isMaybeWorktree(): boolean | undefined {
if (this._gitDir == null) return undefined;
return this._gitDir.commonUri != null;
}
async isWorktree(): Promise<boolean> {
return (await this.getGitDir())?.commonUri != null;
}

||||||
x
 
000:0
Loading…
Cancel
Save