File: 22-revert.t

package info (click to toggle)
libgit-raw-perl 0.90%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,456 kB
  • sloc: perl: 5,426; ansic: 182; makefile: 6
file content (84 lines) | stat: -rw-r--r-- 2,221 bytes parent folder | download | duplicates (2)
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
#!perl

use Test::More;

use Git::Raw;
use File::Slurp::Tiny qw(write_file read_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('rbranch', $initial_head -> target);

$repo -> checkout($repo -> head($branch), {
	'checkout_strategy' => {
		'force' => 1
	}
});

my $file1 = $repo -> workdir . 'revert_file';
write_file($file1, 'this is revert_file');

my $index = $repo -> index;
is $index -> has_conflicts, 0;
$index -> add('revert_file');
$index -> write;

is_deeply $repo -> status({}) -> {'revert_file'} -> {'flags'}, ['index_new'];

my $me = Git::Raw::Signature -> default($repo);
my $commit1 = $repo -> commit("commit1 on rbranch\n", $me, $me, [$branch -> target],
	$index -> write_tree);

is $repo -> status({}) -> {'revert_file'}, undef;

write_file($file1, "this is revert_file\nwith some more modifications\nand some more");
$index -> add('revert_file');
$index -> write;

is_deeply $repo -> status({}) -> {'revert_file'} -> {'flags'}, ['index_modified'];

my $commit2 = $repo -> commit("commit2 on rbranch\n", $me, $me, [$commit1],
	$index -> write_tree);

is $repo -> status({}) -> {'revert_file'}, undef;

my $revert_branch = $repo -> branch('revert_branch', $commit2);
$repo -> checkout($repo -> head($revert_branch), {
	'checkout_strategy' => {
		'force' => 1
	}
});

ok (!eval { $repo -> revert($commit2, {}, {}, 9999) });
$repo -> revert($commit2, {}, {}, 0);

is_deeply $repo -> status({}) -> {'revert_file'} -> {'flags'}, ['index_modified'];

is read_file($file1), 'this is revert_file';

my $revert_commit = $repo -> commit("revert commit1\n", $me, $me, [$commit2],
	$index -> write_tree);

is_deeply $repo -> status({}) -> {'revert_file'}, undef;
is $revert_commit -> tree -> id, $commit1 -> tree -> id;

is $repo -> state, "revert";
$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
	}
});

$repo -> head($main);

done_testing;