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:
Junio C Hamano 2013-11-01 07:38:49 -07:00
Родитель 60e779adaa b3e9ce1332
Коммит 1feb458fb9
4 изменённых файлов: 23 добавлений и 16 удалений

Просмотреть файл

@ -304,7 +304,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
if (patch_mode) {
if (reset_type != NONE)
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

Просмотреть файл

@ -263,6 +263,17 @@ sub get_empty_tree {
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:
# VALUE: pathname
# BINARY: is a binary path
@ -286,14 +297,7 @@ sub list_modified {
return if (!@tracked);
}
my $reference;
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';
}
my $reference = get_diff_reference($patch_mode_revision);
for (run_cmd_pipe(qw(git diff-index --cached
--numstat --summary), $reference,
'--', @tracked)) {
@ -737,7 +741,7 @@ sub parse_diff {
splice @diff_cmd, 1, 0, "--diff-algorithm=${diff_algorithm}";
}
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 @colored = ();

Просмотреть файл

@ -25,15 +25,17 @@ test_expect_success PERL 'saying "n" does nothing' '
'
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_saved_state bar
verify_saved_state bar &&
test_i18ngrep "Unstage" output
'
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_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'

Просмотреть файл

@ -37,11 +37,12 @@ test_expect_success PERL 'reset -p' '
rm .git/index &&
git add a &&
echo y >yes &&
git reset -p <yes &&
git reset -p <yes >output &&
>expect &&
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' '