Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Revision history for Rex
[API CHANGES]

[BUG FIXES]
- Fix git rebase tests on old git versions

[DOCUMENTATION]

Expand Down
72 changes: 50 additions & 22 deletions t/scm/git.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use English qw(-no_match_vars);
use File::Spec;
use File::Temp qw(tempdir);
use Rex::Commands;
use Rex::Commands::File;
use Rex::Commands::Run;
use Rex::Commands::SCM;
use Rex::Helper::Run;
Expand Down Expand Up @@ -46,8 +47,11 @@ ok( $git_version, qq(Git version returned as '$git_version') );
my $test_repo_dir = tempdir( CLEANUP => 1 );
ok( -d $test_repo_dir, "$test_repo_dir is the test repo directory now" );

my $test_repo_name = 'test_repo';
my $test_branch_name = 'test_branch';
my $test_repo_name = 'test_repo';
my $test_initial_commit_message = 'initial_commit';

my $test_branch_name = 'test_branch';
my $test_branch_commit_message = 'origin_branch_commit';

prepare_test_repo($test_repo_dir);
git_repo_ok($test_repo_dir);
Expand Down Expand Up @@ -92,9 +96,7 @@ subtest 'checkout new commits', sub {

my $test_commit_message = 'new_origin_commit';

i_run "git commit --allow-empty -m $test_commit_message",
cwd => $test_repo_dir,
env => $git_environment;
create_commit( directory => $test_repo_dir, message => $test_commit_message );

lives_ok {
checkout $test_repo_name,
Expand All @@ -112,15 +114,17 @@ subtest 'checkout new commits with rebase', sub {

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;
create_commit(
directory => $test_repo_dir,
message => 'new_oriting_commit_rebase'
);

my $test_commit_message = 'new_local_commit';

i_run "git commit --allow-empty -m $test_commit_message",
cwd => $clone_target_dir,
env => $git_environment;
create_commit(
directory => $clone_target_dir,
message => $test_commit_message
);

lives_ok {
checkout $test_repo_name,
Expand Down Expand Up @@ -179,7 +183,7 @@ subtest 'checkout new commits from a branch', sub {
'pulling new commit from branch';

git_branch_ok( $clone_target_dir, $test_branch_name );
git_last_commit_message_ok( $clone_target_dir, 'origin_branch_commit' );
git_last_commit_message_ok( $clone_target_dir, $test_branch_commit_message );
};

subtest 'checkout new commits from a branch with rebase', sub {
Expand All @@ -189,9 +193,10 @@ subtest 'checkout new commits from a branch with rebase', sub {

my $test_commit_message = 'local_branch_commit';

i_run "git commit --allow-empty -m $test_commit_message",
cwd => $clone_target_dir,
env => $git_environment;
create_commit(
directory => $clone_target_dir,
message => $test_commit_message
);

git_last_commit_message_ok( $clone_target_dir, $test_commit_message );

Expand Down Expand Up @@ -220,17 +225,19 @@ sub prepare_test_repo {

$default_branch =~ s{refs/heads/}{}msx;

i_run 'git commit --allow-empty -m commit',
cwd => $directory,
env => $git_environment;
create_commit(
directory => $directory,
message => $test_initial_commit_message
);

i_run "git checkout -b $test_branch_name",
cwd => $directory,
env => $git_environment;

i_run 'git commit --allow-empty -m origin_branch_commit',
cwd => $directory,
env => $git_environment;
create_commit(
directory => $directory,
message => $test_branch_commit_message
);

i_run "git checkout $default_branch",
cwd => $directory,
Expand Down Expand Up @@ -306,7 +313,7 @@ sub reset_test_repo {
cwd => $test_repo_dir,
env => $git_environment;

git_last_commit_message_ok( $test_repo_dir, 'commit' );
git_last_commit_message_ok( $test_repo_dir, $test_initial_commit_message );

return;
}
Expand All @@ -322,3 +329,24 @@ sub git_branch_ok {

return;
}

sub create_commit {
my %opts = @_;

my $directory = $opts{directory};
my $message = my $filename = $opts{message};

my $path = File::Spec->join( $directory, $filename );

file $path;

i_run "git add $filename",
cwd => $directory,
env => $git_environment;

i_run "git commit -m $message",
cwd => $directory,
env => $git_environment;

return;
}
Loading