Skip to content

fix(git): various strictness errors #2583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const postProcessBranches =
.map((branch) => {
let name = branch.trim();
const parts = branch.match(/\S+/g);
if (parts.length > 1) {
if (parts && parts.length > 1) {
if (parts[0] === "*") {
// We are in a detached HEAD state
if (branch.includes("HEAD detached")) {
Expand Down Expand Up @@ -108,6 +108,7 @@ const postProcessBranches =
};
})
.filter((suggestion) => {
if (!suggestion) return false;
if (seen.has(suggestion.name)) return false;
seen.add(suggestion.name);
return true;
Expand Down Expand Up @@ -259,7 +260,7 @@ export const gitGenerators: Record<string, Fig.Generator> = {
custom: async (tokens, executeShellCommand) => {
const pp = postProcessBranches({ insertWithoutRemotes: true });
if (tokens.includes("-r")) {
return pp(
return pp?.(
(
await executeShellCommand({
command: "git",
Expand All @@ -274,7 +275,7 @@ export const gitGenerators: Record<string, Fig.Generator> = {
tokens
);
} else {
return pp(
return pp?.(
(
await executeShellCommand({
command: "git",
Expand All @@ -295,14 +296,16 @@ export const gitGenerators: Record<string, Fig.Generator> = {
remotes: {
script: ["git", "--no-optional-locks", "remote", "-v"],
postProcess: function (out) {
const remoteURLs = out.split("\n").reduce((dict, line) => {
const pair = line.split("\t");
const remote = pair[0];
const url = pair[1].split(" ")[0];
const remoteURLs = out
.split("\n")
.reduce<Record<string, string>>((dict, line) => {
const pair = line.split("\t");
const remote = pair[0];
const url = pair[1].split(" ")[0];

dict[remote] = url;
return dict;
}, {});
dict[remote] = url;
return dict;
}, {});

return Object.keys(remoteURLs).map((remote) => {
const url = remoteURLs[remote];
Expand Down