Skip to content

Commit 9cf0137

Browse files
committed
Merge branch 'bg/install-branch-config-skip-prefix'
* bg/install-branch-config-skip-prefix: branch: use skip_prefix() in install_branch_config() t3200-branch: test setting branch as own upstream
2 parents 1c18a14 + 303d1d0 commit 9cf0137

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

branch.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "git-compat-util.h"
12
#include "cache.h"
23
#include "branch.h"
34
#include "refs.h"
@@ -49,12 +50,11 @@ static int should_setup_rebase(const char *origin)
4950

5051
void install_branch_config(int flag, const char *local, const char *origin, const char *remote)
5152
{
52-
const char *shortname = remote + 11;
53-
int remote_is_branch = starts_with(remote, "refs/heads/");
53+
const char *shortname = skip_prefix(remote, "refs/heads/");
5454
struct strbuf key = STRBUF_INIT;
5555
int rebasing = should_setup_rebase(origin);
5656

57-
if (remote_is_branch
57+
if (shortname
5858
&& !strcmp(local, shortname)
5959
&& !origin) {
6060
warning(_("Not setting branch %s as its own upstream."),
@@ -77,29 +77,29 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
7777
strbuf_release(&key);
7878

7979
if (flag & BRANCH_CONFIG_VERBOSE) {
80-
if (remote_is_branch && origin)
80+
if (shortname && origin)
8181
printf_ln(rebasing ?
8282
_("Branch %s set up to track remote branch %s from %s by rebasing.") :
8383
_("Branch %s set up to track remote branch %s from %s."),
8484
local, shortname, origin);
85-
else if (remote_is_branch && !origin)
85+
else if (shortname && !origin)
8686
printf_ln(rebasing ?
8787
_("Branch %s set up to track local branch %s by rebasing.") :
8888
_("Branch %s set up to track local branch %s."),
8989
local, shortname);
90-
else if (!remote_is_branch && origin)
90+
else if (!shortname && origin)
9191
printf_ln(rebasing ?
9292
_("Branch %s set up to track remote ref %s by rebasing.") :
9393
_("Branch %s set up to track remote ref %s."),
9494
local, remote);
95-
else if (!remote_is_branch && !origin)
95+
else if (!shortname && !origin)
9696
printf_ln(rebasing ?
9797
_("Branch %s set up to track local ref %s by rebasing.") :
9898
_("Branch %s set up to track local ref %s."),
9999
local, remote);
100100
else
101-
die("BUG: impossible combination of %d and %p",
102-
remote_is_branch, origin);
101+
die("BUG: impossible combination of %p and %p",
102+
shortname, origin);
103103
}
104104
}
105105

t/t3200-branch.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,16 @@ EOF
507507
test_cmp expected actual
508508
'
509509

510+
test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
511+
git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
512+
cat >expected <<-\EOF &&
513+
warning: Not setting branch my13 as its own upstream.
514+
EOF
515+
test_expect_code 1 git config branch.my13.remote &&
516+
test_expect_code 1 git config branch.my13.merge &&
517+
test_i18ncmp expected actual
518+
'
519+
510520
# Keep this test last, as it changes the current branch
511521
cat >expect <<EOF
512522
$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master

0 commit comments

Comments
 (0)