Skip to content

Commit 539d09c

Browse files
glandiumgitster
authored andcommitted
show-branch: show all local heads when only giving one rev along --topics
"git show-branch --topics <rev> <revs>..." displays ancestry graph, only considering commits that are in all given revs, except the first one. "git show-branch" displays ancestry graph for all local branches. Unfortunately, "git show-branch --topics <rev>" only prints out the rev info for the given rev, and nothing else, e.g.: $ git show-branch --topics origin/master [origin/master] Sync with 2.3.3 While there is an option to add all remote-tracking branches (-r), and another to add all local+remote branches (-a), there is no option to add only local branches. Adding such an option could be considered, but a user would likely already expect that the above command line considers the lack of rev other than for --topics as meaning all local branches, like when there is no argument at all. Moreover, when using -r and -a along with --topics, the first local or remote-tracking branch, depending on alphabetic order is used instead of the one given after --topics (any rev given on the command line is actually simply ignored when either -r or -a is given). And if no rev is given at all, the fact that the first alphetical branch is the base of topics is probably not expected by users (Maybe --topics should always require one rev on the command line?) This change makes "show-branch --topics $rev" act as "show-branch --topics $rev $(git for-each-ref refs/heads --format='%(refname:short)')" "show-branch -r --topics $rev ..." act as "show-branch --topics $rev ... $(git for-each-ref refs/remotes --format='%(refname:short)')" instead of "show-branch --topics $(git for-each-ref refs/remotes --format='%(refname:short)')" and "show-branch -a --topics $rev ..." act as "show-branch --topics $rev ... $(git for-each-ref refs/heads refs/remotes --format='%(refname:short)')" instead of "show-branch --topics $(git for-each-ref refs/heads refs/remotes --format='%(refname:short)')" Signed-off-by: Mike Hommey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9874fca commit 539d09c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

builtin/show-branch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
718718
}
719719

720720
/* If nothing is specified, show all branches by default */
721-
if (ac + all_heads + all_remotes == 0)
721+
if (ac <= topics && all_heads + all_remotes == 0)
722722
all_heads = 1;
723723

724724
if (reflog) {
@@ -785,13 +785,13 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
785785
}
786786
free(ref);
787787
}
788-
else if (all_heads + all_remotes)
789-
snarf_refs(all_heads, all_remotes);
790788
else {
791789
while (0 < ac) {
792790
append_one_rev(*av);
793791
ac--; av++;
794792
}
793+
if (all_heads + all_remotes)
794+
snarf_refs(all_heads, all_remotes);
795795
}
796796

797797
head_p = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,

0 commit comments

Comments
 (0)