1. 07 5月, 2019 2 次提交
    • N
      restore: take tree-ish from --source option instead · c9c935f6
      Nguyễn Thái Ngọc Duy 提交于
      This is another departure from 'git checkout' syntax, which uses -- to
      separate ref and pathspec. The observation is restore (or "git
      checkout -- <pathspec>") is most often used to restore some files from
      the index. If this is correct, we can simplify it by taking away the
      ref, so that we can write
      
          git restore some-file
      
      without worrying about some-file being a ref and whether we need to do
      
          git restore -- some-file
      
      for safety. If the source of the restore comes from a tree, it will be
      in the form of an option with value, e.g.
      
          git restore --source=this-tree some-file
      
      This is of course longer to type than using "--". But hopefully it
      will not be used as often, and it is clearly easier to understand.
      
      dwim_new_local_branch is no longer set (or unset) in cmd_restore_files()
      because it's irrelevant because we don't really care about dwim-ing.
      With accept_ref being unset, dwim can't happen.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c9c935f6
    • N
      checkout: split part of it to new command 'restore' · 46e91b66
      Nguyễn Thái Ngọc Duy 提交于
      Previously the switching branch business of 'git checkout' becomes a
      new command 'switch'. This adds the restore command for the checking
      out paths path.
      
      Similar to git-switch, a new man page is added to describe what the
      command will become. The implementation will be updated shortly to
      match the man page.
      
      A couple main differences from 'git checkout <paths>':
      
      - 'restore' by default will only update worktree. This matters more
        when --source is specified ('checkout <tree> <paths>' updates both
        worktree and index).
      
      - 'restore --staged' can be used to restore the index. This command
        overlaps with 'git reset <paths>'.
      
      - both worktree and index could also be restored at the same time
        (from a tree) when both --staged and --worktree are specified. This
        overlaps with 'git checkout <tree> <paths>'
      
      - default source for restoring worktree and index is the index and
        HEAD respectively. A different (tree) source could be specified as
        with --source (*).
      
      - when both index and worktree are restored, --source must be
        specified since the default source for these two individual targets
        are different (**)
      
      - --no-overlay is enabled by default, if an entry is missing in the
        source, restoring means deleting the entry
      
      (*) I originally went with --from instead of --source. I still think
        --from is a better name. The short option -f however is already
        taken by force. And I do think short option is good to have, e.g. to
        write -s@ or -s@^ instead of --source=HEAD.
      
      (**) If you sit down and think about it, moving worktree's source from
        the index to HEAD makes sense, but nobody is really thinking it
        through when they type the commands.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      46e91b66
  2. 02 4月, 2019 18 次提交
  3. 23 2月, 2019 1 次提交
  4. 07 2月, 2019 2 次提交
    • N
      checkout: count and print -m paths separately · 1d1f689b
      Nguyễn Thái Ngọc Duy 提交于
      Since 0f086e6d (checkout: print something when checking out paths -
      2018-11-13), this command reports how many paths have been updated
      from what source (either from a tree, or from the index). I forget
      that there's a third source: when -m is used, the merge conflict is
      re-created (granted, also from the index, but it's not a straight copy
      from the index).
      
      Count and report unmerged paths separately. There's a bit more update
      to avoid reporting:
      
         Recreated X merge conflicts
         Updated 0 paths from the index
      
      The second line is unnecessary. Though if there's no conflict
      recreation, we still report
      
         Updated 0 paths from the index
      
      to make it clear we're not really doing anything.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1d1f689b
    • N
      checkout: update count-checkouts messages · 3c5883b3
      Nguyễn Thái Ngọc Duy 提交于
      Commit 0f086e6d [1] counts the number of files updated by "git
      checkout -- <paths>" command and prints it. Later on 536ec183 [2]
      adds the ability to remove files in "git checkout -- <paths>". This is
      still an update on worktree and should be reported to the user.
      
      To prepare for such an update since that commit is on track to
      'master' now, the messages are rephrased to avoid "checked out" which
      does not imply file deletion.
      
      [1] 0f086e6d (checkout: print something when checking out paths -
          2018-11-13)
      [2] 536ec183 (entry: support CE_WT_REMOVE flag in checkout_entry -
          2018-12-20)
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3c5883b3
  5. 05 2月, 2019 1 次提交
    • T
      revert "checkout: introduce checkout.overlayMode config" · e92aa0e4
      Thomas Gummerer 提交于
      This reverts 1495ff7d ("checkout: introduce checkout.overlayMode
      config", 2019-01-08) and thus removes the checkout.overlayMode config
      option.
      
      The option was originally introduced to give users the option to make
      the new no-overlay behaviour the default.  However users may be using
      'git checkout' in scripts, even though it is porcelain.  Users setting
      the option to false may actually end up accidentally breaking scripts.
      
      With the introduction of a new subcommand that will make the behaviour
      the default, the config option will not be needed anymore anyway.
      Revert the commit and remove the config option, so we don't risk
      breaking scripts.
      Suggested-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NThomas Gummerer <t.gummerer@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e92aa0e4
  6. 25 1月, 2019 1 次提交
  7. 24 1月, 2019 1 次提交
  8. 15 1月, 2019 2 次提交
  9. 09 1月, 2019 2 次提交
    • T
      checkout: introduce checkout.overlayMode config · 1495ff7d
      Thomas Gummerer 提交于
      In the previous patch we introduced a new no-overlay mode for git
      checkout.  Some users (such as the author of this commit) may want to
      have this mode turned on by default as it matches their mental model
      more closely.  Make that possible by introducing a new config option
      to that extend.
      Signed-off-by: NThomas Gummerer <t.gummerer@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1495ff7d
    • T
      checkout: introduce --{,no-}overlay option · 091e04bc
      Thomas Gummerer 提交于
      Currently 'git checkout' is defined as an overlay operation, which
      means that if in 'git checkout <tree-ish> -- [<pathspec>]' we have an
      entry in the index that matches <pathspec>, but that doesn't exist in
      <tree-ish>, that entry will not be removed from the index or the
      working tree.
      
      Introduce a new --{,no-}overlay option, which allows using 'git
      checkout' in non-overlay mode, thus removing files from the working
      tree if they do not exist in <tree-ish> but match <pathspec>.
      
      Note that 'git checkout -p <tree-ish> -- [<pathspec>]' already works
      this way, so no changes are needed for the patch mode.  We disallow
      'git checkout --overlay -p' to avoid confusing users who would expect
      to be able to force overlay mode in 'git checkout -p' this way.
      
      Untracked files are not affected by this change, so 'git checkout
      --no-overlay HEAD -- untracked' will not remove untracked from the
      working tree.  This is so e.g. 'git checkout --no-overlay HEAD -- dir/'
      doesn't delete all untracked files in dir/, but rather just resets the
      state of files that are known to git.
      Suggested-by: NJunio C Hamano <gitster@pobox.com>
      Signed-off-by: NThomas Gummerer <t.gummerer@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      091e04bc
  10. 03 1月, 2019 2 次提交
  11. 19 11月, 2018 1 次提交
  12. 14 11月, 2018 2 次提交
    • N
      checkout: print something when checking out paths · 0f086e6d
      Nguyễn Thái Ngọc Duy 提交于
      One of the problems with "git checkout" is that it does so many
      different things and could confuse people specially when we fail to
      handle ambiguation correctly.
      
      One way to help with that is tell the user what sort of operation is
      actually carried out. When switching branches, we always print
      something unless --quiet, either
      
       - "HEAD is now at ..."
       - "Reset branch ..."
       - "Already on ..."
       - "Switched to and reset ..."
       - "Switched to a new branch ..."
       - "Switched to branch ..."
      
      Checking out paths however is silent. Print something so that if we
      got the user intention wrong, they won't waste too much time to find
      that out. For the remaining cases of checkout we now print either
      
       - "Checked out ... paths out of the index"
       - "Checked out ... paths out of <abbrev hash>"
      
      Since the purpose of printing this is to help disambiguate. Only do it
      when "--" is missing.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0f086e6d
    • N
      checkout: disambiguate dwim tracking branches and local files · be4908f1
      Nguyễn Thái Ngọc Duy 提交于
      When checkout dwim is added in [1], it is restricted to only dwim when
      certain conditions are met and fall back to default checkout behavior
      otherwise. It turns out falling back could be confusing. One of the
      conditions to turn
      
          git checkout frotz
      
      to
      
          git checkout -b frotz origin/frotz
      
      is that frotz must not exist as a file. But when the user comes to
      expect "git checkout frotz" to create the branch "frotz" and there
      happens to be a file named "frotz", git's silently reverting "frotz"
      file content is not helping. This is reported in Git mailing list [2]
      and even used as an example of "Git is bad" elsewhere [3].
      
      We normally try to do the right thing, but when there are multiple
      "right things" to do, it's best to leave it to the user to decide.
      Check this case, ask the user to to disambiguate:
      
      - "git checkout -- foo" will check out path "foo"
      - "git checkout foo --" will dwim and create branch "foo" [4]
      
      For users who do not want dwim, use --no-guess. It's useless in this
      particular case because "git checkout --no-guess foo --" will just
      fail. But it could be used by scripts.
      
      [1] 70c9ac2f (DWIM "git checkout frotz" to "git checkout -b frotz
          origin/frotz" - 2009-10-18)
      [2] https://public-inbox.org/git/CACsJy8B2TVr1g+k+eSQ=pBEO3WN4_LtgLo9gpur8X7Z9GOFL_A@mail.gmail.com/
      [3] https://news.ycombinator.com/item?id=18230655
      [4] a047fafc (checkout: allow dwim for branch creation for "git
          checkout $branch --" - 2013-10-18)
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      be4908f1
  13. 12 11月, 2018 1 次提交
  14. 04 10月, 2018 1 次提交
  15. 22 9月, 2018 2 次提交
  16. 30 8月, 2018 1 次提交
    • J
      convert "oidcmp() == 0" to oideq() · 4a7e27e9
      Jeff King 提交于
      Using the more restrictive oideq() should, in the long run,
      give the compiler more opportunities to optimize these
      callsites. For now, this conversion should be a complete
      noop with respect to the generated code.
      
      The result is also perhaps a little more readable, as it
      avoids the "zero is equal" idiom. Since it's so prevalent in
      C, I think seasoned programmers tend not to even notice it
      anymore, but it can sometimes make for awkward double
      negations (e.g., we can drop a few !!oidcmp() instances
      here).
      
      This patch was generated almost entirely by the included
      coccinelle patch. This mechanical conversion should be
      completely safe, because we check explicitly for cases where
      oidcmp() is compared to 0, which is what oideq() is doing
      under the hood. Note that we don't have to catch "!oidcmp()"
      separately; coccinelle's standard isomorphisms make sure the
      two are treated equivalently.
      
      I say "almost" because I did hand-edit the coccinelle output
      to fix up a few style violations (it mostly keeps the
      original formatting, but sometimes unwraps long lines).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4a7e27e9