Merge branch 'nd/switch-and-restore'

Two new commands "git switch" and "git restore" are introduced to
split "checking out a branch to work on advancing its history" and
"checking out paths out of the index and/or a tree-ish to work on
advancing the current history" out of the single "git checkout"
command.

* nd/switch-and-restore: (46 commits)
  completion: disable dwim on "git switch -d"
  switch: allow to switch in the middle of bisect
  t2027: use test_must_be_empty
  Declare both git-switch and git-restore experimental
  help: move git-diff and git-reset to different groups
  doc: promote "git restore"
  user-manual.txt: prefer 'merge --abort' over 'reset --hard'
  completion: support restore
  t: add tests for restore
  restore: support --patch
  restore: replace --force with --ignore-unmerged
  restore: default to --source=HEAD when only --staged is specified
  restore: reject invalid combinations with --staged
  restore: add --worktree and --staged
  checkout: factor out worktree checkout code
  restore: disable overlay mode by default
  restore: make pathspec mandatory
  restore: take tree-ish from --source option instead
  checkout: split part of it to new command 'restore'
  doc: promote "git switch"
  ...
This commit is contained in:
Junio C Hamano
2019-07-09 15:25:44 -07:00
65 changed files with 1956 additions and 700 deletions

View File

@ -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';
@ -1053,6 +1067,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."),
);
@ -1263,6 +1283,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"),
);
@ -1425,6 +1457,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 {
@ -1760,6 +1802,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 --");