Skip to content

Commit 9b0ad08

Browse files
committed
Applies gitlens.advanced.abbreviateShaOnCopy to copyRemoteFileUrlToClipboard
Closes #2160 When copying a remote file URL to the clipboard, if the user has enabled the gitlens.advanced.abbreviateShaOnCopy setting, the SHA in the URL will now be abbreviated (shortened) just like when copying a SHA directly. This affects the following commands: - gitlens.copyRemoteFileUrlToClipboard - gitlens.copyRemoteFileUrlWithoutRange - gitlens.copyRemoteFileUrlFrom
1 parent 80c318f commit 9b0ad08

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/commands/openFileOnRemote.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { LineRange } from '@gitlens/git/models/lineRange.js';
33
import type { GitRemote } from '@gitlens/git/models/remote.js';
44
import { RemoteResourceType } from '@gitlens/git/models/remoteResource.js';
55
import { getBranchNameWithoutRemote, getRemoteNameFromBranchName } from '@gitlens/git/utils/branch.utils.js';
6-
import { isSha } from '@gitlens/git/utils/revision.utils.js';
6+
import { isSha, isUncommitted, shortenRevision } from '@gitlens/git/utils/revision.utils.js';
77
import { Logger } from '@gitlens/utils/logger.js';
88
import { pad, splitSingle } from '@gitlens/utils/string.js';
99
import { areUrisEqual } from '@gitlens/utils/uri.js';
@@ -13,6 +13,7 @@ import { GitUri } from '../git/gitUri.js';
1313
import { showGenericErrorMessage } from '../messages.js';
1414
import { showReferencePicker } from '../quickpicks/referencePicker.js';
1515
import { command, executeCommand } from '../system/-webview/command.js';
16+
import { configuration } from '../system/-webview/configuration.js';
1617
import { StatusFileNode } from '../views/nodes/statusFileNode.js';
1718
import { ActiveEditorCommand } from './commandBase.js';
1819
import { getCommandUri } from './commandBase.utils.js';
@@ -213,7 +214,14 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
213214
branchOrTag: args.branchOrTag ?? 'HEAD',
214215
fileName: gitUri.relativePath,
215216
range: range,
216-
sha: sha ?? undefined,
217+
sha:
218+
sha != null &&
219+
args.clipboard &&
220+
configuration.get('advanced.abbreviateShaOnCopy') &&
221+
isSha(sha, true) &&
222+
!isUncommitted(sha)
223+
? shortenRevision(sha)
224+
: (sha ?? undefined),
217225
},
218226
repoPath: gitUri.repoPath,
219227
remotes: remotes,

0 commit comments

Comments
 (0)