Skip to content

Commit ceeae93

Browse files
committed
Add test for pulling new git commits
1 parent cb77afa commit ceeae93

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

t/scm/git.t

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $::QUIET = 1;
2222
my $git = can_run('git');
2323

2424
if ( defined $git ) {
25-
plan tests => 9;
25+
plan tests => 11;
2626
}
2727
else {
2828
plan skip_all => 'Can not find git command';
@@ -87,6 +87,53 @@ subtest 'clone into existing directory', sub {
8787
git_repo_ok($clone_target_dir);
8888
};
8989

90+
subtest 'checkout new commits', sub {
91+
plan tests => 4;
92+
93+
my $clone_target_dir = init_test( clone => TRUE );
94+
95+
my $test_commit_message = 'new_origin_commit';
96+
97+
i_run "git commit --allow-empty -m $test_commit_message",
98+
cwd => $test_repo_dir,
99+
env => $git_environment;
100+
101+
lives_ok { checkout $test_repo_name, path => $clone_target_dir }
102+
'pulling new commit';
103+
104+
git_last_commit_message_ok( $clone_target_dir, $test_commit_message );
105+
106+
reset_test_repo();
107+
};
108+
109+
subtest 'checkout new commits with rebase', sub {
110+
plan tests => 4; ## no critic (ProhibitDuplicateLiteral)
111+
112+
my $clone_target_dir = init_test( clone => TRUE );
113+
114+
i_run 'git commit --allow-empty -m new_origin_commit',
115+
cwd => $test_repo_dir,
116+
env => $git_environment;
117+
118+
my $test_commit_message = 'new_local_commit';
119+
120+
i_run "git commit --allow-empty -m $test_commit_message",
121+
cwd => $clone_target_dir,
122+
env => $git_environment;
123+
124+
lives_ok {
125+
checkout $test_repo_name,
126+
path => $clone_target_dir,
127+
rebase => TRUE,
128+
env => $git_environment,
129+
}
130+
'pulling new commit with rebase';
131+
132+
git_last_commit_message_ok( $clone_target_dir, $test_commit_message );
133+
134+
reset_test_repo();
135+
};
136+
90137
sub prepare_test_repo {
91138
my $directory = shift;
92139

@@ -117,7 +164,40 @@ sub git_repo_ok {
117164
}
118165

119166
sub init_test {
167+
my %opts = @_;
168+
120169
my $clone_target_dir = tempdir( CLEANUP => 1 );
121170

171+
if ( $opts{clone} ) {
172+
lives_ok {
173+
checkout $test_repo_name,
174+
path => $clone_target_dir,
175+
}
176+
'cloning the repo';
177+
}
178+
122179
return $clone_target_dir;
123180
}
181+
182+
sub git_last_commit_message_ok {
183+
my ( $directory, $expected_commit_message ) = @_;
184+
185+
my $last_commit_message = i_run 'git log --oneline -1 --format=%s',
186+
cwd => $directory,
187+
env => $git_environment;
188+
189+
is( $last_commit_message, $expected_commit_message,
190+
'got correct last commit message' );
191+
192+
return;
193+
}
194+
195+
sub reset_test_repo {
196+
i_run 'git reset --hard HEAD~1',
197+
cwd => $test_repo_dir,
198+
env => $git_environment;
199+
200+
git_last_commit_message_ok( $test_repo_dir, 'commit' );
201+
202+
return;
203+
}

0 commit comments

Comments
 (0)