]> git.ipfire.org Git - thirdparty/git.git/commitdiff
restore: support --patch
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Thu, 25 Apr 2019 09:45:54 +0000 (16:45 +0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 May 2019 04:04:47 +0000 (13:04 +0900)
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: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c
git-add--interactive.perl

index 824ab65886c0f5778be250331174ee13b1c67b6f..bed79ae595cb84cf810fd0c247025226b76fbb54 100644 (file)
@@ -454,9 +454,11 @@ static int checkout_paths(const struct checkout_opts *opts,
                        patch_mode = "--patch=checkout";
                else if (opts->checkout_index && !opts->checkout_worktree)
                        patch_mode = "--patch=reset";
+               else if (!opts->checkout_index && opts->checkout_worktree)
+                       patch_mode = "--patch=worktree";
                else
-                       die(_("'%s' with only '%s' is not currently supported"),
-                           "--patch", "--worktree");
+                       BUG("either flag must have been set, worktree=%d, index=%d",
+                           opts->checkout_worktree, opts->checkout_index);
                return run_add_interactive(revision, patch_mode, &opts->pathspec);
        }
 
index 20eb81cc92f947d872b31a179d43d97772ff25e4..3dfb3629c99617e83e75c5652fa567ad589f551a 100755 (executable)
@@ -149,6 +149,20 @@ my %patch_modes = (
                FILTER => undef,
                IS_REVERSE => 0,
        },
+       'worktree_head' => {
+               DIFF => 'diff-index -p',
+               APPLY => sub { apply_patch 'apply -R', @_ },
+               APPLY_CHECK => 'apply -R',
+               FILTER => undef,
+               IS_REVERSE => 1,
+       },
+       'worktree_nothead' => {
+               DIFF => 'diff-index -R -p',
+               APPLY => sub { apply_patch 'apply', @_ },
+               APPLY_CHECK => 'apply',
+               FILTER => undef,
+               IS_REVERSE => 0,
+       },
 );
 
 $patch_mode = 'stage';
@@ -1049,6 +1063,12 @@ marked for discarding."),
 marked for discarding."),
        checkout_nothead => N__(
 "If the patch applies cleanly, the edited hunk will immediately be
+marked for applying."),
+       worktree_head => N__(
+"If the patch applies cleanly, the edited hunk will immediately be
+marked for discarding."),
+       worktree_nothead => N__(
+"If the patch applies cleanly, the edited hunk will immediately be
 marked for applying."),
 );
 
@@ -1259,6 +1279,18 @@ d - do not discard this hunk or any of the later hunks in the file"),
 n - do not apply this hunk to index and worktree
 q - quit; do not apply this hunk or any of the remaining ones
 a - apply this hunk and all later hunks in the file
+d - do not apply this hunk or any of the later hunks in the file"),
+       worktree_head => N__(
+"y - discard this hunk from worktree
+n - do not discard this hunk from worktree
+q - quit; do not discard this hunk or any of the remaining ones
+a - discard this hunk and all later hunks in the file
+d - do not discard this hunk or any of the later hunks in the file"),
+       worktree_nothead => N__(
+"y - apply this hunk to worktree
+n - do not apply this hunk to worktree
+q - quit; do not apply this hunk or any of the remaining ones
+a - apply this hunk and all later hunks in the file
 d - do not apply this hunk or any of the later hunks in the file"),
 );
 
@@ -1421,6 +1453,16 @@ my %patch_update_prompt_modes = (
                deletion => N__("Apply deletion to index and worktree [y,n,q,a,d%s,?]? "),
                hunk => N__("Apply this hunk to index and worktree [y,n,q,a,d%s,?]? "),
        },
+       worktree_head => {
+               mode => N__("Discard mode change from worktree [y,n,q,a,d%s,?]? "),
+               deletion => N__("Discard deletion from worktree [y,n,q,a,d%s,?]? "),
+               hunk => N__("Discard this hunk from worktree [y,n,q,a,d%s,?]? "),
+       },
+       worktree_nothead => {
+               mode => N__("Apply mode change to worktree [y,n,q,a,d%s,?]? "),
+               deletion => N__("Apply deletion to worktree [y,n,q,a,d%s,?]? "),
+               hunk => N__("Apply this hunk to worktree [y,n,q,a,d%s,?]? "),
+       },
 );
 
 sub patch_update_file {
@@ -1756,6 +1798,16 @@ sub process_args {
                                                       'checkout_head' : 'checkout_nothead');
                                        $arg = shift @ARGV or die __("missing --");
                                }
+                       } elsif ($1 eq 'worktree') {
+                               $arg = shift @ARGV or die __("missing --");
+                               if ($arg eq '--') {
+                                       $patch_mode = 'checkout_index';
+                               } else {
+                                       $patch_mode_revision = $arg;
+                                       $patch_mode = ($arg eq 'HEAD' ?
+                                                      'worktree_head' : 'worktree_nothead');
+                                       $arg = shift @ARGV or die __("missing --");
+                               }
                        } elsif ($1 eq 'stage' or $1 eq 'stash') {
                                $patch_mode = $1;
                                $arg = shift @ARGV or die __("missing --");