mbox series

[v1,00/11] And new command "restore"

Message ID 20190308101655.9767-1-pclouds@gmail.com (mailing list archive)
Headers show
Series And new command "restore" | expand

Message

Duy Nguyen March 8, 2019, 10:16 a.m. UTC
This is the companion of "git switch" [1] and is based on that topic.
This command peforms the "checkout paths" from git-checkout, git-reset
and also has a third mode to reset only worktree, leaving the index
alone.

For new people not aware of previous discussions, this command is
supposed to be a friendlier replacement for "git checkout" and
hopefully fixes some warts that have grown over the time in git-checkout.
For this reason, the last patch starts to recommend "git restore"
everywhere.

For old people, I'm surprised nobody reacts to the command rename from
restore-files to restore. "restore" vs "reset" is certainly confusing.
My hope was to remove "common porcelain" status from reset, but I
probably will not succeed in doing that.

Some open issues from the last discussion [2]

- intent-to-add support. This will come but maybe later.

- --index has a different meaning in git-apply. I don't have a good
  suggestion except "yeah we have two different worlds now, the old
  and the new one"

The series is also available at [3]

[1] https://public-inbox.org/git/20190308095752.8574-1-pclouds@gmail.com
[2] https://public-inbox.org/git/CACsJy8CQhWeC3b6eGPePuRejfOx7c17X61-wqq5kOiRzYkRESw@mail.gmail.com/
[3] https://gitlab.com/pclouds/git/tree/switch-and-restore

Nguyễn Thái Ngọc Duy (11):
  checkout: split part of it to new command 'restore'
  restore: take tree-ish from --source option instead
  restore: make pathspec mandatory
  restore: disable overlay mode by default
  checkout: factor out worktree checkout code
  restore: add --worktree and --index
  restore: default to --source=HEAD when only --index is specified
  restore: support --patch
  t: add tests for restore
  completion: support restore
  doc: promote "git restore"

 .gitignore                             |   1 +
 Documentation/config/interactive.txt   |   3 +-
 Documentation/git-checkout.txt         |   1 +
 Documentation/git-clean.txt            |   2 +-
 Documentation/git-commit.txt           |   4 +-
 Documentation/git-format-patch.txt     |   2 +-
 Documentation/git-reset.txt            |   6 +-
 Documentation/git-restore.txt (new)    | 172 ++++++++++++++++
 Documentation/git-revert.txt           |   4 +-
 Documentation/gitcli.txt               |   4 +-
 Documentation/giteveryday.txt          |   4 +-
 Documentation/gittutorial-2.txt        |   4 +-
 Documentation/gittutorial.txt          |   2 +-
 Documentation/user-manual.txt          |  14 +-
 Makefile                               |   1 +
 builtin.h                              |   1 +
 builtin/checkout.c                     | 259 +++++++++++++++++++------
 builtin/clone.c                        |   2 +-
 builtin/commit.c                       |   2 +-
 command-list.txt                       |   3 +-
 contrib/completion/git-completion.bash |  15 ++
 git-add--interactive.perl              |  52 +++++
 git.c                                  |   1 +
 t/lib-patch-mode.sh                    |  12 ++
 t/t2070-restore.sh (new +x)            |  77 ++++++++
 t/t2071-restore-patch.sh (new +x)      | 105 ++++++++++
 t/t7508-status.sh                      |  82 ++++----
 t/t7512-status-help.sh                 |  20 +-
 wt-status.c                            |  26 ++-
 29 files changed, 736 insertions(+), 145 deletions(-)
 create mode 100644 Documentation/git-restore.txt
 create mode 100755 t/t2070-restore.sh
 create mode 100755 t/t2071-restore-patch.sh

Comments

Duy Nguyen March 10, 2019, 11:19 a.m. UTC | #1
On Fri, Mar 8, 2019 at 5:17 PM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> - --index has a different meaning in git-apply. I don't have a good
>   suggestion except "yeah we have two different worlds now, the old
>   and the new one"

I will rename --index to --staged to avoid this. It is already used as
synonym for --cached in git-diff. I will also add --staged as synonym
to "git rm" so that "git status" can consistently advise "git <verb>
--staged" where verb is either restore or rm.

Since option rename is a lot of work. If you think this is not a good
move, raise it now, even if it's just "I don't like it, no reasons".
Jacob Keller March 10, 2019, 10:45 p.m. UTC | #2
On March 10, 2019 4:19:28 AM PDT, Duy Nguyen <pclouds@gmail.com> wrote:
>On Fri, Mar 8, 2019 at 5:17 PM Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>wrote:
>> - --index has a different meaning in git-apply. I don't have a good
>>   suggestion except "yeah we have two different worlds now, the old
>>   and the new one"
>
>I will rename --index to --staged to avoid this. It is already used as
>synonym for --cached in git-diff. I will also add --staged as synonym
>to "git rm" so that "git status" can consistently advise "git <verb>
>--staged" where verb is either restore or rm.
>
>Since option rename is a lot of work. If you think this is not a good
>move, raise it now, even if it's just "I don't like it, no reasons".

For what it's worth, I think this is a good rename.

Thanks,
Jake
Elijah Newren March 11, 2019, 4:01 p.m. UTC | #3
On Sun, Mar 10, 2019 at 4:19 AM Duy Nguyen <pclouds@gmail.com> wrote:
>
> On Fri, Mar 8, 2019 at 5:17 PM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> > - --index has a different meaning in git-apply. I don't have a good
> >   suggestion except "yeah we have two different worlds now, the old
> >   and the new one"
>
> I will rename --index to --staged to avoid this. It is already used as
> synonym for --cached in git-diff. I will also add --staged as synonym
> to "git rm" so that "git status" can consistently advise "git <verb>
> --staged" where verb is either restore or rm.
>
> Since option rename is a lot of work. If you think this is not a good
> move, raise it now, even if it's just "I don't like it, no reasons".
> --

Works for me, but this sounds like the kind of thing Junio might
object to, so I'm curious about his input.
Junio C Hamano March 13, 2019, 10:58 p.m. UTC | #4
Duy Nguyen <pclouds@gmail.com> writes:

> On Fri, Mar 8, 2019 at 5:17 PM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
>> - --index has a different meaning in git-apply. I don't have a good
>>   suggestion except "yeah we have two different worlds now, the old
>>   and the new one"
>
> I will rename --index to --staged to avoid this. It is already used as
> synonym for --cached in git-diff. I will also add --staged as synonym
> to "git rm" so that "git status" can consistently advise "git <verb>
> --staged" where verb is either restore or rm.

Does "restore --index" (now "--staged") work the same way as
"--cached" aka "--staged" in git-diff?  "--cached" is about
affecting only what is in the index (as opposed to "--index"
affecting both the index and the working tree).

If it does, then calling it "--cached" aka "--staged" does make more
sense than calling it "--index", I would think.  Otherwise, such a
rename does not buy us much.
Duy Nguyen March 14, 2019, 3:49 a.m. UTC | #5
On Thu, Mar 14, 2019 at 5:58 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Duy Nguyen <pclouds@gmail.com> writes:
>
> > On Fri, Mar 8, 2019 at 5:17 PM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> >> - --index has a different meaning in git-apply. I don't have a good
> >>   suggestion except "yeah we have two different worlds now, the old
> >>   and the new one"
> >
> > I will rename --index to --staged to avoid this. It is already used as
> > synonym for --cached in git-diff. I will also add --staged as synonym
> > to "git rm" so that "git status" can consistently advise "git <verb>
> > --staged" where verb is either restore or rm.
>
> Does "restore --index" (now "--staged") work the same way as
> "--cached" aka "--staged" in git-diff?  "--cached" is about
> affecting only what is in the index (as opposed to "--index"
> affecting both the index and the working tree).

Yes. To affect both you would need --staged --worktree (or -WS for
short because I don't think anybody is going to type that many
characters)

> If it does, then calling it "--cached" aka "--staged" does make more
> sense than calling it "--index", I would think.  Otherwise, such a
> rename does not buy us much.