]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'js/branch-track-inherit'
authorJunio C Hamano <gitster@pobox.com>
Mon, 10 Jan 2022 19:52:54 +0000 (11:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Jan 2022 19:52:54 +0000 (11:52 -0800)
"git -c branch.autosetupmerge=inherit branch new old" makes "new"
to have the same upstream as the "old" branch, instead of marking
"old" itself as its upstream.

* js/branch-track-inherit:
  config: require lowercase for branch.*.autosetupmerge
  branch: add flags and config to inherit tracking
  branch: accept multiple upstream branches for tracking

1  2 
Documentation/config/branch.txt
Documentation/git-branch.txt
Documentation/git-checkout.txt
Documentation/git-switch.txt
branch.c
builtin/branch.c
builtin/checkout.c
config.c
parse-options.h
t/t2017-checkout-orphan.sh
t/t3200-branch.sh

Simple merge
Simple merge
Simple merge
Simple merge
diff --cc branch.c
index 2cfe496d242794d9c979cc63707f65cd1906231c,a4e4631ef16722c3e360970d52356ee3f9693d35..829130bb115d9ac1fa387596712e5164205c8cc3
+++ b/branch.c
@@@ -59,15 -68,27 +68,27 @@@ static int install_branch_config_multip
  {
        const char *shortname = NULL;
        struct strbuf key = STRBUF_INIT;
+       struct string_list_item *item;
        int rebasing = should_setup_rebase(origin);
  
-       if (skip_prefix(remote, "refs/heads/", &shortname)
-           && !strcmp(local, shortname)
-           && !origin) {
-               warning(_("not setting branch %s as its own upstream"),
-                       local);
-               return 0;
-       }
+       if (!remotes->nr)
+               BUG("must provide at least one remote for branch config");
+       if (rebasing && remotes->nr > 1)
+               die(_("cannot inherit upstream tracking configuration of "
+                     "multiple refs when rebasing is requested"));
+       /*
+        * If the new branch is trying to track itself, something has gone
+        * wrong. Warn the user and don't proceed any further.
+        */
+       if (!origin)
+               for_each_string_list_item(item, remotes)
+                       if (skip_prefix(item->string, "refs/heads/", &shortname)
+                           && !strcmp(local, shortname)) {
 -                              warning(_("not setting branch '%s' as its own upstream."),
++                              warning(_("not setting branch '%s' as its own upstream"),
+                                       local);
+                               return 0;
+                       }
  
        strbuf_addf(&key, "branch.%s.remote", local);
        if (git_config_set_gently(key.buf, origin ? origin : ".") < 0)
  
  out_err:
        strbuf_release(&key);
 -      error(_("Unable to write upstream branch configuration"));
 +      error(_("unable to write upstream branch configuration"));
  
-       advise(_(tracking_advice),
-              origin ? origin : "",
-              origin ? "/" : "",
-              shortname ? shortname : remote);
+       advise(_("\nAfter fixing the error cause you may try to fix up\n"
+               "the remote tracking information by invoking:"));
+       if (remotes->nr == 1)
+               advise("  git branch --set-upstream-to=%s%s%s",
+                       origin ? origin : "",
+                       origin ? "/" : "",
+                       remotes->items[0].string);
+       else {
+               advise("  git config --add branch.\"%s\".remote %s",
+                       local, origin ? origin : ".");
+               for_each_string_list_item(item, remotes)
+                       advise("  git config --add branch.\"%s\".merge %s",
+                               local, item->string);
+       }
  
        return -1;
  }
@@@ -153,14 -249,16 +249,16 @@@ static void setup_tracking(const char *
                }
  
        if (tracking.matches > 1)
 -              die(_("Not tracking: ambiguous information for ref %s"),
 +              die(_("not tracking: ambiguous information for ref %s"),
                    orig_ref);
  
-       if (install_branch_config(config_flags, new_ref, tracking.remote,
-                             tracking.src ? tracking.src : orig_ref) < 0)
+       if (tracking.srcs->nr < 1)
+               string_list_append(tracking.srcs, orig_ref);
+       if (install_branch_config_multiple_remotes(config_flags, new_ref,
+                               tracking.remote, tracking.srcs) < 0)
                exit(-1);
  
-       free(tracking.src);
+       string_list_clear(tracking.srcs, 0);
  }
  
  int read_branch_desc(struct strbuf *buf, const char *branch_name)
Simple merge
Simple merge
diff --cc config.c
Simple merge
diff --cc parse-options.h
Simple merge
Simple merge
index 8a619d785e4f7b031bcf437ca5c80086777e89b8,a74b2e06a146e322f7978f6a4e4b5c97736b40e6..1bc3795847dbbbe810e230dee5313d0b20b641aa
@@@ -979,10 -950,10 +979,10 @@@ test_expect_success 'disabled option --
        test_must_fail git branch --set-upstream origin/main
  '
  
- test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
+ test_expect_success '--set-upstream-to notices an error to set branch as own upstream' "
        git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
        cat >expect <<-\EOF &&
-       warning: not setting branch my13 as its own upstream
 -      warning: not setting branch 'my13' as its own upstream.
++      warning: not setting branch 'my13' as its own upstream
        EOF
        test_expect_code 1 git config branch.my13.remote &&
        test_expect_code 1 git config branch.my13.merge &&