Skip to content

Commit

Permalink
Merge branch 'jk/reset-p-current-head-fix'
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
Junio C Hamano committed Nov 1, 2013
2 parents 60e779a + b3e9ce1 commit 1feb458
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion builtin/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions git-add--interactive.perl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand Down Expand Up @@ -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 = ();
Expand Down
10 changes: 6 additions & 4 deletions t/t7105-reset-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions t/t7106-reset-unborn-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' '
Expand Down

0 comments on commit 1feb458

Please sign in to comment.