1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#!perl
use Test::More;
use Git::Raw;
use File::Slurp::Tiny qw(write_file);
use File::Spec::Functions qw(catfile rel2abs);
my $path = rel2abs(catfile('t', 'test_repo'));
my $repo = Git::Raw::Repository -> open($path);
my $initial_head = $repo -> head;
my $branch = $repo -> branch('cbranch', $initial_head -> target);
my $cherry_pick_branch = $repo -> branch('cherry_pick_branch', $initial_head -> target);
$repo -> checkout($repo -> head($branch), {
'checkout_strategy' => {
'safe' => 1
}
});
my $file1 = $repo -> workdir . 'cherry_file';
write_file($file1, 'this is cherry_file');
my $index = $repo -> index;
$index -> add('cherry_file');
$index -> write;
is_deeply $repo -> status({}) -> {'cherry_file'} -> {'flags'}, ['index_new'];
my $me = Git::Raw::Signature -> default($repo);
my $commit1 = $repo -> commit("commit1 on cbranch\n", $me, $me, [$branch -> target],
$index -> write_tree);
is $repo -> status({}) -> {'cherry_file'}, undef;
write_file($file1, "this is cherry_file\nwith some more modifications\nand some more");
$index -> add('cherry_file');
$index -> write;
is_deeply $repo -> status({}) -> {'cherry_file'} -> {'flags'}, ['index_modified'];
my $commit2 = $repo -> commit("commit2 on cbranch\n", $me, $me, [$commit1],
$index -> write_tree);
is $repo -> status({}) -> {'cherry_file'}, undef;
$repo -> checkout($repo -> head($cherry_pick_branch), {
'checkout_strategy' => {
'force' => 1
}
});
isnt -f $file1, 1;
is $repo -> status({}) -> {'cherry_file'}, undef;
$repo -> cherry_pick($commit1);
is_deeply $repo -> status({}) -> {'cherry_file'} -> {'flags'}, ['index_new'];
is $index -> has_conflicts, 0;
ok (!eval { $repo -> cherry_pick($commit2) });
my $c_commit1 = $repo -> commit("commit1 on cbranch\n", $me, $me, [$cherry_pick_branch -> target],
$index -> write_tree);
is $repo -> status({}) -> {'cherry_file'}, undef;
my $cherry_pick_conflict_branch = $repo -> branch('cherry_pick_conflict_branch', $c_commit1);
$repo -> cherry_pick($commit2);
is_deeply $repo -> status({}) -> {'cherry_file'} -> {'flags'}, ['index_modified'];
is $index -> has_conflicts, 0;
ok (!eval { $repo -> cherry_pick($commit2) });
my $c_commit2 = $repo -> commit("commit2 on cbranch\n", $me, $me, [$c_commit1],
$index -> write_tree);
is $branch -> target -> tree -> id, $cherry_pick_branch -> target -> tree -> id;
$repo -> cherry_pick($commit2);
is $index -> has_conflicts, 0;
is $repo -> state, "cherry_pick";
$repo -> state_cleanup;
is $repo -> state, "none";
my $head = $repo -> head($cherry_pick_conflict_branch);
$repo -> checkout($head -> target -> tree, {
'checkout_strategy' => {
'force' => 1
}
});
$index -> read(1);
is $repo -> status({}) -> {'cherry_file'}, undef;
write_file($file1, "this is cherry_file\nwith some conflict producing modifications");
$index -> add('cherry_file');
$index -> write;
my $conflict_commit1 = $repo -> commit("conflict commit on cbranch\n", $me, $me, [$cherry_pick_conflict_branch -> target],
$index -> write_tree);
ok (!eval { $repo -> cherry_pick($commit2, {}, {}, 9999) });
$repo -> cherry_pick($commit2, {}, {}, 0);
is $index -> has_conflicts, 1;
write_file($file1, "resolved!");
$index -> add('cherry_file');
is $index -> has_conflicts, 0;
my $conflict_commit2 = $repo -> commit("commit2 on cbranch\n", $me, $me, [$conflict_commit1],
$index -> write_tree);
is $index -> has_conflicts, 0;
is $repo -> status({}) -> {'cherry_file'}, undef;
isnt $branch -> target -> tree -> id, $cherry_pick_conflict_branch -> target -> tree -> id;
is $repo -> state, "cherry_pick";
$repo -> state_cleanup;
is $repo -> state, "none";
my $main = Git::Raw::Branch -> lookup($repo, 'main', 1);
$index -> read_tree($main -> target -> tree);
$index -> write;
$repo -> checkout($main -> target -> tree, {
'checkout_strategy' => {
'safe' => 1
}
});
$head = $repo -> head($main);
is $index -> has_conflicts, 0;
is $repo -> status({}) -> {'cherry_file'}, undef;
done_testing;
|