{"thread":{"id":"53397","subject":"[PATCH v2 0/1] enhance \"git restore --worktree --staged\" behavior","startedAt":"2020-05-05T07:18:17Z","lastAt":"2020-05-05T16:04:04Z","messageCount":3,"participants":["Eric Sunshine","Taylor Blau"],"isPatch":true,"patchVersion":2,"patchTotal":1},"messages":[{"id":"397056","messageId":"20200505071716.23240-1-sunshine@sunshineco.com","threadId":"53397","inReplyTo":null,"subject":"[PATCH v2 0/1] enhance \"git restore --worktree --staged\" behavior","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-05-05T07:17:15Z","receivedAt":"2020-05-05T07:18:17Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"This is a re-roll of [1] which enhances git-restore to default --source\nto HEAD when --worktree and --staged are combined.\n\nChanges since v1:\n\n* tighten the commit message and documentation changes as requested by\n  Junio[2]\n\n* drop patch 1/2 since 2/2 threw away all the changes from 1/2, and the\n  end result is the same with or without 1/2\n\nAlthough the code is identical between v1 and v2, I didn't include\nTaylor's \"Reviewed-by:\"[3,4] since the documentation changes have been\nrefined a bit.\n\n[1]: https://lore.kernel.org/git/20200501082746.23943-1-sunshine@sunshineco.com/\n[2]: https://lore.kernel.org/git/xmqqimhfoelf.fsf@gitster.c.googlers.com/\n[3]: https://lore.kernel.org/git/20200501221613.GC41612@syl.local/\n[4]: https://lore.kernel.org/git/20200501221951.GD41612@syl.local/\n\nEric Sunshine (1):\n  restore: default to HEAD when combining --staged and --worktree\n\n Documentation/git-restore.txt | 11 ++++-------\n builtin/checkout.c            |  6 +++---\n t/t2070-restore.sh            | 11 +++++++++++\n 3 files changed, 18 insertions(+), 10 deletions(-)\n\nInterdiff against v1:\ndiff --git a/Documentation/git-restore.txt b/Documentation/git-restore.txt\nindex 5b61812e17..84c6c40010 100644\n--- a/Documentation/git-restore.txt\n+++ b/Documentation/git-restore.txt\n@@ -22,10 +22,8 @@ The command can also be used to restore the content in the index with\n `--staged`, or restore both the working tree and the index with\n `--staged --worktree`.\n \n-By default, the restore source for `--worktree` is the index, and the\n-restore source for `--staged` is `HEAD`. When combining `--worktree` and\n-`--staged`, the restore source is `HEAD`. `--source` can be used to specify\n-a different commit as the restore source.\n+By default, if `--staged` is given, the contents are restored from `HEAD`,\n+otherwise from the index. Use `--source` to restore from a different commit.\n \n See \"Reset, restore and revert\" in linkgit:git[1] for the differences\n between the three commands.\n@@ -40,10 +38,8 @@ OPTIONS\n \ttree. It is common to specify the source tree by naming a\n \tcommit, branch or tag associated with it.\n +\n-If not specified, the default restore source for `--worktree` is\n-the index, and the default restore source for `--staged` is\n-`HEAD`. When both `--staged` and `--worktree` are specified,\n-the default restore source is `HEAD`.\n+If not specified, the contents are restored from `HEAD` if `--staged` is\n+given, otherwise from the index.\n \n -p::\n --patch::\n-- \n2.26.2.672.g232c24e857\n\n"},{"id":"397057","messageId":"20200505071716.23240-2-sunshine@sunshineco.com","threadId":"53397","inReplyTo":"20200505071716.23240-1-sunshine@sunshineco.com","subject":"[PATCH v2 1/1] restore: default to HEAD when combining --staged and --worktree","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-05-05T07:17:16Z","receivedAt":"2020-05-05T07:18:18Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"By default, files are restored from the index for --worktree, and from\nHEAD for --staged. When --worktree and --staged are combined, --source\nmust be specified to disambiguate the restore source[1], thus making it\ncumbersome to restore a file in both the worktree and the index.\n\nHowever, HEAD is also a reasonable default for --worktree when combined\nwith --staged, so make it the default anytime --staged is used (whether\ncombined with --worktree or not).\n\n[1]: Due to an oversight, the --source requirement, though documented,\nis not actually enforced.\n\nSigned-off-by: Eric Sunshine <sunshine@sunshineco.com>\n---\n Documentation/git-restore.txt | 11 ++++-------\n builtin/checkout.c            |  6 +++---\n t/t2070-restore.sh            | 11 +++++++++++\n 3 files changed, 18 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/git-restore.txt b/Documentation/git-restore.txt\nindex 8e3b339802..84c6c40010 100644\n--- a/Documentation/git-restore.txt\n+++ b/Documentation/git-restore.txt\n@@ -22,9 +22,8 @@ The command can also be used to restore the content in the index with\n `--staged`, or restore both the working tree and the index with\n `--staged --worktree`.\n \n-By default, the restore sources for working tree and the index are the\n-index and `HEAD` respectively. `--source` could be used to specify a\n-commit as the restore source.\n+By default, if `--staged` is given, the contents are restored from `HEAD`,\n+otherwise from the index. Use `--source` to restore from a different commit.\n \n See \"Reset, restore and revert\" in linkgit:git[1] for the differences\n between the three commands.\n@@ -39,10 +38,8 @@ OPTIONS\n \ttree. It is common to specify the source tree by naming a\n \tcommit, branch or tag associated with it.\n +\n-If not specified, the default restore source for the working tree is\n-the index, and the default restore source for the index is\n-`HEAD`. When both `--staged` and `--worktree` are specified,\n-`--source` must also be specified.\n+If not specified, the contents are restored from `HEAD` if `--staged` is\n+given, otherwise from the index.\n \n -p::\n --patch::\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 8bc94d392b..500c3e23ff 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -1605,10 +1605,10 @@ static int checkout_main(int argc, const char **argv, const char *prefix,\n \tif (opts->checkout_index < 0 || opts->checkout_worktree < 0)\n \t\tBUG(\"these flags should be non-negative by now\");\n \t/*\n-\t * convenient shortcut: \"git restore --staged\" equals\n-\t * \"git restore --staged --source HEAD\"\n+\t * convenient shortcut: \"git restore --staged [--worktree]\" equals\n+\t * \"git restore --staged [--worktree] --source HEAD\"\n \t */\n-\tif (!opts->from_treeish && opts->checkout_index && !opts->checkout_worktree)\n+\tif (!opts->from_treeish && opts->checkout_index)\n \t\topts->from_treeish = \"HEAD\";\n \n \t/*\ndiff --git a/t/t2070-restore.sh b/t/t2070-restore.sh\nindex 076d0df7fc..89e5a142c9 100755\n--- a/t/t2070-restore.sh\n+++ b/t/t2070-restore.sh\n@@ -69,6 +69,17 @@ test_expect_success 'restore --staged uses HEAD as source' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'restore --worktree --staged uses HEAD as source' '\n+\ttest_when_finished git reset --hard &&\n+\tgit show HEAD:./first.t >expected &&\n+\techo dirty >>first.t &&\n+\tgit add first.t &&\n+\tgit restore --worktree --staged first.t &&\n+\tgit show :./first.t >actual &&\n+\ttest_cmp expected actual &&\n+\ttest_cmp expected first.t\n+'\n+\n test_expect_success 'restore --ignore-unmerged ignores unmerged entries' '\n \tgit init unmerged &&\n \t(\n-- \n2.26.2.672.g232c24e857\n\n"},{"id":"397105","messageId":"20200505160400.GC69300@syl.local","threadId":"53397","inReplyTo":"20200505071716.23240-2-sunshine@sunshineco.com","subject":"Re: [PATCH v2 1/1] restore: default to HEAD when combining --staged and --worktree","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-05-05T16:04:00Z","receivedAt":"2020-05-05T16:04:04Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Tue, May 05, 2020 at 03:17:16AM -0400, Eric Sunshine wrote:\n> By default, files are restored from the index for --worktree, and from\n> HEAD for --staged. When --worktree and --staged are combined, --source\n> must be specified to disambiguate the restore source[1], thus making it\n> cumbersome to restore a file in both the worktree and the index.\n>\n> However, HEAD is also a reasonable default for --worktree when combined\n> with --staged, so make it the default anytime --staged is used (whether\n> combined with --worktree or not).\n>\n> [1]: Due to an oversight, the --source requirement, though documented,\n> is not actually enforced.\n>\n> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>\n> ---\n>  Documentation/git-restore.txt | 11 ++++-------\n>  builtin/checkout.c            |  6 +++---\n>  t/t2070-restore.sh            | 11 +++++++++++\n>  3 files changed, 18 insertions(+), 10 deletions(-)\n\nThanks, the new version looks good to me, too.\n\n  Reviewed-by: Taylor Blau <me@ttaylorr.com>\n\nThanks,\nTaylor\n"}]}