Merge branch 'jh/checkout-auto-tracking'
authorJunio C Hamano <gitster@pobox.com>
Fri, 20 Sep 2013 19:31:57 +0000 (12:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Sep 2013 19:31:57 +0000 (12:31 -0700)
Fix a minor regression in v1.8.3.2 and later that made it
impossible to base your local work on anything but a local branch
of the upstream repository you are tracking from.

* jh/checkout-auto-tracking:
t3200: fix failure on case-insensitive filesystems
branch.c: Relax unnecessary requirement on upstream's remote ref name
t3200: Add test demonstrating minor regression in 41c21f2
Refer to branch.<name>.remote/merge when documenting --track
t3200: Minor fix when preparing for tracking failure
t2024: Fix &&-chaining and a couple of typos

1  2 
branch.c
t/t3200-branch.sh
diff --combined branch.c
index 546c4b44060a3eddec3124379030bdb068d637d6,428be60b8ce5c12b5b40b24f856962fed13999ec..d31b354d487e43f710206bbafbb130ab96d87637
+++ b/branch.c
@@@ -57,7 -57,7 +57,7 @@@ void install_branch_config(int flag, co
        if (remote_is_branch
            && !strcmp(local, shortname)
            && !origin) {
 -              warning("Not setting branch %s as its own upstream.",
 +              warning(_("Not setting branch %s as its own upstream."),
                        local);
                return;
        }
  
        if (flag & BRANCH_CONFIG_VERBOSE) {
                if (remote_is_branch && origin)
 -                      printf(rebasing ?
 -                             "Branch %s set up to track remote branch %s from %s by rebasing.\n" :
 -                             "Branch %s set up to track remote branch %s from %s.\n",
 -                             local, shortname, origin);
 +                      printf_ln(rebasing ?
 +                                _("Branch %s set up to track remote branch %s from %s by rebasing.") :
 +                                _("Branch %s set up to track remote branch %s from %s."),
 +                                local, shortname, origin);
                else if (remote_is_branch && !origin)
 -                      printf(rebasing ?
 -                             "Branch %s set up to track local branch %s by rebasing.\n" :
 -                             "Branch %s set up to track local branch %s.\n",
 -                             local, shortname);
 +                      printf_ln(rebasing ?
 +                                _("Branch %s set up to track local branch %s by rebasing.") :
 +                                _("Branch %s set up to track local branch %s."),
 +                                local, shortname);
                else if (!remote_is_branch && origin)
 -                      printf(rebasing ?
 -                             "Branch %s set up to track remote ref %s by rebasing.\n" :
 -                             "Branch %s set up to track remote ref %s.\n",
 -                             local, remote);
 +                      printf_ln(rebasing ?
 +                                _("Branch %s set up to track remote ref %s by rebasing.") :
 +                                _("Branch %s set up to track remote ref %s."),
 +                                local, remote);
                else if (!remote_is_branch && !origin)
 -                      printf(rebasing ?
 -                             "Branch %s set up to track local ref %s by rebasing.\n" :
 -                             "Branch %s set up to track local ref %s.\n",
 -                             local, remote);
 +                      printf_ln(rebasing ?
 +                                _("Branch %s set up to track local ref %s by rebasing.") :
 +                                _("Branch %s set up to track local ref %s."),
 +                                local, remote);
                else
                        die("BUG: impossible combination of %d and %p",
                            remote_is_branch, origin);
@@@ -115,7 -115,7 +115,7 @@@ static int setup_tracking(const char *n
        int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE;
  
        if (strlen(new_ref) > 1024 - 7 - 7 - 1)
 -              return error("Tracking not set up: name too long: %s",
 +              return error(_("Tracking not set up: name too long: %s"),
                                new_ref);
  
        memset(&tracking, 0, sizeof(tracking));
                }
  
        if (tracking.matches > 1)
 -              return error("Not tracking: ambiguous information for ref %s",
 +              return error(_("Not tracking: ambiguous information for ref %s"),
                                orig_ref);
  
        install_branch_config(config_flags, new_ref, tracking.remote,
@@@ -179,12 -179,12 +179,12 @@@ int validate_new_branchname(const char 
                            int force, int attr_only)
  {
        if (strbuf_check_branch_ref(ref, name))
 -              die("'%s' is not a valid branch name.", name);
 +              die(_("'%s' is not a valid branch name."), name);
  
        if (!ref_exists(ref->buf))
                return 0;
        else if (!force && !attr_only)
 -              die("A branch named '%s' already exists.", ref->buf + strlen("refs/heads/"));
 +              die(_("A branch named '%s' already exists."), ref->buf + strlen("refs/heads/"));
  
        if (!attr_only) {
                const char *head;
  
                head = resolve_ref_unsafe("HEAD", sha1, 0, NULL);
                if (!is_bare_repository() && head && !strcmp(head, ref->buf))
 -                      die("Cannot force update the current branch.");
 +                      die(_("Cannot force update the current branch."));
        }
        return 1;
  }
@@@ -203,8 -203,7 +203,7 @@@ static int check_tracking_branch(struc
        struct refspec query;
        memset(&query, 0, sizeof(struct refspec));
        query.dst = tracking_branch;
-       return !(remote_find_tracking(remote, &query) ||
-                prefixcmp(query.src, "refs/heads/"));
+       return !remote_find_tracking(remote, &query);
  }
  
  static int validate_remote_tracking_branch(char *ref)
@@@ -262,7 -261,7 +261,7 @@@ void create_branch(const char *head
                        }
                        die(_(upstream_missing), start_name);
                }
 -              die("Not a valid object name: '%s'.", start_name);
 +              die(_("Not a valid object name: '%s'."), start_name);
        }
  
        switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) {
                }
                break;
        default:
 -              die("Ambiguous object name: '%s'.", start_name);
 +              die(_("Ambiguous object name: '%s'."), start_name);
                break;
        }
  
        if ((commit = lookup_commit_reference(sha1)) == NULL)
 -              die("Not a valid branch point: '%s'.", start_name);
 +              die(_("Not a valid branch point: '%s'."), start_name);
        hashcpy(sha1, commit->object.sha1);
  
        if (!dont_change_ref) {
                lock = lock_any_ref_for_update(ref.buf, NULL, 0);
                if (!lock)
 -                      die_errno("Failed to lock ref for update");
 +                      die_errno(_("Failed to lock ref for update"));
        }
  
        if (reflog)
                         start_name);
  
        if (real_ref && track)
 -              setup_tracking(ref.buf+11, real_ref, track, quiet);
 +              setup_tracking(ref.buf + 11, real_ref, track, quiet);
  
        if (!dont_change_ref)
                if (write_ref_sha1(lock, sha1, msg) < 0)
 -                      die_errno("Failed to write ref");
 +                      die_errno(_("Failed to write ref"));
  
        strbuf_release(&ref);
        free(real_ref);
diff --combined t/t3200-branch.sh
index d85306f1b991b7b1c178a35c05f1bbfc70077321,55c9ab0b6a5c65aacdb3ef6107c3417d7bdc4e00..0fe7647928b9d20963e60e56009f72c54ee488e2
@@@ -14,8 -14,7 +14,8 @@@ test_expect_success 'prepare a trivial 
        echo World >>A &&
        git update-index --add A &&
        git commit -m "Second commit." &&
 -      HEAD=$(git rev-parse --verify HEAD)'
 +      HEAD=$(git rev-parse --verify HEAD)
 +'
  
  test_expect_success 'git branch --help should not have created a bogus branch' '
        test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null &&
@@@ -320,8 -319,9 +320,9 @@@ test_expect_success 'test tracking setu
  
  test_expect_success 'tracking setup fails on non-matching refspec' '
        git config remote.local.url . &&
-       git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
+       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
        (git show-ref -q refs/remotes/local/master || git fetch local) &&
+       git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
        test_must_fail git branch --track my5 local/master &&
        test_must_fail git config branch.my5.remote &&
        test_must_fail git config branch.my5.merge
@@@ -351,7 -351,7 +352,7 @@@ test_expect_success 'test overriding tr
  test_expect_success 'no tracking without .fetch entries' '
        git config branch.autosetupmerge true &&
        git branch my6 s &&
 -      git config branch.automsetupmerge false &&
 +      git config branch.autosetupmerge false &&
        test -z "$(git config branch.my6.remote)" &&
        test -z "$(git config branch.my6.merge)"
  '
@@@ -425,14 -425,14 +426,14 @@@ test_expect_success '--set-upstream-to 
  test_expect_success 'use --set-upstream-to modify HEAD' '
        test_config branch.master.remote foo &&
        test_config branch.master.merge foo &&
 -      git branch my12
 +      git branch my12 &&
        git branch --set-upstream-to my12 &&
        test "$(git config branch.master.remote)" = "." &&
        test "$(git config branch.master.merge)" = "refs/heads/my12"
  '
  
  test_expect_success 'use --set-upstream-to modify a particular branch' '
 -      git branch my13
 +      git branch my13 &&
        git branch --set-upstream-to master my13 &&
        test "$(git config branch.my13.remote)" = "." &&
        test "$(git config branch.my13.merge)" = "refs/heads/master"
@@@ -443,7 -443,7 +444,7 @@@ test_expect_success '--unset-upstream s
  '
  
  test_expect_success 'test --unset-upstream on HEAD' '
 -      git branch my14
 +      git branch my14 &&
        test_config branch.master.remote foo &&
        test_config branch.master.merge foo &&
        git branch --set-upstream-to my14 &&
@@@ -465,7 -465,7 +466,7 @@@ test_expect_success '--unset-upstream s
  '
  
  test_expect_success 'test --unset-upstream on a particular branch' '
 -      git branch my15
 +      git branch my15 &&
        git branch --set-upstream-to master my14 &&
        git branch --unset-upstream my14 &&
        test_must_fail git config branch.my14.remote &&
@@@ -871,4 -871,39 +872,39 @@@ test_expect_success '--merged catches i
        test_must_fail git branch --merged 0000000000000000000000000000000000000000
  '
  
+ test_expect_success 'tracking with unexpected .fetch refspec' '
+       rm -rf a b c d &&
+       git init a &&
+       (
+               cd a &&
+               test_commit a
+       ) &&
+       git init b &&
+       (
+               cd b &&
+               test_commit b
+       ) &&
+       git init c &&
+       (
+               cd c &&
+               test_commit c &&
+               git remote add a ../a &&
+               git remote add b ../b &&
+               git fetch --all
+       ) &&
+       git init d &&
+       (
+               cd d &&
+               git remote add c ../c &&
+               git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
+               git fetch c &&
+               git branch --track local/a/master remotes/a/master &&
+               test "$(git config branch.local/a/master.remote)" = "c" &&
+               test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
+               git rev-parse --verify a >expect &&
+               git rev-parse --verify local/a/master >actual &&
+               test_cmp expect actual
+       )
+ '
  test_done