Merge branch 'jk/reset-p-current-head-fix'
"git reset -p HEAD" has codepath to special case it from resetting to contents of other commits, but recent change broke it. * jk/reset-p-current-head-fix: reset: pass real rev name to add--interactive add-interactive: handle unborn branch in patch mode
This commit is contained in:
commit
1feb458fb9
@ -304,7 +304,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
|
|||||||
if (patch_mode) {
|
if (patch_mode) {
|
||||||
if (reset_type != NONE)
|
if (reset_type != NONE)
|
||||||
die(_("--patch is incompatible with --{hard,mixed,soft}"));
|
die(_("--patch is incompatible with --{hard,mixed,soft}"));
|
||||||
return run_add_interactive(sha1_to_hex(sha1), "--patch=reset", &pathspec);
|
return run_add_interactive(rev, "--patch=reset", &pathspec);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* git reset tree [--] paths... can be used to
|
/* git reset tree [--] paths... can be used to
|
||||||
|
@ -263,6 +263,17 @@ sub get_empty_tree {
|
|||||||
return '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
|
return '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_diff_reference {
|
||||||
|
my $ref = shift;
|
||||||
|
if (defined $ref and $ref ne 'HEAD') {
|
||||||
|
return $ref;
|
||||||
|
} elsif (is_initial_commit()) {
|
||||||
|
return get_empty_tree();
|
||||||
|
} else {
|
||||||
|
return 'HEAD';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Returns list of hashes, contents of each of which are:
|
# Returns list of hashes, contents of each of which are:
|
||||||
# VALUE: pathname
|
# VALUE: pathname
|
||||||
# BINARY: is a binary path
|
# BINARY: is a binary path
|
||||||
@ -286,14 +297,7 @@ sub list_modified {
|
|||||||
return if (!@tracked);
|
return if (!@tracked);
|
||||||
}
|
}
|
||||||
|
|
||||||
my $reference;
|
my $reference = get_diff_reference($patch_mode_revision);
|
||||||
if (defined $patch_mode_revision and $patch_mode_revision ne 'HEAD') {
|
|
||||||
$reference = $patch_mode_revision;
|
|
||||||
} elsif (is_initial_commit()) {
|
|
||||||
$reference = get_empty_tree();
|
|
||||||
} else {
|
|
||||||
$reference = 'HEAD';
|
|
||||||
}
|
|
||||||
for (run_cmd_pipe(qw(git diff-index --cached
|
for (run_cmd_pipe(qw(git diff-index --cached
|
||||||
--numstat --summary), $reference,
|
--numstat --summary), $reference,
|
||||||
'--', @tracked)) {
|
'--', @tracked)) {
|
||||||
@ -737,7 +741,7 @@ sub parse_diff {
|
|||||||
splice @diff_cmd, 1, 0, "--diff-algorithm=${diff_algorithm}";
|
splice @diff_cmd, 1, 0, "--diff-algorithm=${diff_algorithm}";
|
||||||
}
|
}
|
||||||
if (defined $patch_mode_revision) {
|
if (defined $patch_mode_revision) {
|
||||||
push @diff_cmd, $patch_mode_revision;
|
push @diff_cmd, get_diff_reference($patch_mode_revision);
|
||||||
}
|
}
|
||||||
my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path);
|
my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path);
|
||||||
my @colored = ();
|
my @colored = ();
|
||||||
|
@ -25,15 +25,17 @@ test_expect_success PERL 'saying "n" does nothing' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success PERL 'git reset -p' '
|
test_expect_success PERL 'git reset -p' '
|
||||||
(echo n; echo y) | git reset -p &&
|
(echo n; echo y) | git reset -p >output &&
|
||||||
verify_state dir/foo work head &&
|
verify_state dir/foo work head &&
|
||||||
verify_saved_state bar
|
verify_saved_state bar &&
|
||||||
|
test_i18ngrep "Unstage" output
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success PERL 'git reset -p HEAD^' '
|
test_expect_success PERL 'git reset -p HEAD^' '
|
||||||
(echo n; echo y) | git reset -p HEAD^ &&
|
(echo n; echo y) | git reset -p HEAD^ >output &&
|
||||||
verify_state dir/foo work parent &&
|
verify_state dir/foo work parent &&
|
||||||
verify_saved_state bar
|
verify_saved_state bar &&
|
||||||
|
test_i18ngrep "Apply" output
|
||||||
'
|
'
|
||||||
|
|
||||||
# The idea in the rest is that bar sorts first, so we always say 'y'
|
# The idea in the rest is that bar sorts first, so we always say 'y'
|
||||||
|
@ -37,11 +37,12 @@ test_expect_success PERL 'reset -p' '
|
|||||||
rm .git/index &&
|
rm .git/index &&
|
||||||
git add a &&
|
git add a &&
|
||||||
echo y >yes &&
|
echo y >yes &&
|
||||||
git reset -p <yes &&
|
git reset -p <yes >output &&
|
||||||
|
|
||||||
>expect &&
|
>expect &&
|
||||||
git ls-files >actual &&
|
git ls-files >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual &&
|
||||||
|
test_i18ngrep "Unstage" output
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'reset --soft is a no-op' '
|
test_expect_success 'reset --soft is a no-op' '
|
||||||
|
Loading…
Reference in New Issue
Block a user