Skip to content

Commit f533a47

Browse files
committed
Fix commit generator hash length
Fixes #260748
1 parent 7ca850c commit f533a47

File tree

1 file changed

+63
-57
lines changed
  • extensions/terminal-suggest/src/completions/upstream

1 file changed

+63
-57
lines changed

extensions/terminal-suggest/src/completions/upstream/git.ts

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const postProcessTrackedFiles: Fig.Generator["postProcess"] = (
2929

3030
try {
3131
ext = file.split(".").slice(-1)[0];
32-
} catch (e) {}
32+
} catch (e) { }
3333

3434
if (file.endsWith("/")) {
3535
ext = "folder";
@@ -53,67 +53,67 @@ interface PostProcessBranchesOptions {
5353

5454
const postProcessBranches =
5555
(options: PostProcessBranchesOptions = {}): Fig.Generator["postProcess"] =>
56-
(out) => {
57-
const { insertWithoutRemotes = false } = options;
56+
(out) => {
57+
const { insertWithoutRemotes = false } = options;
5858

59-
const output = filterMessages(out);
59+
const output = filterMessages(out);
6060

61-
if (output.startsWith("fatal:")) {
62-
return [];
63-
}
61+
if (output.startsWith("fatal:")) {
62+
return [];
63+
}
6464

65-
const seen = new Set<string>();
66-
return output
67-
.split("\n")
68-
.filter((line) => !line.trim().startsWith("HEAD"))
69-
.map((branch) => {
70-
let name = branch.trim();
71-
const parts = branch.match(/\S+/g);
72-
if (parts && parts.length > 1) {
73-
if (parts[0] === "*") {
74-
// We are in a detached HEAD state
75-
if (branch.includes("HEAD detached")) {
76-
return null;
65+
const seen = new Set<string>();
66+
return output
67+
.split("\n")
68+
.filter((line) => !line.trim().startsWith("HEAD"))
69+
.map((branch) => {
70+
let name = branch.trim();
71+
const parts = branch.match(/\S+/g);
72+
if (parts && parts.length > 1) {
73+
if (parts[0] === "*") {
74+
// We are in a detached HEAD state
75+
if (branch.includes("HEAD detached")) {
76+
return null;
77+
}
78+
// Current branch
79+
return {
80+
name: branch.replace("*", "").trim(),
81+
description: "Current branch",
82+
priority: 100,
83+
icon: "⭐️",
84+
};
85+
} else if (parts[0] === "+") {
86+
// Branch checked out in another worktree.
87+
name = branch.replace("+", "").trim();
7788
}
78-
// Current branch
79-
return {
80-
name: branch.replace("*", "").trim(),
81-
description: "Current branch",
82-
priority: 100,
83-
icon: "⭐️",
84-
};
85-
} else if (parts[0] === "+") {
86-
// Branch checked out in another worktree.
87-
name = branch.replace("+", "").trim();
8889
}
89-
}
9090

91-
let description = "Branch";
91+
let description = "Branch";
9292

93-
if (insertWithoutRemotes && name.startsWith("remotes/")) {
94-
name = name.slice(name.indexOf("/", 8) + 1);
95-
description = "Remote branch";
96-
}
93+
if (insertWithoutRemotes && name.startsWith("remotes/")) {
94+
name = name.slice(name.indexOf("/", 8) + 1);
95+
description = "Remote branch";
96+
}
9797

98-
const space = name.indexOf(" ");
99-
if (space !== -1) {
100-
name = name.slice(0, space);
101-
}
98+
const space = name.indexOf(" ");
99+
if (space !== -1) {
100+
name = name.slice(0, space);
101+
}
102102

103-
return {
104-
name,
105-
description,
106-
icon: "fig://icon?type=git",
107-
priority: 75,
108-
};
109-
})
110-
.filter((suggestion) => {
111-
if (!suggestion) return false;
112-
if (seen.has(suggestion.name)) return false;
113-
seen.add(suggestion.name);
114-
return true;
115-
});
116-
};
103+
return {
104+
name,
105+
description,
106+
icon: "fig://icon?type=git",
107+
priority: 75,
108+
};
109+
})
110+
.filter((suggestion) => {
111+
if (!suggestion) return false;
112+
if (seen.has(suggestion.name)) return false;
113+
seen.add(suggestion.name);
114+
return true;
115+
});
116+
};
117117

118118
export const gitGenerators: Record<string, Fig.Generator> = {
119119
// Commit history
@@ -126,11 +126,17 @@ export const gitGenerators: Record<string, Fig.Generator> = {
126126
return [];
127127
}
128128

129-
return output.split("\n").map((line) => {
129+
const lines = output.split("\n");
130+
const firstLine = lines.length > 0 ? lines[0] : undefined;
131+
const hashLength =
132+
firstLine && firstLine.length > 0 ? firstLine.indexOf(" ") : 7;
133+
const descriptionStart = hashLength + 1;
134+
135+
return lines.map((line) => {
130136
return {
131-
name: line.substring(0, 7),
137+
name: line.substring(0, hashLength),
132138
icon: "fig://icon?type=node",
133-
description: line.substring(7),
139+
description: line.substring(descriptionStart),
134140
};
135141
});
136142
},
@@ -426,7 +432,7 @@ export const gitGenerators: Record<string, Fig.Generator> = {
426432
let ext = "";
427433
try {
428434
ext = file.split(".").slice(-1)[0];
429-
} catch (e) {}
435+
} catch (e) { }
430436

431437
if (file.endsWith("/")) {
432438
ext = "folder";

0 commit comments

Comments
 (0)