@@ -22,7 +22,7 @@ $::QUIET = 1;
22
22
my $git = can_run(' git' );
23
23
24
24
if ( defined $git ) {
25
- plan tests => 9 ;
25
+ plan tests => 11 ;
26
26
}
27
27
else {
28
28
plan skip_all => ' Can not find git command' ;
@@ -87,6 +87,53 @@ subtest 'clone into existing directory', sub {
87
87
git_repo_ok($clone_target_dir );
88
88
};
89
89
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
+
90
137
sub prepare_test_repo {
91
138
my $directory = shift ;
92
139
@@ -117,7 +164,40 @@ sub git_repo_ok {
117
164
}
118
165
119
166
sub init_test {
167
+ my %opts = @_ ;
168
+
120
169
my $clone_target_dir = tempdir( CLEANUP => 1 );
121
170
171
+ if ( $opts {clone } ) {
172
+ lives_ok {
173
+ checkout $test_repo_name ,
174
+ path => $clone_target_dir ,
175
+ }
176
+ ' cloning the repo' ;
177
+ }
178
+
122
179
return $clone_target_dir ;
123
180
}
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