summaryrefslogtreecommitdiff
path: root/git-add--interactive.perl
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2013-10-25 02:52:30 -0400
committerJunio C Hamano <gitster@pobox.com>2013-10-25 14:54:17 -0700
commit954312a3ff76652a954b730ae69a031f98293a99 (patch)
tree188a014d9f51b994950797e73d46450adf886de0 /git-add--interactive.perl
parent3d092bfc6f2d9a998967979f926c661e9762601c (diff)
downloadgit-954312a3ff76652a954b730ae69a031f98293a99.tar.gz
add-interactive: handle unborn branch in patch mode
The list_modified function already knows how to handle an unborn branch by diffing against the empty tree. However, the diff we perform to get the actual hunks does not. Let's use the same logic for both diffs. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-add--interactive.perl')
-rwxr-xr-xgit-add--interactive.perl22
1 files changed, 13 insertions, 9 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 51563840f4..24bb1ab992 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -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 = ();