def test_scm_git_clone_commit(gitrepo, tmpdir): """Verify we can clone using a specific commit""" local_dir = os.path.join(str(tmpdir), 'local') commit = check_output('git -C {} log --oneline --all | grep AA-03'.format(gitrepo), shell=True).split()[0] main(args=['clone', 'file://' + gitrepo, local_dir, '--commit', commit]) actual_commit = check_output('git -C {} rev-parse HEAD'.format(local_dir)) assert actual_commit.startswith(commit)
def test_scm_git_clone_branch(gitrepo, tmpdir): """Verify we can clone using a specific branch""" local_dir = os.path.join(str(tmpdir), 'local') branch_tip_commit = check_output('git -C {} show-ref mergeable'.format(gitrepo)).split()[0] main(args=['clone', 'file://' + gitrepo, local_dir, '--branch', 'mergeable']) actual_commit = check_output('git -C {} rev-parse HEAD'.format(local_dir)) assert branch_tip_commit == actual_commit
def test_scm_axops_codecommit(axops, tmpdir, aws_credentials): """Verify we can clone from a code commit repository""" if not aws_credentials: pytest.skip("AWS credentials must be supplied from command line or env variables") local_dir = os.path.join(str(tmpdir), 'local') repo_url = 'https://git-codecommit.us-east-1.amazonaws.com/v1/repos/goexample' main(args=['clone', repo_url, local_dir])
def test_scm_git_merge_with_author(gitrepo, tmpdir): """Verify e-mail address is tested as a valid e-mail""" local_dir = os.path.join(str(tmpdir), 'local') mickeymouse = 'Mickey Mouse <*****@*****.**>' main(args=['clone', 'file://' + gitrepo, local_dir, '--branch', 'master', '--merge', 'mergeable', '--author', mickeymouse]) gitlog = check_output('git -C {} log -1'.format(local_dir)) assert mickeymouse in gitlog
def test_scm_git_clone_remote_head(gitrepo, tmpdir): """Verify git clone will checkout remote head when commit/branch is omitted""" local_dir = os.path.join(str(tmpdir), 'local') main(args=['clone', 'file://' + gitrepo, local_dir]) head_commit = check_output('git -C {} rev-parse HEAD'.format(gitrepo)) actual_commit = check_output('git -C {} rev-parse HEAD'.format(local_dir)) assert head_commit == actual_commit
def test_scm_git_merge_ff_branch(gitrepo, tmpdir): """Verify when we merge+push a fast-forwardable branch, we still use a merge commit""" local_dir = os.path.join(str(tmpdir), 'local') before = check_output('git -C {} log --oneline --graph --all --decorate'.format(gitrepo)) num_commits_before = before.count('*') main(args=['clone', 'file://' + gitrepo, local_dir, '--branch', 'master', '--merge', 'ff-mergeable', '--push']) after = check_output('git -C {} log --oneline --graph --all --decorate'.format(gitrepo)) num_commits_after = after.count('*') assert num_commits_after == num_commits_before + 1, "Unexpected number of commits"
def test_scm_git_merge_branch_same_branch(gitrepo, tmpdir): """Verify merge request from the current branch to the current branch is a no-op""" local_dir = os.path.join(str(tmpdir), 'local') before = check_output('git -C {} log --oneline --graph --all --decorate'.format(gitrepo)) num_commits_before = before.count('*') main(args=['clone', 'file://' + gitrepo, local_dir, '--branch', 'mergeable', '--merge', 'mergeable']) after = check_output('git -C {} log --oneline --graph --all --decorate'.format(local_dir)) num_commits_after = after.count('*') assert num_commits_after == num_commits_before, "Unexpected number of commits"
def test_scm_git_merge_existing_commit_same_branch(gitrepo, tmpdir): """Verify merge request for a commit that is already in current branch is a no-op""" local_dir = os.path.join(str(tmpdir), 'local') before = check_output('git -C {} log --oneline --graph --all --decorate'.format(gitrepo)) num_commits_before = before.count('*') commit = check_output('git -C {} log --oneline --all | grep AA-02'.format(gitrepo), shell=True).split()[0] main(args=['clone', 'file://' + gitrepo, local_dir, '--branch', 'master', '--merge', commit]) after = check_output('git -C {} log --oneline --graph --all --decorate'.format(local_dir)) num_commits_after = after.count('*') assert num_commits_after == num_commits_before, "Unexpected number of commits"
def test_scm_git_merge_behind_into_ahead(gitrepo, tmpdir): """Verify a merge from a branch which is behind, into a branch which ahead is a no-op""" local_dir = os.path.join(str(tmpdir), 'local') before = check_output('git -C {} log --oneline --graph --all --decorate'.format(gitrepo)) num_commits_before = before.count('*') main(args=['clone', 'file://' + gitrepo, local_dir, '--branch', 'ff-mergeable', '--merge', 'master']) expected = check_output('git -C {} log --oneline --graph --all --decorate'.format(gitrepo)) num_commits_before = before.count('*') after = check_output('git -C {} log --oneline --graph --all --decorate'.format(local_dir)) num_commits_after = after.count('*') assert num_commits_after == num_commits_before, "Unexpected number of commits"
def test_scm_git_push(gitrepo, tmpdir, branches): """Verify we can push changes from a local repo""" before = check_output('git -C {} log --oneline --graph --all --decorate'.format(gitrepo)) num_commits_before = before.count('*') local_dir = os.path.join(str(tmpdir), 'local') main(args=['clone', 'file://' + gitrepo, local_dir, '--branch', branches[0], '--merge', branches[1]]) assert "Your branch is ahead" in check_output('git -C {} status'.format(local_dir)) main(args=['push', local_dir]) assert "Your branch is up-to-date" in check_output('git -C {} status'.format(local_dir)) after = check_output('git -C {} log --oneline --graph --all --decorate'.format(gitrepo)) num_commits_after = after.count('*') assert num_commits_after == num_commits_before + 1, "Unexpected number of commits"
def test_scm_git_merge_conflicts(gitrepo, tmpdir, branches): """Verify merge with conflicts raises exception (private->master and vice versa)""" local_dir = os.path.join(str(tmpdir), 'local') with pytest.raises(SystemExit): main(args=['clone', 'file://' + gitrepo, local_dir, '--branch', branches[0], '--merge', branches[1]])
def test_scm_git_merge_no_conflicts(gitrepo, tmpdir, branches): """Verify we are able to perform a merge with no conflicts (master->private and vice versa)""" local_dir = os.path.join(str(tmpdir), 'local') main(args=['clone', 'file://' + gitrepo, local_dir, '--branch', branches[0], '--merge', branches[1]]) for f in ['file01', 'file02', 'file03', 'file04', 'file05', 'file06']: assert os.path.exists(os.path.join(local_dir, f))
def test_scm_axops_generic_git_passwordless(axops, tmpdir): """Verify we can clone from a generic git server""" local_dir = os.path.join(str(tmpdir), 'local') repo_url = 'https://github.com/demo/goexample.git' main(args=['clone', repo_url, local_dir])
#!/usr/bin/env python3 from ax.util.az_patch import az_patch az_patch() from ax.devops.scm.cli import main if __name__ == '__main__': main()
def test_scm_axops_github(axops, tmpdir): """Verify we can clone from a github account""" local_dir = os.path.join(str(tmpdir), 'local') repo_url = 'https://github.com/demo/ansible-example.git' main(args=['clone', repo_url, local_dir])
def test_scm_git_merge_invalid_author(gitrepo, tmpdir): """Verify e-mail address is tested as a valid e-mail""" local_dir = os.path.join(str(tmpdir), 'local') with pytest.raises(SystemExit): main(args=['clone', 'file://' + gitrepo, local_dir, '--branch', 'master', '--merge', 'mergeable', '--author', 'invalid'])
def test_scm_axops_generic_git(axops, tmpdir): """Verify we can clone from a generic git server""" local_dir = os.path.join(str(tmpdir), 'local') repo_url = 'https://bitbucket.org/atlassian_tutorial/helloworld.git' main(args=['clone', repo_url, local_dir])