1. 11 Jun, 2018 4 commits
    • Ævar Arnfjörð Bjarmason's avatar
      checkout & worktree: introduce checkout.defaultRemote · 8d7b558b
      Ævar Arnfjörð Bjarmason authored
      Introduce a checkout.defaultRemote setting which can be used to
      designate a remote to prefer (via checkout.defaultRemote=origin) when
      running e.g. "git checkout master" to mean origin/master, even though
      there's other remotes that have the "master" branch.
      
      I want this because it's very handy to use this workflow to checkout a
      repository and create a topic branch, then get back to a "master" as
      retrieved from upstream:
      
          (
              cd /tmp &&
              rm -rf tbdiff &&
              git clone git@github.com:trast/tbdiff.git &&
              cd tbdiff &&
              git branch -m topic &&
              git checkout master
          )
      
      That will output:
      
          Branch 'master' set up to track remote branch 'master' from 'origin'.
          Switched to a new branch 'master'
      
      But as soon as a new remote is added (e.g. just to inspect something
      from someone else) the DWIMery goes away:
      
          (
              cd /tmp &&
              rm -rf tbdiff &&
              git clone git@github.com:trast/tbdiff.git &&
              cd tbdiff &&
              git branch -m topic &&
              git remote add avar git@github.com:avar/tbdiff.git &&
              git fetch avar &&
              git checkout master
          )
      
      Will output (without the advice output added earlier in this series):
      
          error: pathspec 'master' did not match any file(s) known to git.
      
      The new checkout.defaultRemote config allows me to say that whenever
      that ambiguity comes up I'd like to prefer "origin", and it'll still
      work as though the only remote I had was "origin".
      
      Also adjust the advice.checkoutAmbiguousRemoteBranchName message to
      mention this new config setting to the user, the full output on my
      git.git is now (the last paragraph is new):
      
          $ ./git --exec-path=$PWD checkout master
          error: pathspec 'master' did not match any file(s) known to git.
          hint: 'master' matched more than one remote tracking branch.
          hint: We found 26 remotes with a reference that matched. So we fell back
          hint: on trying to resolve the argument as a path, but failed there too!
          hint:
          hint: If you meant to check out a remote tracking branch on, e.g. 'origin',
          hint: you can do so by fully qualifying the name with the --track option:
          hint:
          hint:     git checkout --track origin/<name>
          hint:
          hint: If you'd like to always have checkouts of an ambiguous <name> prefer
          hint: one remote, e.g. the 'origin' remote, consider setting
          hint: checkout.defaultRemote=origin in your config.
      
      I considered splitting this into checkout.defaultRemote and
      worktree.defaultRemote, but it's probably less confusing to break our
      own rules that anything shared between config should live in core.*
      than have two config settings, and I couldn't come up with a short
      name under core.* that made sense (core.defaultRemoteForCheckout?).
      
      See also 70c9ac2f ("DWIM "git checkout frotz" to "git checkout -b
      frotz origin/frotz"", 2009-10-18) which introduced this DWIM feature
      to begin with, and 4e853331 ("worktree: make add <path> <branch>
      dwim", 2017-11-26) which added it to git-worktree.
      Signed-off-by: Ævar Arnfjörð Bjarmason's avatarÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
      8d7b558b
    • Ævar Arnfjörð Bjarmason's avatar
      checkout: pass the "num_matches" up to callers · 3c87aa94
      Ævar Arnfjörð Bjarmason authored
      Pass the previously added "num_matches" struct value up to the callers
      of unique_tracking_name(). This will allow callers to optionally print
      better error messages in a later change.
      Signed-off-by: Ævar Arnfjörð Bjarmason's avatarÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
      3c87aa94
    • Ævar Arnfjörð Bjarmason's avatar
      checkout.c: change "unique" member to "num_matches" · e4d2d55a
      Ævar Arnfjörð Bjarmason authored
      Internally track how many matches we find in the check_tracking_name()
      callback. Nothing uses this now, but it will be made use of in a later
      change.
      Signed-off-by: Ævar Arnfjörð Bjarmason's avatarÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
      e4d2d55a
    • Ævar Arnfjörð Bjarmason's avatar
      checkout.c: introduce an *_INIT macro · e417151b
      Ævar Arnfjörð Bjarmason authored
      Add an *_INIT macro for the tracking_name_data similar to what exists
      elsewhere in the codebase, e.g. OID_ARRAY_INIT in sha1-array.h. This
      will make it more idiomatic in later changes to add more fields to the
      struct & its initialization macro.
      Signed-off-by: Ævar Arnfjörð Bjarmason's avatarÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
      e417151b
  2. 17 May, 2018 2 commits
  3. 27 Nov, 2017 1 commit