def test_switching_to_new_fixed_ref_local_changes(qisrc_action, git_server, record_messages): """ Test Switching To New Fixed Ref Local Changes """ git_server.create_repo("foo.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") git_server.push_tag("foo.git", "v0.2") git_server.push_file("foo.git", "c.txt", "c") git_server.set_fixed_ref("foo.git", "v0.1") qisrc_action("init", git_server.manifest_url) git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = TestGit(foo_proj.path) git.write_file("a.txt", "unstaged changes") git_server.set_fixed_ref("foo.git", "v0.2") record_messages.reset() rc = qisrc_action("sync", retcode=True) # ERROR message must be displayed to warn user assert rc != 0 assert record_messages.find("unstaged changes") _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.1") # git repo unchanged assert sha1 == expected git.call("reset", "--hard") rc = qisrc_action("sync", retcode=True) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.2") # if modification is revert sync must be successful assert rc != 0 assert sha1 == expected
def test_switching_to_new_fixed_ref_local_changes(qisrc_action, git_server, record_messages): """ Test Switching To New Fixed Ref Local Changes """ git_server.create_repo("foo.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") git_server.push_tag("foo.git", "v0.2") git_server.push_file("foo.git", "c.txt", "c") git_server.set_fixed_ref("foo.git", "v0.1") qisrc_action("init", git_server.manifest_url) git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = TestGit(foo_proj.path) git.write_file("a.txt", "unstaged changes") git_server.set_fixed_ref("foo.git", "v0.2") record_messages.reset() rc = qisrc_action("sync", retcode=True) # ERROR message must be displayed to warn user assert rc != 0 assert record_messages.find("unstaged changes") _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.1") # git repo unchanged assert sha1 == expected git.call("reset", "--hard") rc = qisrc_action("sync", retcode=True) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.2") # if modification is revert sync must be successful assert rc != 0 assert sha1 == expected
def _test_switching_to_fixed_ref_happy(qisrc_action, git_server, record_messages, tag_ref_to_test, branch_ref_to_test): git_server.create_repo("foo.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") git_server.push_branch("foo.git", "feature/b") git_server.push_file("foo.git", "c.txt", "c") qisrc_action("init", git_server.manifest_url) # Check for fixed_ref tag git_server.set_fixed_ref("foo.git", tag_ref_to_test) qisrc_action("sync") git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = qisrc.git.Git(foo_proj.path) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.1") assert sha1 == expected # qisrc.reset.clever_reset_ref should tell where is the HEAD after reset record_messages.reset() qisrc_action("sync") assert record_messages.find("HEAD is now at") assert record_messages.find("Add a.txt") _, status_output = git.status(raises=False) assert "HEAD" in status_output assert "detached" in status_output # If branch ref name is local, makesure it exists on local copy, then go back to master if branch_ref_to_test == "feature/b": git.checkout("feature/b", raises=False) git.checkout("master", raises=False) # Check for fixed_ref branch git_server.set_fixed_ref("foo.git", branch_ref_to_test) qisrc_action("sync") git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = qisrc.git.Git(foo_proj.path) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/remotes/origin/feature/b") assert sha1 == expected # qisrc.reset.clever_reset_ref should tell where is the HEAD after reset record_messages.reset() qisrc_action("sync") assert record_messages.find("HEAD is now at") assert record_messages.find("Add b.txt") _, status_output = git.status(raises=False) # FIXME: when using ref long name branch (refs/xxx), if we come from a tag, we stay in a detached head, # and we should be in an attached head state to be consistent with the ref short name branc behaviour # That's not an issue for now as users reference short name in manifest, but it will be cleaner to be consistent... if not branch_ref_to_test.startswith("refs/"): assert "HEAD" not in status_output assert "detached" not in status_output else: # Remove these assert when dealing with behaviour consistency mentionned above assert "HEAD" in status_output assert "detached" in status_output
def _test_switching_to_fixed_ref_happy(qisrc_action, git_server, record_messages, tag_ref_to_test, branch_ref_to_test): """ Test Switching To Fixed Ref Happy """ git_server.create_repo("foo.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") git_server.push_branch("foo.git", "feature/b") git_server.push_file("foo.git", "c.txt", "c") qisrc_action("init", git_server.manifest_url) # Check for fixed_ref tag git_server.set_fixed_ref("foo.git", tag_ref_to_test) qisrc_action("sync") git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = qisrc.git.Git(foo_proj.path) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.1") assert sha1 == expected # qisrc.reset.clever_reset_ref should tell where is the HEAD after reset record_messages.reset() qisrc_action("sync") assert record_messages.find("HEAD is now at") assert record_messages.find("Add a.txt") _, status_output = git.status(raises=False) assert "HEAD" in status_output assert "detached" in status_output # If branch ref name is local, makesure it exists on local copy, then go back to master if branch_ref_to_test == "feature/b": git.checkout("feature/b", raises=False) git.checkout("master", raises=False) # Check for fixed_ref branch git_server.set_fixed_ref("foo.git", branch_ref_to_test) qisrc_action("sync") git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = qisrc.git.Git(foo_proj.path) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/remotes/origin/feature/b") assert sha1 == expected # qisrc.reset.clever_reset_ref should tell where is the HEAD after reset record_messages.reset() qisrc_action("sync") assert record_messages.find("HEAD is now at") assert record_messages.find("Add b.txt") _, status_output = git.status(raises=False) # FIXME: when using ref long name branch (refs/xxx), if we come from a tag, we stay in a detached head, # and we should be in an attached head state to be consistent with the ref short name branc behaviour # That's not an issue for now as users reference short name in manifest, but it will be cleaner to be consistent... if not branch_ref_to_test.startswith("refs/"): assert "HEAD" not in status_output assert "detached" not in status_output else: # Remove these assert when dealing with behaviour consistency mentionned above assert "HEAD" in status_output assert "detached" in status_output
def test_qisrc_checkout_with_branch_to_ref(qisrc_action, git_server): """ Test QiSrc Checkout With Branch to Ref """ manifest_url = git_server.manifest_url git_server.create_repo("foo.git") git_server.create_repo("bar.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") git_server.push_tag("bar.git", "v0.2") git_server.push_file("bar.git", "c.txt", "b") qisrc_action("init", manifest_url) git_server.switch_manifest_branch("devel") git_server.set_fixed_ref("foo.git", "v0.1") git_server.set_fixed_ref("bar.git", "v0.2") git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = TestGit(foo_proj.path) assert git.get_current_branch() == "master" qisrc_action("checkout", "devel") _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.1") assert sha1 == expected bar_proj = git_worktree.get_git_project("bar") bar_git = qisrc.git.Git(bar_proj.path) _, sha1 = bar_git.call("rev-parse", "HEAD", raises=False) expected = bar_git.get_ref_sha1("refs/tags/v0.2") assert sha1 == expected
def test_qisrc_checkout_with_branch_to_ref(qisrc_action, git_server): """ Test QiSrc Checkout With Branch to Ref """ manifest_url = git_server.manifest_url git_server.create_repo("foo.git") git_server.create_repo("bar.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") git_server.push_tag("bar.git", "v0.2") git_server.push_file("bar.git", "c.txt", "b") qisrc_action("init", manifest_url) git_server.switch_manifest_branch("devel") git_server.set_fixed_ref("foo.git", "v0.1") git_server.set_fixed_ref("bar.git", "v0.2") git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = TestGit(foo_proj.path) assert git.get_current_branch() == "master" qisrc_action("checkout", "devel") _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.1") assert sha1 == expected bar_proj = git_worktree.get_git_project("bar") bar_git = qisrc.git.Git(bar_proj.path) _, sha1 = bar_git.call("rev-parse", "HEAD", raises=False) expected = bar_git.get_ref_sha1("refs/tags/v0.2") assert sha1 == expected
def test_switching_to_fixed_ref_happy(qisrc_action, git_server, record_messages): git_server.create_repo("foo.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") qisrc_action("init", git_server.manifest_url) git_server.set_fixed_ref("foo.git", "v0.1") qisrc_action("sync") git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = qisrc.git.Git(foo_proj.path) actual = git.get_ref_sha1("refs/heads/master") expected = git.get_ref_sha1("refs/tags/v0.1") assert actual == expected # qisrc.reset.clever_reset_ref should do nothing, so there should be # no output record_messages.reset() qisrc_action("sync") assert not record_messages.find("HEAD is now at")
def test_tags(qisrc_action, git_server): """ Test Tags """ git_server.create_repo("foo.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") git_server.set_fixed_ref("foo.git", "v0.1") qisrc_action("init", git_server.manifest_url) git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = TestGit(foo_proj.path) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.1") assert sha1 == expected
def test_tags(qisrc_action, git_server): """ Test Tags """ git_server.create_repo("foo.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") git_server.set_fixed_ref("foo.git", "v0.1") qisrc_action("init", git_server.manifest_url) git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = TestGit(foo_proj.path) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.1") assert sha1 == expected
def test_switching_from_fixed_ref_to_branch(qisrc_action, git_server): git_server.create_repo("foo.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") qisrc_action("init", git_server.manifest_url) git_server.set_fixed_ref("foo.git", "v0.1") qisrc_action("sync") git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = qisrc.git.Git(foo_proj.path) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.1") assert sha1 == expected git_server.set_branch("foo.git", "master") qisrc_action("sync") assert git.get_current_branch() == "master"
def test_switching_to_new_fixed_ref(qisrc_action, git_server): """ Test Switching To New Fixed Ref """ git_server.create_repo("foo.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") git_server.push_tag("foo.git", "v0.2") git_server.push_file("foo.git", "c.txt", "c") git_server.set_fixed_ref("foo.git", "v0.1") qisrc_action("init", git_server.manifest_url) git_server.set_fixed_ref("foo.git", "v0.2") qisrc_action("sync", retcode=True) git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = qisrc.git.Git(foo_proj.path) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.2") assert sha1 == expected
def test_switching_from_fixed_ref_to_branch(qisrc_action, git_server): """ Test Switching From Fixed Ref To Branch """ git_server.create_repo("foo.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") qisrc_action("init", git_server.manifest_url) git_server.set_fixed_ref("foo.git", "v0.1") qisrc_action("sync") git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = qisrc.git.Git(foo_proj.path) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.1") assert sha1 == expected git_server.set_branch("foo.git", "master") qisrc_action("sync") assert git.get_current_branch() == "master"
def test_switching_to_new_fixed_ref(qisrc_action, git_server): """ Test Switching To New Fixed Ref """ git_server.create_repo("foo.git") git_server.push_file("foo.git", "a.txt", "a") git_server.push_tag("foo.git", "v0.1") git_server.push_file("foo.git", "b.txt", "b") git_server.push_tag("foo.git", "v0.2") git_server.push_file("foo.git", "c.txt", "c") git_server.set_fixed_ref("foo.git", "v0.1") qisrc_action("init", git_server.manifest_url) git_server.set_fixed_ref("foo.git", "v0.2") qisrc_action("sync", retcode=True) git_worktree = TestGitWorkTree() foo_proj = git_worktree.get_git_project("foo") git = qisrc.git.Git(foo_proj.path) _, sha1 = git.call("rev-parse", "HEAD", raises=False) expected = git.get_ref_sha1("refs/tags/v0.2") assert sha1 == expected