def can_use_cache_when_cloning_git_repository(): with temporary_empty_dir() as target: with temporary_git_repo() as git_repo: original_uri = "git+file://" + git_repo.working_directory add_commit_to_repo(git_repo) fetch(original_uri + "#master^", target, use_cache=True) assert_equal("Run it.", read_file(os.path.join(target, "README")))
def can_clone_repository_to_specific_commit_using_hash_before_commit_name( vcs, target, commit): with vcs.temporary_repo() as repo: original_uri = "{0}+file://{1}".format(vcs.name, repo.working_directory) add_commit_to_repo(repo) fetch("{0}#{1}".format(original_uri, commit), target) assert_equal("Run it.", read_file(os.path.join(target, "README")))
def can_update_repository_to_latest_version(vcs, target): with vcs.temporary_repo() as repo: original_uri = "{0}+file://{1}".format(vcs.name, repo.working_directory) fetch(original_uri, target) assert_equal("Run it.", read_file(os.path.join(target, "README"))) add_commit_to_repo(repo) fetch(original_uri, target) assert_equal("Run away!", read_file(os.path.join(target, "README")))
def can_update_repository_to_specific_commit_using_hash_before_commit_name(vcs, target, commit): with vcs.temporary_repo() as repo: original_uri = "{0}+file://{1}".format(vcs.name, repo.working_directory) add_commit_to_repo(repo) fetch(original_uri, target) assert_equal("Run away!", read_file(os.path.join(target, "README"))) fetch("{0}#{1}".format(original_uri, commit), target) assert_equal("Run it.", read_file(os.path.join(target, "README")))
def hg_fetch_raises_error_if_target_is_checkout_of_different_repository(): with temporary_empty_dir() as target: with temporary_hg_repo() as first_repo: with temporary_hg_repo() as second_repo: fetch("hg+file://" + first_repo.working_directory, target) assert_raises_message( MayoUserError, "{0} is existing checkout of different repository: file://{1}" .format(target, first_repo.working_directory), lambda: fetch("hg+file://" + second_repo.working_directory, target) )
def hg_fetch_raises_error_if_target_is_checkout_of_different_repository(): with temporary_empty_dir() as target: with temporary_hg_repo() as first_repo: with temporary_hg_repo() as second_repo: fetch("hg+file://" + first_repo.working_directory, target) assert_raises_message( MayoUserError, "{0} is existing checkout of different repository: file://{1}" .format(target, first_repo.working_directory), lambda: fetch("hg+file://" + second_repo.working_directory, target))
def repository_is_used_if_uri_has_prefix(): git = mock_vcs("git") hg = mock_vcs("hg") git_uri = "http://www.example.com/project.git" fetch("git+" + git_uri, "/tmp/project", systems=[hg, git]) git.fetch.assert_called_once_with(mock.ANY, "/tmp/project") uri_arg = git.fetch.call_args[0][0] assert_equal("git", uri_arg.vcs) assert_equal(git_uri, uri_arg.repo_uri) assert_equal(None, uri_arg.revision)
def origin_is_prefixed_to_git_commit_if_necessary(): with temporary_empty_dir() as target: with temporary_git_repo() as git_repo: original_uri = "git+file://" + git_repo.working_directory # master == origin/master fetch(original_uri, target) assert_equal("Run it.", read_file(os.path.join(target, "README"))) add_commit_to_repo(git_repo) # If we checkout master rather than origin/master, we don't change revision fetch(original_uri + "#master", target) assert_equal("Run away!", read_file(os.path.join(target, "README")))
def git_fetch_raises_error_if_target_is_not_git_repository(): with temporary_directory() as target: with temporary_git_repo() as git_repo: original_uri = "git+file://" + git_repo.working_directory assert_raises_message( MayoUserError, "{0} already exists and is not a git repository".format( target), lambda: fetch(original_uri, target))
def error_is_raised_if_repository_uri_is_not_recognised(): with temporary_empty_dir() as target: original_uri = "asf+file:///tmp" assert_raises_message( UnrecognisedSourceControlSystem, "Source control system not recognised: asf", lambda: fetch(original_uri, target) )
def error_is_raised_if_target_is_file(): with temporary_empty_dir() as target: write_file(target, "Nope") with temporary_git_repo() as git_repo: original_uri = "git+file://" + git_repo.working_directory assert_raises_message( MayoUserError, "Checkout path already exists, and is not directory: {0}". format(target), lambda: fetch(original_uri, target))
def git_fetch_raises_error_if_target_is_not_git_repository(): with temporary_directory() as target: with temporary_git_repo() as git_repo: original_uri = "git+file://" + git_repo.working_directory assert_raises_message( MayoUserError, "{0} already exists and is not a git repository".format(target), lambda: fetch(original_uri, target) )
def error_is_raised_if_target_is_file(): with temporary_empty_dir() as target: write_file(target, "Nope") with temporary_git_repo() as git_repo: original_uri = "git+file://" + git_repo.working_directory assert_raises_message( MayoUserError, "Checkout path already exists, and is not directory: {0}".format(target), lambda: fetch(original_uri, target) )
def can_fetch_repository_into_new_directory(vcs, target): with vcs.temporary_repo() as repo: original_uri = "{0}+file://{1}".format(vcs.name, repo.working_directory) fetch(original_uri, target) assert_equal("Run it.", read_file(os.path.join(target, "README")))
def error_is_raised_if_repository_uri_is_not_recognised(): with temporary_empty_dir() as target: original_uri = "asf+file:///tmp" assert_raises_message(UnrecognisedSourceControlSystem, "Source control system not recognised: asf", lambda: fetch(original_uri, target))