Skip to content

Commit

Permalink
Fixes bad truncation on refs
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Mar 9, 2025
1 parent 387e660 commit cd077e7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/git/utils/reference.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ export function createReference(
upstream?: { name: string; missing: boolean };
},
): GitBranchReference;
export function createReference(
ref: string,
repoPath: string,
options?: { refType: 'revision'; name?: string; message?: string },
): GitRevisionReference;
export function createReference(
ref: string,
repoPath: string,
Expand All @@ -36,6 +31,11 @@ export function createReference(
repoPath: string,
options: { refType: 'tag'; name: string; id?: string },
): GitTagReference;
export function createReference(
ref: string,
repoPath: string,
options?: { refType: 'revision'; name?: string; message?: string },
): GitRevisionReference;
export function createReference(
ref: string,
repoPath: string,
Expand Down Expand Up @@ -87,7 +87,7 @@ export function createReference(
repoPath: repoPath,
ref: ref,
sha: ref,
name: options.name ?? shortenRevision(ref, { force: true, strings: { working: 'Working Tree' } }),
name: options.name ?? shortenRevision(ref, { strings: { working: 'Working Tree' } }),
message: options.message,
};
}
Expand Down
6 changes: 1 addition & 5 deletions src/git/utils/revision.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,17 @@ export function setAbbreviatedShaLength(length: number): void {
export function shortenRevision(
ref: string | undefined,
options?: {
force?: boolean;
strings?: { uncommitted?: string; uncommittedStaged?: string; working?: string };
},
): string {
if (ref === deletedOrMissing) return '(deleted)';

if (!ref) return options?.strings?.working ?? '';
if (isUncommitted(ref)) {
return isUncommittedStaged(ref)
? options?.strings?.uncommittedStaged ?? 'Index'
: options?.strings?.uncommitted ?? 'Working Tree';
}

if (isRevisionRange(ref)) return ref;
if (!options?.force && !isShaLike(ref)) return ref;
if (isRevisionRange(ref) || !isShaLike(ref)) return ref;

// Don't allow shas to be shortened to less than 5 characters
const len = Math.max(5, getAbbreviatedShaLength());
Expand Down
4 changes: 1 addition & 3 deletions src/views/nodes/tagNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ export class TagNode extends ViewRefNode<'tag', ViewsWithTags, GitTagReference>
item.id = this.id;
item.contextValue = ContextValues.Tag;
item.description = emojify(this.tag.message);
item.tooltip = `${this.tag.name}${pad(GlyphChars.Dash, 2, 2)}${shortenRevision(this.tag.sha, {
force: true,
})}${
item.tooltip = `${this.tag.name}${pad(GlyphChars.Dash, 2, 2)}${shortenRevision(this.tag.sha)}${
this.tag.date != null
? `\n${this.tag.formatDateFromNow()} (${this.tag.formatDate(
this.view.container.TagDateFormatting.dateFormat,
Expand Down

0 comments on commit cd077e7

Please sign in to comment.