Skip to content

Commit 3b9532d

Browse files
phillipwoodgitster
authored andcommitted
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. If a selected hunk is split all of the new hunks are marked as "selected" and the user is only prompted with the first of the split hunks. The user is not asked whether or not they wish to select the rest of the new hunks. This means that if they wish to deselect any of the new hunks apart from the first one they have to navigate back to the hunk they want to deselect before they can deselect it. This is unfortunate as the user is presumably splitting the original hunk because they only want to select some sub-set of it. Instead mark all the new hunks as "undecided" so that the user is prompted whether they wish to select each one in turn. In the case where the user only wants to change the selection of the first of the split hunks they will now have to do more work re-selecting the remaining split hunks. However, changing the selection of any of the other newly created hunks is now much simpler as the user no-longer has to navigate back to them in order to change their selected state. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 92c87bd commit 3b9532d

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
@@ -956,6 +956,7 @@ static int split_hunk(struct add_p_state *s, struct file_diff *file_diff,
956956
* sizeof(*hunk));
957957
hunk = file_diff->hunk + hunk_index;
958958
hunk->splittable_into = 1;
959+
hunk->use = UNDECIDED_HUNK;
959960
memset(hunk + 1, 0, (splittable_into - 1) * sizeof(*hunk));
960961

961962
header = &hunk->header;
@@ -1057,7 +1058,7 @@ static int split_hunk(struct add_p_state *s, struct file_diff *file_diff,
10571058

10581059
hunk++;
10591060
hunk->splittable_into = 1;
1060-
hunk->use = hunk[-1].use;
1061+
hunk->use = UNDECIDED_HUNK;
10611062
header = &hunk->header;
10621063

10631064
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
@@ -1301,4 +1301,14 @@ do
13011301
'
13021302
done
13031303

1304+
test_expect_success 'splitting previous hunk marks split hunks as undecided' '
1305+
test_write_lines a " " b c d e f g h i j k >file &&
1306+
git add file &&
1307+
test_write_lines x " " b y d e f g h i j x >file &&
1308+
test_write_lines n K s n y q | git add -p file &&
1309+
git cat-file blob :file >actual &&
1310+
test_write_lines a " " b y d e f g h i j k >expect &&
1311+
test_cmp expect actual
1312+
'
1313+
13041314
test_done

0 commit comments

Comments
 (0)