Merge branch 'jk/add-p-skip-conflicts' into maint
"git add -p" is not designed to deal with unmerged paths but did not exclude them and tried to apply funny patches only to fail. By Jeff King * jk/add-p-skip-conflicts: add--interactive: ignore unmerged entries in patch mode
This commit is contained in:
commit
4579a0547c
@ -268,6 +268,7 @@ sub get_empty_tree {
|
|||||||
# FILE: is file different from index?
|
# FILE: is file different from index?
|
||||||
# INDEX_ADDDEL: is it add/delete between HEAD and index?
|
# INDEX_ADDDEL: is it add/delete between HEAD and index?
|
||||||
# FILE_ADDDEL: is it add/delete between index and file?
|
# FILE_ADDDEL: is it add/delete between index and file?
|
||||||
|
# UNMERGED: is the path unmerged
|
||||||
|
|
||||||
sub list_modified {
|
sub list_modified {
|
||||||
my ($only) = @_;
|
my ($only) = @_;
|
||||||
@ -318,16 +319,10 @@ sub list_modified {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (run_cmd_pipe(qw(git diff-files --numstat --summary --), @tracked)) {
|
for (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @tracked)) {
|
||||||
if (($add, $del, $file) =
|
if (($add, $del, $file) =
|
||||||
/^([-\d]+) ([-\d]+) (.*)/) {
|
/^([-\d]+) ([-\d]+) (.*)/) {
|
||||||
$file = unquote_path($file);
|
$file = unquote_path($file);
|
||||||
if (!exists $data{$file}) {
|
|
||||||
$data{$file} = +{
|
|
||||||
INDEX => 'unchanged',
|
|
||||||
BINARY => 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
my ($change, $bin);
|
my ($change, $bin);
|
||||||
if ($add eq '-' && $del eq '-') {
|
if ($add eq '-' && $del eq '-') {
|
||||||
$change = 'binary';
|
$change = 'binary';
|
||||||
@ -346,6 +341,18 @@ sub list_modified {
|
|||||||
$file = unquote_path($file);
|
$file = unquote_path($file);
|
||||||
$data{$file}{FILE_ADDDEL} = $adddel;
|
$data{$file}{FILE_ADDDEL} = $adddel;
|
||||||
}
|
}
|
||||||
|
elsif (/^:[0-7]+ [0-7]+ [0-9a-f]+ [0-9a-f]+ (.) (.*)$/) {
|
||||||
|
$file = unquote_path($2);
|
||||||
|
if (!exists $data{$file}) {
|
||||||
|
$data{$file} = +{
|
||||||
|
INDEX => 'unchanged',
|
||||||
|
BINARY => 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if ($1 eq 'U') {
|
||||||
|
$data{$file}{UNMERGED} = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (sort keys %data) {
|
for (sort keys %data) {
|
||||||
@ -1190,6 +1197,10 @@ sub apply_patch_for_checkout_commit {
|
|||||||
|
|
||||||
sub patch_update_cmd {
|
sub patch_update_cmd {
|
||||||
my @all_mods = list_modified($patch_mode_flavour{FILTER});
|
my @all_mods = list_modified($patch_mode_flavour{FILTER});
|
||||||
|
error_msg "ignoring unmerged: $_->{VALUE}\n"
|
||||||
|
for grep { $_->{UNMERGED} } @all_mods;
|
||||||
|
@all_mods = grep { !$_->{UNMERGED} } @all_mods;
|
||||||
|
|
||||||
my @mods = grep { !($_->{BINARY}) } @all_mods;
|
my @mods = grep { !($_->{BINARY}) } @all_mods;
|
||||||
my @them;
|
my @them;
|
||||||
|
|
||||||
|
@ -330,4 +330,30 @@ test_expect_success PERL 'split hunk "add -p (edit)"' '
|
|||||||
! grep "^+15" actual
|
! grep "^+15" actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'patch mode ignores unmerged entries' '
|
||||||
|
git reset --hard &&
|
||||||
|
test_commit conflict &&
|
||||||
|
test_commit non-conflict &&
|
||||||
|
git checkout -b side &&
|
||||||
|
test_commit side conflict.t &&
|
||||||
|
git checkout master &&
|
||||||
|
test_commit master conflict.t &&
|
||||||
|
test_must_fail git merge side &&
|
||||||
|
echo changed >non-conflict.t &&
|
||||||
|
echo y | git add -p >output &&
|
||||||
|
! grep a/conflict.t output &&
|
||||||
|
cat >expected <<-\EOF &&
|
||||||
|
* Unmerged path conflict.t
|
||||||
|
diff --git a/non-conflict.t b/non-conflict.t
|
||||||
|
index f766221..5ea2ed4 100644
|
||||||
|
--- a/non-conflict.t
|
||||||
|
+++ b/non-conflict.t
|
||||||
|
@@ -1 +1 @@
|
||||||
|
-non-conflict
|
||||||
|
+changed
|
||||||
|
EOF
|
||||||
|
git diff --cached >diff &&
|
||||||
|
test_cmp expected diff
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user