Skip to content

Commit d00e828

Browse files
Fix issue display local branches containing forward slash
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent e7e392c commit d00e828

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

git_sim/git_sim_base_command.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,10 @@ def draw_branch(self, commit):
319319
# Use forward slash to check if branch is local or remote tracking
320320
# and draw the branch label if its hexsha matches the current commit
321321
if (
322-
"/" not in branch # local branch
322+
not self.is_remote_tracking_branch(branch) # local branch
323323
and commit.hexsha == self.repo.heads[branch].commit.hexsha
324324
) or (
325-
"/" in branch # remote tracking branch
325+
self.is_remote_tracking_branch(branch) # remote tracking branch
326326
and commit.hexsha == remote_tracking_branches[branch]
327327
):
328328
branchText = m.Text(
@@ -954,6 +954,15 @@ def get_remote_tracking_branches(self):
954954
remote_tracking_branches[ref.name] = ref.commit.hexsha
955955
return remote_tracking_branches
956956

957+
def is_remote_tracking_branch(self, branch):
958+
remote_refs = [remote.refs for remote in self.repo.remotes]
959+
remote_tracking_branches = {}
960+
for reflist in remote_refs:
961+
for ref in reflist:
962+
if "HEAD" not in ref.name and ref.name not in remote_tracking_branches:
963+
remote_tracking_branches[ref.name] = ref.commit.hexsha
964+
return branch in remote_tracking_branches
965+
957966

958967
class DottedLine(m.Line):
959968
def __init__(self, *args, dot_spacing=0.4, dot_kwargs={}, **kwargs):

git_sim/git_sim_merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def execute(self):
5757
self.get_commits(start=self.scene.args.branch[0])
5858

5959
# Use forward slash to determine if supplied branch arg is local or remote tracking branch
60-
if "/" not in self.scene.args.branch[0]:
60+
if not self.is_remote_tracking_branch(self.scene.args.branch[0]):
6161
if self.scene.args.branch[0] in self.repo.git.branch(
6262
"--contains", self.orig_commits[0].hexsha
6363
):

0 commit comments

Comments
 (0)