Skip to content

Commit 4ff01e6

Browse files
authored
Git - tweak copilot worktree folder detection (microsoft#299147)
* Git - tweak copilot worktree folder detection * Pull request feedback
1 parent b5a312a commit 4ff01e6

3 files changed

Lines changed: 8 additions & 14 deletions

File tree

‎extensions/git/src/artifactProvider.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { LogOutputChannel, SourceControlArtifactProvider, SourceControlArtifactGroup, SourceControlArtifact, Event, EventEmitter, ThemeIcon, l10n, workspace, Uri, Disposable, Command } from 'vscode';
7-
import { coalesce, dispose, filterEvent, IDisposable, isCopilotWorktree } from './util';
7+
import { coalesce, dispose, filterEvent, IDisposable, isCopilotWorktreeFolder } from './util';
88
import { Repository } from './repository';
99
import type { Ref, Worktree } from './api/git';
1010
import { RefType } from './api/git.constants';
@@ -178,7 +178,7 @@ export class GitArtifactProvider implements SourceControlArtifactProvider, IDisp
178178
]).join(' \u2022 '),
179179
icon: w.main
180180
? new ThemeIcon('repo')
181-
: isCopilotWorktree(w.path)
181+
: isCopilotWorktreeFolder(w.path)
182182
? new ThemeIcon('chat-sparkle')
183183
: new ThemeIcon('worktree')
184184
}));

‎extensions/git/src/repository.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { IPushErrorHandlerRegistry } from './pushError';
2525
import { IRemoteSourcePublisherRegistry } from './remotePublisher';
2626
import { StatusBarCommands } from './statusbar';
2727
import { toGitUri } from './uri';
28-
import { anyEvent, combinedDisposable, debounceEvent, dispose, EmptyDisposable, eventToPromise, filterEvent, find, getCommitShortHash, IDisposable, isCopilotWorktree, isDescendant, isLinuxSnap, isRemote, isWindows, Limiter, onceEvent, pathEquals, relativePath } from './util';
28+
import { anyEvent, combinedDisposable, debounceEvent, dispose, EmptyDisposable, eventToPromise, filterEvent, find, getCommitShortHash, IDisposable, isCopilotWorktreeFolder, isDescendant, isLinuxSnap, isRemote, isWindows, Limiter, onceEvent, pathEquals, relativePath } from './util';
2929
import { IFileWatcher, watch } from './watch';
3030
import { ISourceControlHistoryItemDetailsProviderRegistry } from './historyItemDetailsProvider';
3131
import { GitArtifactProvider } from './artifactProvider';
@@ -954,7 +954,7 @@ export class Repository implements Disposable {
954954
const icon = repository.kind === 'submodule'
955955
? new ThemeIcon('archive')
956956
: repository.kind === 'worktree'
957-
? isCopilotWorktree(repository.root)
957+
? isCopilotWorktreeFolder(repository.root)
958958
? new ThemeIcon('chat-sparkle')
959959
: new ThemeIcon('worktree')
960960
: new ThemeIcon('repo');
@@ -967,7 +967,7 @@ export class Repository implements Disposable {
967967
// from the Repositories view.
968968
this._isHidden = workspace.workspaceFolders === undefined ||
969969
(repository.kind === 'worktree' &&
970-
isCopilotWorktree(repository.root) && parent !== undefined);
970+
isCopilotWorktreeFolder(repository.root) && parent !== undefined);
971971

972972
const root = Uri.file(repository.root);
973973
this._sourceControl = scm.createSourceControl('git', 'Git', root, icon, this._isHidden, parent);

‎extensions/git/src/util.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Event, Disposable, EventEmitter, SourceControlHistoryItemRef, l10n, workspace, Uri, DiagnosticSeverity, env, SourceControlHistoryItem } from 'vscode';
7-
import { dirname, normalize, sep, relative } from 'path';
7+
import { basename, dirname, normalize, sep, relative } from 'path';
88
import { Readable } from 'stream';
99
import { promises as fs, createReadStream } from 'fs';
1010
import byline from 'byline';
@@ -867,12 +867,6 @@ export function getStashDescription(stash: Stash): string | undefined {
867867
return descriptionSegments.join(' \u2022 ');
868868
}
869869

870-
export const CopilotWorktreeBranchPrefix = 'copilot-worktree-';
871-
872-
export function isCopilotWorktree(path: string): boolean {
873-
const lastSepIndex = path.lastIndexOf(sep);
874-
875-
return lastSepIndex !== -1
876-
? path.substring(lastSepIndex + 1).startsWith(CopilotWorktreeBranchPrefix)
877-
: path.startsWith(CopilotWorktreeBranchPrefix);
870+
export function isCopilotWorktreeFolder(path: string): boolean {
871+
return basename(path).startsWith('copilot-');
878872
}

0 commit comments

Comments
 (0)