Skip to content

Commit

Permalink
Add test for pulling new git commits
Browse files Browse the repository at this point in the history
  • Loading branch information
ferki committed Jan 21, 2025
1 parent cb77afa commit ceeae93
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion t/scm/git.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $::QUIET = 1;
my $git = can_run('git');

if ( defined $git ) {
plan tests => 9;
plan tests => 11;
}
else {
plan skip_all => 'Can not find git command';
Expand Down Expand Up @@ -87,6 +87,53 @@ subtest 'clone into existing directory', sub {
git_repo_ok($clone_target_dir);
};

subtest 'checkout new commits', sub {
plan tests => 4;

my $clone_target_dir = init_test( clone => TRUE );

my $test_commit_message = 'new_origin_commit';

i_run "git commit --allow-empty -m $test_commit_message",
cwd => $test_repo_dir,
env => $git_environment;

lives_ok { checkout $test_repo_name, path => $clone_target_dir }
'pulling new commit';

git_last_commit_message_ok( $clone_target_dir, $test_commit_message );

reset_test_repo();
};

subtest 'checkout new commits with rebase', sub {
plan tests => 4; ## no critic (ProhibitDuplicateLiteral)

my $clone_target_dir = init_test( clone => TRUE );

i_run 'git commit --allow-empty -m new_origin_commit',
cwd => $test_repo_dir,
env => $git_environment;

my $test_commit_message = 'new_local_commit';

i_run "git commit --allow-empty -m $test_commit_message",
cwd => $clone_target_dir,
env => $git_environment;

lives_ok {
checkout $test_repo_name,
path => $clone_target_dir,
rebase => TRUE,
env => $git_environment,
}
'pulling new commit with rebase';

git_last_commit_message_ok( $clone_target_dir, $test_commit_message );

reset_test_repo();
};

sub prepare_test_repo {
my $directory = shift;

Expand Down Expand Up @@ -117,7 +164,40 @@ sub git_repo_ok {
}

sub init_test {
my %opts = @_;

my $clone_target_dir = tempdir( CLEANUP => 1 );

if ( $opts{clone} ) {
lives_ok {
checkout $test_repo_name,
path => $clone_target_dir,
}
'cloning the repo';
}

return $clone_target_dir;
}

sub git_last_commit_message_ok {
my ( $directory, $expected_commit_message ) = @_;

my $last_commit_message = i_run 'git log --oneline -1 --format=%s',
cwd => $directory,
env => $git_environment;

is( $last_commit_message, $expected_commit_message,
'got correct last commit message' );

return;
}

sub reset_test_repo {
i_run 'git reset --hard HEAD~1',
cwd => $test_repo_dir,
env => $git_environment;

git_last_commit_message_ok( $test_repo_dir, 'commit' );

return;
}

0 comments on commit ceeae93

Please sign in to comment.