Skip to content

Commit 954312a

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d092bf commit 954312a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

git-add--interactive.perl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,17 @@ sub get_empty_tree {
263263
return '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
264264
}
265265

266+
sub get_diff_reference {
267+
my $ref = shift;
268+
if (defined $ref and $ref ne 'HEAD') {
269+
return $ref;
270+
} elsif (is_initial_commit()) {
271+
return get_empty_tree();
272+
} else {
273+
return 'HEAD';
274+
}
275+
}
276+
266277
# Returns list of hashes, contents of each of which are:
267278
# VALUE: pathname
268279
# BINARY: is a binary path
@@ -286,14 +297,7 @@ sub list_modified {
286297
return if (!@tracked);
287298
}
288299

289-
my $reference;
290-
if (defined $patch_mode_revision and $patch_mode_revision ne 'HEAD') {
291-
$reference = $patch_mode_revision;
292-
} elsif (is_initial_commit()) {
293-
$reference = get_empty_tree();
294-
} else {
295-
$reference = 'HEAD';
296-
}
300+
my $reference = get_diff_reference($patch_mode_revision);
297301
for (run_cmd_pipe(qw(git diff-index --cached
298302
--numstat --summary), $reference,
299303
'--', @tracked)) {
@@ -737,7 +741,7 @@ sub parse_diff {
737741
splice @diff_cmd, 1, 0, "--diff-algorithm=${diff_algorithm}";
738742
}
739743
if (defined $patch_mode_revision) {
740-
push @diff_cmd, $patch_mode_revision;
744+
push @diff_cmd, get_diff_reference($patch_mode_revision);
741745
}
742746
my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path);
743747
my @colored = ();

0 commit comments

Comments
 (0)