@matheusbsbs / matheus-bagliano / commits / 72f600832f
Fork 0

Improve "git branch --tracking" output

An earlier patch always spelled the full name of the ref that we track (e.g. "refs/heads/frotz" instead of just "frotz" when we mean the branch whose name is "frotz"). Worse yet, because we now use the true name of the ref at the original repository when talk about a tracking branch that copies from a remote, such a full name alone still does not give enough information. This reorganizes the verbose codepath to: - differentiate "refs/heads/something" and everything else; we say that the branch tracks "branch <something>" if it begins with "refs/heads/", and otherwise the branch tracks "ref refs/<someother>/<something>"; - report the name of the remote when we talk about a tracking branch, by saying "branch frotz from origin"; - not say "by merging" at the end; it is the default and is not worth reporting. Signed-off-by: Junio C Hamano <junio@pobox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Mar 10, 2009 at 01:20 UTC 72f600832f75db626fd9290a21d02d49c92ca9ca
1 file changed +17 -6
branch.c
+17 -6
@@ -65,12 +65,23 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
65 git_config_set(key.buf, "true");
66 }
67
68 - if (flag & BRANCH_CONFIG_VERBOSE)
69 - printf("Branch %s set up to track %s branch %s %s.\n",
70 - local,
71 - origin ? "remote" : "local",
72 - remote,
73 - rebasing ? "by rebasing" : "by merging");
68 + if (flag & BRANCH_CONFIG_VERBOSE) {
69 + strbuf_reset(&key);
70 +
71 + strbuf_addstr(&key, origin ? "remote" : "local");
72 +
73 + /* Are we tracking a proper "branch"? */
74 + if (!prefixcmp(remote, "refs/heads/")) {
75 + strbuf_addf(&key, " branch %s", remote + 11);
76 + if (origin)
77 + strbuf_addf(&key, " from %s", origin);
78 + }
79 + else
80 + strbuf_addf(&key, " ref %s", remote);
81 + printf("Branch %s set up to track %s%s.\n",
82 + local, key.buf,
83 + rebasing ? " by rebasing" : "");
84 + }
85 strbuf_release(&key);
86 }
87