1. 07 5月, 2019 10 次提交
    • N
      restore: support --patch · 2f0896ec
      Nguyễn Thái Ngọc Duy 提交于
      git-restore is different from git-checkout that it only restores the
      worktree by default, not both worktree and index. add--interactive
      needs some update to support this mode.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2f0896ec
    • N
      restore: replace --force with --ignore-unmerged · a5e5f399
      Nguyễn Thái Ngọc Duy 提交于
      Use a more specific option name to express its purpose. --force may come
      back as an alias of --ignore-unmerged and possibly more. But since this
      is a destructive operation, I don't see why we need to "force" anything
      more. We already don't hold back.
      
      When 'checkout --force' or 'restore --ignore-unmerged' is used, we may
      also print warnings about unmerged entries being ignore. Since this is
      not exactly warning (people tell us to do so), more informational, let
      it be suppressed if --quiet is given. This is a behavior change for
      git-checkout.
      
      PS. The diff looks a bit iffy since --force is moved to
      add_common_switch_branch_options() (i.e. for switching). But
      git-checkout is also doing switching and inherits this --force.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a5e5f399
    • N
      restore: default to --source=HEAD when only --staged is specified · 3a733ce5
      Nguyễn Thái Ngọc Duy 提交于
      "git restore --staged" without --source does not make much sense since
      by default we restore from the index.  Instead of copying the index to
      itself, set the default source to HEAD in this case, yielding behavior
      that matches "git reset -- <paths>".
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3a733ce5
    • N
      restore: reject invalid combinations with --staged · e3ddd3b5
      Nguyễn Thái Ngọc Duy 提交于
      git-checkout rejects plenty of invalid option combinations. Since
      git-checkout is equivalent of either
      
          git restore --source --staged --worktree
      
      or
      
          git restore --worktree
      
      that still leaves the new mode 'git restore --index' unprotected. Reject
      some more invalid option combinations.
      
      The other new mode 'restore --source --worktree' does not need anything
      else.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e3ddd3b5
    • N
      restore: add --worktree and --staged · 183fb44f
      Nguyễn Thái Ngọc Duy 提交于
      'git checkout <tree-ish> <pathspec>' updates both index and
      worktree. But updating the index when you want to restore worktree
      files is non-intuitive. The index contains the data ready for the next
      commit, and there's no indication that the user will want to commit
      the restored versions.
      
      'git restore' therefore by default only touches worktree. The user has
      the option to update either the index with
      
          git restore --staged --source=<tree> <path>  (1)
      
      or update both with
      
          git restore --staged --worktree --source=<tree> <path> (2)
      
      PS. Orignally I wanted to make worktree update default and form (1)
      would add index update while also updating the worktree, and the user
      would need to do "--staged --no-worktree" to update index only. But it
      looks really confusing that "--staged" option alone updates both. So
      now form (2) is used for both, which reads much more obvious.
      
      PPS. Yes form (1) overlaps with "git reset <rev> <path>". I don't know
      if we can ever turn "git reset" back to "_always_ reset HEAD and
      optionally do something else".
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      183fb44f
    • N
    • N
      restore: disable overlay mode by default · a6cfb9ba
      Nguyễn Thái Ngọc Duy 提交于
      Overlay mode is considered confusing when the command is about
      restoring files on worktree. Disable it by default. The user can still
      turn it on, or use 'git checkout' which still has overlay mode on by
      default.
      
      While at it, make the check in checkout_branch() stricter. Neither
      --overlay or --no-overlay should be accepted in branch switching mode.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a6cfb9ba
    • N
      restore: make pathspec mandatory · be8ed502
      Nguyễn Thái Ngọc Duy 提交于
      "git restore" without arguments does not make much sense when
      it's about restoring files (what files now?). We could default to
      either
      
          git restore .
      
      or
      
          git restore :/
      
      Neither is intuitive. Make the user always give pathspec, force the
      user to think the scope of restore they want because this is a
      destructive operation.
      
      "git restore -p" without pathspec is an exception to this
      because it really is a separate mode. It will be treated as running
      patch mode on the whole worktree.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      be8ed502
    • 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 27 次提交
  3. 11 3月, 2019 3 次提交