Skip to content
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

fix(git): Separate local and remote branches in branch display #2412

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const postProcessBranches =
}

const seen = new Set<string>();
const local = new Set<string>();
const remote = new Set<string>();
return output
.split("\n")
.filter((line) => !line.trim().startsWith("HEAD"))
Expand All @@ -71,6 +73,7 @@ const postProcessBranches =
const parts = branch.match(/\S+/g);
if (parts.length > 1) {
if (parts[0] === "*") {
local.add(branch.replace("*", "").trim());
// We are in a detached HEAD state
if (branch.includes("HEAD detached")) {
return null;
Expand All @@ -93,6 +96,9 @@ const postProcessBranches =
if (insertWithoutRemotes && name.startsWith("remotes/")) {
name = name.slice(name.indexOf("/", 8) + 1);
description = "Remote branch";
remote.add(name);
} else {
local.add(name);
}

const space = name.indexOf(" ");
Expand All @@ -107,6 +113,25 @@ const postProcessBranches =
priority: 75,
};
})
.map((suggestion) => {
if (local.has(suggestion.name) && remote.has(suggestion.name)) {
return suggestion;
} else if (local.has(suggestion.name) && !remote.has(suggestion.name)) {
return {
...suggestion,
description: "Local branch",
};
} else if (!local.has(suggestion.name) && remote.has(suggestion.name)) {
return {
...suggestion,
name: "remotes/origin/" + suggestion.name,
icon: "fig://icon?type=alert",
priority: 74,
};
}

return suggestion;
})
.filter((suggestion) => {
if (seen.has(suggestion.name)) return false;
seen.add(suggestion.name);
Expand Down
Loading