Skip to content

Commit 43a0592

Browse files
committed
add -p: mark split hunks as undecided
When a hunk is split each of the new hunks inherits whether it is selected or not from the original hunk. This means that if a selected hunk is split all of the new hunks are selected and the user is not asked whether or not they want to select the new hunks. This is unfortunate as the user is presumably splitting the original hunk because they only want to select some sub-set of it. Fix this by marking all the new hunks as "undecided" so that we prompt the user to decide whether to select them or not. Signed-off-by: Phillip Wood <[email protected]>
1 parent 0394451 commit 43a0592

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

add-patch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ static int split_hunk(struct add_p_state *s, struct file_diff *file_diff,
953953
* sizeof(*hunk));
954954
hunk = file_diff->hunk + hunk_index;
955955
hunk->splittable_into = 1;
956+
hunk->use = UNDECIDED_HUNK;
956957
memset(hunk + 1, 0, (splittable_into - 1) * sizeof(*hunk));
957958

958959
header = &hunk->header;
@@ -1054,7 +1055,7 @@ static int split_hunk(struct add_p_state *s, struct file_diff *file_diff,
10541055

10551056
hunk++;
10561057
hunk->splittable_into = 1;
1057-
hunk->use = hunk[-1].use;
1058+
hunk->use = UNDECIDED_HUNK;
10581059
header = &hunk->header;
10591060

10601061
header->old_count = header->new_count = context_line_count;

t/t3701-add-interactive.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,4 +1230,14 @@ test_expect_success 'hunk splitting works with diff.suppressBlankEmpty' '
12301230
test_cmp expect actual
12311231
'
12321232

1233+
test_expect_success 'splitting previous hunk marks split hunks as undecided' '
1234+
test_write_lines a " " b c d e f g h i j k >file &&
1235+
git add file &&
1236+
test_write_lines x " " b y d e f g h i j x >file &&
1237+
test_write_lines n K s n y q | git add -p file &&
1238+
git cat-file blob :file >actual &&
1239+
test_write_lines a " " b y d e f g h i j k >expect &&
1240+
test_cmp expect actual
1241+
'
1242+
12331243
test_done

0 commit comments

Comments
 (0)