Esempio n. 1
0
def test_uses_build_deps_by_default(qisrc_action, git_server):
    git_server.add_qibuild_test_project("world")
    git_server.add_qibuild_test_project("hello")
    git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)

    # Crete some changes in foo and world
    git_server.push_file("foo.git", "foo.txt", "unrelated changes")
    git_server.push_file("world.git", "world.txt", "dependency has been updated")

    # Sync hello
    qisrc_action.chdir("hello")
    qisrc_action("sync")
    qisrc_action.chdir(qisrc_action.root)
    git_worktree = TestGitWorkTree()

    # foo is not a dep, should not have changed:
    foo_proj = git_worktree.get_git_project("foo")
    foo_txt = os.path.join(foo_proj.path, "foo.txt")
    assert not os.path.exists(foo_txt)

    # World is a dep of hello:
    world_proj = git_worktree.get_git_project("world")
    world_txt = os.path.join(world_proj.path, "world.txt")
    assert os.path.exists(world_txt)
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
def test_moving_repos_sync_action(git_worktree, git_server, qisrc_action):
    git_server.create_repo("lib/foo.git")
    manifest_url = git_server.manifest_url
    git_worktree.configure_manifest("default", manifest_url)
    git_server.move_repo("lib/foo.git", "lib/bar")
    qisrc_action("sync")
    git_worktree = TestGitWorkTree()
    assert not git_worktree.get_git_project("lib/foo")
    assert git_worktree.get_git_project("lib/bar")
    # Sync twice just to test that nothing happens
    qisrc_action("sync")
Esempio n. 5
0
def test_wrong_branch(qisrc_action, git_server, record_messages):
    """ Test Wrong Branch """
    git_server.create_repo("foo.git")
    git_server.create_repo("bar.git")
    qisrc_action("init", git_server.manifest_url)
    git_worktree = TestGitWorkTree()
    foo1 = git_worktree.get_git_project("foo")
    _bar1 = git_worktree.get_git_project("bar")
    foo_git = qisrc.git.Git(foo1.path)
    foo_git.checkout("-B", "devel")
    qisrc_action("status")
    assert record_messages.find("Some projects are not on the expected branch")
    assert record_messages.find(r"\* foo\s+devel\s+master")
Esempio n. 6
0
def test_checkout_happy(qisrc_action, git_server):
    manifest_url = git_server.manifest_url
    git_server.create_repo("foo.git")
    git_server.create_repo("bar.git")
    qisrc_action("init", manifest_url)
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo.git", "devel")
    qisrc_action("checkout", "devel")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    foo_git = qisrc.git.Git(foo_proj.path)
    assert foo_git.get_current_branch() == "devel"
    bar_proj = git_worktree.get_git_project("bar")
    bar_git = qisrc.git.Git(bar_proj.path)
    assert bar_git.get_current_branch() == "master"
Esempio n. 7
0
def setup_test():
    build_worktree = TestBuildWorkTree()
    foo = build_worktree.create_project("foo")
    world = build_worktree.create_project("world")
    hello = build_worktree.create_project("hello", build_depends=["world"])
    git = qisrc.git.Git(foo.path)
    git.init()
    git = qisrc.git.Git(world.path)
    git.init()
    git = qisrc.git.Git(hello.path)
    git.init()
    git_worktree = TestGitWorkTree()
    foo = git_worktree.get_git_project("foo")
    hello = git_worktree.get_git_project("hello")
    world = git_worktree.get_git_project("world")
    return (foo, hello, world)
Esempio n. 8
0
def test_check(qisrc_action, git_server):
    # Get a correct xml file from the server:
    manifest_url = git_server.manifest_url
    git_server.create_repo("foo.git")
    qisrc_action("init", manifest_url)

    # copy it to an other place, make a mistake, and run --check:
    srv_xml = git_server.src.join("manifest", "manifest.xml")
    manifest = qisrc.manifest.Manifest(srv_xml.strpath)
    editable_path = qisrc_action.tmpdir.join("manifest.xml")
    manifest.manifest_xml = editable_path.strpath
    manifest.add_repo("doestnotexists.git", "nowhere", ["origin"])
    manifest.dump()

    rc = qisrc_action("check-manifest", editable_path.strpath,
                      retcode=True)
    assert rc != 0
    # running qisrc sync should still work:
    qisrc_action("sync")

    # this time create a correct xml and re-run --check:
    git_server.create_repo("bar.git")
    manifest = qisrc.manifest.Manifest(srv_xml.strpath)
    editable_path = qisrc_action.tmpdir.join("manifest.xml")
    manifest.manifest_xml = editable_path.strpath
    manifest.dump()

    qisrc_action("check-manifest", editable_path.strpath)
    git_worktree = TestGitWorkTree()
    assert git_worktree.get_git_project("bar")

    # running qisrc sync just to be sure:
    qisrc_action("sync")
Esempio n. 9
0
def test_clone_new_repos(qisrc_action, git_server):
    git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)
    git_server.create_repo("bar.git")
    qisrc_action("sync")
    git_worktree = TestGitWorkTree()
    assert git_worktree.get_git_project("bar")
Esempio n. 10
0
def test_switching_from_fixed_ref_to_branch_local_changes(qisrc_action, git_server, record_messages):
    """ Test Swithcing From Fixed Ref To Branch 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_branch("foo.git", "master")
    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")
    qisrc_action("sync", retcode=True)
    # if modification is revert sync must be successful
    assert git.get_current_branch() == "master"
Esempio n. 11
0
def test_creates_required_subdirs(qisrc_action, git_server):
    """ Test Create Required SubDirs """
    git_server.create_repo("foo/bar.git")
    qisrc_action("init", git_server.manifest_url)
    qisrc_action("sync")
    git_worktree = TestGitWorkTree()
    assert git_worktree.get_git_project("foo/bar")
Esempio n. 12
0
def test_check_configures_review(qisrc_action, git_server):

    # Get a correct xml file from the server:
    manifest_url = git_server.manifest_url
    qisrc_action("init", manifest_url)

    git_server.create_repo("foo.git")
    git_server._create_repo("foo.git", review=True)

    # Create a foo repo, but without code review set
    foo_proj = qisrc_action.create_git_project("foo")
    assert not foo_proj.review

    # Edit the manifest.xml to set code review for foo
    srv_xml = git_server.src.join("manifest", "manifest.xml")
    manifest = qisrc.manifest.Manifest(srv_xml.strpath)
    editable_path = qisrc_action.tmpdir.join("manifest.xml")
    manifest.manifest_xml = editable_path.strpath

    foo_repo = manifest.get_repo("foo.git")
    foo_repo.remote_names = ["origin", "gerrit"]

    manifest.dump()

    # Run qisrc check-manifest
    qisrc_action("check-manifest", editable_path.strpath)

    # Code review should be now set:
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    assert foo_proj.review
Esempio n. 13
0
def test_sync_branch_devel(qisrc_action, git_server, test_git):
    # This tests the case where everything goes smoothly
    git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)
    git_server.push_file("foo.git", "foo.txt", "a super change")
    git_server.push_file("foo.git", "bar.txt", "a super bugfix")
    git_worktree = TestGitWorkTree()

    foo = git_worktree.get_git_project("foo")

    test_git = TestGit(foo.path)
    test_git.call("checkout", "-b", "devel")

    test_git.commit_file("developing.txt", "like a boss")
    git_server.push_file("foo.git", "foobar.txt", "some other change")
    git_server.push_file("foo.git", "bigchange.txt", "some huge change")

    qisrc_action("sync", "--rebase-devel")
    test_git.call("checkout", "master")
    # Check that master is fast-forwarded
    bigchange_txt = os.path.join(foo.path, "bigchange.txt")
    assert os.path.exists(bigchange_txt)

    # Check rebase is done smoothly
    test_git.call("checkout", "devel")
    test_git.call("rebase", "master")
    assert os.path.exists(bigchange_txt)
    developing_txt = os.path.join(foo.path, "developing.txt")
    assert os.path.exists(developing_txt)
Esempio n. 14
0
def test_using_checkout_after_no_review(qisrc_action, git_server):
    git_server.create_repo("foo", review=True)
    qisrc_action("init", git_server.manifest_url, "--no-review")
    git_server.switch_manifest_branch("devel")
    qisrc_action("checkout", "devel")
    git_worktree = TestGitWorkTree()
    foo = git_worktree.get_git_project("foo")
    assert not foo.review
Esempio n. 15
0
def test_retcode_when_skipping(qisrc_action, git_server):
    git_server.create_repo("bar")
    qisrc_action("init", git_server.manifest_url)
    git_worktree = TestGitWorkTree()
    bar_proj = git_worktree.get_git_project("bar")
    git = TestGit(bar_proj.path)
    git.checkout("-b", "devel")
    rc = qisrc_action("sync", retcode=True)
    assert rc != 0
Esempio n. 16
0
def test_configure_new_repos(qisrc_action, git_server):
    git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)
    qisrc_action("sync")
    git_server.create_repo("bar.git")
    qisrc_action("sync", "foo")  # Sync only foo, but expect to clone bar
    git_worktree = TestGitWorkTree()
    bar = git_worktree.get_git_project("bar")
    assert bar.default_remote
Esempio n. 17
0
def test_does_not_store_if_setup_fails(git_worktree, git_server):
    git_server.create_repo("foo", review=True)
    manifest_url = git_server.manifest_url
    worktree_syncer = qisrc.sync.WorkTreeSyncer(git_worktree)
    with mock.patch("qisrc.review.setup_project") as mock_setup:
        mock_setup.return_value = False
        worktree_syncer.configure_manifest(manifest_url)
    git_worktree2 = TestGitWorkTree()
    foo = git_worktree2.get_git_project("foo")
    assert foo.review is False
Esempio n. 18
0
def test_checkout_preserve_changes_when_checkout_fails(qisrc_action, git_server):
    manifest_url = git_server.manifest_url
    git_server.create_repo("foo.git")
    git_server.push_file("foo.git", "README.txt", "readme\n")
    qisrc_action("init", manifest_url)
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo.git", "devel")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    readme = os.path.join(foo_proj.path, "README.txt")
    with open(readme, "w") as fp:
        fp.write("unstaged\n")
    qisrc_action("checkout", "devel")
    foo_proj = git_worktree.get_git_project("foo")
    foo_git = qisrc.git.Git(foo_proj.path)
    assert foo_git.get_current_branch() == "master"
    # With --force:
    qisrc_action("checkout", "devel", "--force")
    assert foo_git.get_current_branch() == "devel"
Esempio n. 19
0
def test_re_add_path_exists(qisrc_action, git_server):
    setup_re_add(qisrc_action, git_server)
    git_worktree = TestGitWorkTree()
    c_path = git_worktree.get_git_project("c").path
    qisrc_action("manifest", "default", "--group", "mygroup")
    qisys.sh.rm(c_path)
    qisys.sh.mkdir(c_path)
    qisrc_action("manifest", "default")
    git_worktree = TestGitWorkTree()
    assert len(git_worktree.git_projects) == 3
Esempio n. 20
0
def test_re_add_removed_by_hand(qisrc_action, git_server):
    manifest_url =  git_server.manifest_url
    setup_re_add(qisrc_action, git_server)
    git_worktree = TestGitWorkTree()
    c_path = git_worktree.get_git_project("c").path
    qisrc_action("init", manifest_url, "--group", "mygroup")
    qisys.sh.rm(c_path)
    qisrc_action("init", manifest_url)
    git_worktree = TestGitWorkTree()
    assert len(git_worktree.git_projects) == 3
Esempio n. 21
0
def test_skip_when_not_on_correct_branch(git_server, qisrc_action, record_messages):
    git_server.create_repo("foo")
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo", "devel")
    qisrc_action("init", git_server.manifest_url, "--branch", "devel")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    git = TestGit(foo_proj.path)
    git.checkout("-B", "perso")
    qisrc_action("rebase", "--branch", "master", "--all")
    assert record_messages.find("skipped")
Esempio n. 22
0
def test_not_under_code_review(qisrc_action, git_server):
    foo_repo = git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    foo_git = TestGit(foo_proj.path)
    foo_git.commit_file("a.txt", "a")
    qisrc_action("push", "foo")
    _, sha1 = foo_git.call("log", "-1", "--pretty=%H", raises=False)
    (_, remote) = foo_git.call("ls-remote", "origin", "master", raises=False)
    assert remote == "%s\trefs/heads/master" % sha1
Esempio n. 23
0
def test_when_ahead(git_server, qisrc_action):
    git_server.create_repo("foo")
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo", "devel")
    qisrc_action("init", git_server.manifest_url, "--branch", "devel")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    git = TestGit(foo_proj.path)
    git.commit_file("devel.txt", "devel")
    git.push()
    qisrc_action("rebase", "--all")
Esempio n. 24
0
def test_publish_changes(qisrc_action, git_server):
    foo_repo = git_server.create_repo("foo.git", review=True)
    qisrc_action("init", git_server.manifest_url)
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    foo_git = TestGit(foo_proj.path)
    foo_git.commit_file("a.txt", "a")
    qisrc_action("push", "foo")
    _, sha1 = foo_git.call("log", "-1", "--pretty=%H", raises=False)
    (_, remote) = foo_git.call("ls-remote", "gerrit", "refs/for/master", raises=False)
    assert remote == "%s\trefs/for/master" % sha1
Esempio n. 25
0
def test_reset_undo_local_changes(qisrc_action, git_server):
    git_server.create_repo("foo")
    manifest_url = git_server.manifest_url
    qisrc_action("init", manifest_url)
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    foo_git = TestGit(foo_proj.path)
    orig_gitinore = foo_git.read_file(".gitignore")
    foo_git.root.join(".gitignore").write("new line\n")
    qisrc_action("reset", "--force")
    assert foo_git.read_file(".gitignore") == orig_gitinore
Esempio n. 26
0
def test_behind(qisrc_action, git_server, record_messages):
    git_server.create_repo("foo.git")
    git_server.create_repo("bar.git")
    qisrc_action("manifest", "--add", "default", git_server.manifest_url)
    git_worktree = TestGitWorkTree()
    foo = git_worktree.get_git_project("foo")
    git_server.push_file("foo.git", "new_file", "")
    foo_git = qisrc.git.Git(foo.path)
    foo_git.fetch()
    qisrc_action("status")
    assert record_messages.find("foo : master tracking -1")
Esempio n. 27
0
def test_checkout_creates_at_correct_place(qisrc_action, git_server):
    manifest_url = git_server.manifest_url
    git_server.create_repo("foo.git")
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo.git", "devel")
    git_server.push_file("foo.git", "foo.txt", "this is foo")
    qisrc_action("init", manifest_url, "--branch", "devel")
    qisrc_action("checkout", "master")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    git = TestGit(foo_proj.path)
    git.read_file("foo.txt")
Esempio n. 28
0
def test_re_add_path_exists(qisrc_action, git_server):
    """ Test Re Add Path Exists """
    manifest_url = git_server.manifest_url
    setup_re_add(qisrc_action, git_server)
    git_worktree = TestGitWorkTree()
    c_path = git_worktree.get_git_project("c").path
    qisrc_action("init", manifest_url, "--group", "mygroup")
    qisys.sh.rm(c_path)
    qisys.sh.mkdir(c_path)
    qisrc_action("init", manifest_url)
    git_worktree = TestGitWorkTree()
    assert len(git_worktree.git_projects) == 3
Esempio n. 29
0
def test_checkout_preserve_changes_when_checkout_fails(qisrc_action,
                                                       git_server):
    manifest_url = git_server.manifest_url
    git_server.create_repo("foo.git")
    git_server.push_file("foo.git", "README.txt", "readme\n")
    qisrc_action("init", manifest_url)
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo.git", "devel")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    readme = os.path.join(foo_proj.path, "README.txt")
    with open(readme, "w") as fp:
        fp.write("unstaged\n")
    rc = qisrc_action("checkout", "devel", retcode=True)
    assert rc != 0
    foo_proj = git_worktree.get_git_project("foo")
    foo_git = qisrc.git.Git(foo_proj.path)
    assert foo_git.get_current_branch() == "master"
    # With --force:
    qisrc_action("checkout", "devel", "--force")
    assert foo_git.get_current_branch() == "devel"
Esempio n. 30
0
def test_checkout_creates_at_correct_place(qisrc_action, git_server):
    manifest_url = git_server.manifest_url
    git_server.create_repo("foo.git")
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo.git", "devel")
    git_server.push_file("foo.git", "foo.txt", "this is foo")
    qisrc_action("init", manifest_url, "--branch", "devel")
    qisrc_action("checkout", "master")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    git = TestGit(foo_proj.path)
    git.read_file("foo.txt")
Esempio n. 31
0
def test_using_force_when_not_an_a_branch(qisrc_action, git_server):
    git_server.create_repo("foo.git")
    git_server.push_file("foo.git", "foo.txt", "this is foo")
    manifest_url = git_server.manifest_url
    qisrc_action("init", manifest_url)
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    git = qisrc.git.Git(foo_proj.path)
    git.checkout("HEAD~1")
    assert not git.get_current_branch()
    qisrc_action("checkout", "master", "--force")
    assert git.get_current_branch() == "master"
Esempio n. 32
0
def test_sync_dash_g(qisrc_action, git_server):
    git_server.create_group("mygroup", ["a", "b"])
    git_server.create_repo("other")
    git_server.push_file("other", "other.txt", "change 1")
    qisrc_action("init", git_server.manifest_url)
    git_server.push_file("other", "other.txt", "change 2")
    qisrc_action("sync", "--group", "mygroup")

    git_worktree = TestGitWorkTree()
    other_proj = git_worktree.get_git_project("other")
    other_git = TestGit(other_proj.path)
    assert other_git.read_file("other.txt") == "change 1"
Esempio n. 33
0
def test_using_force_when_not_a_branch(qisrc_action, git_server):
    """ Test Using Force When Not a Branch """
    git_server.create_repo("foo.git")
    git_server.push_file("foo.git", "foo.txt", "this is foo")
    manifest_url = git_server.manifest_url
    qisrc_action("init", manifest_url)
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    git = qisrc.git.Git(foo_proj.path)
    git.checkout("HEAD~1")
    assert not git.get_current_branch()
    qisrc_action("checkout", "master", "--force")
    assert git.get_current_branch() == "master"
Esempio n. 34
0
def test_retcode_when_checkout_fails(qisrc_action, git_server):
    """ Test RetCode When Checkout """
    git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo.git", "devel")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    gitignore = os.path.join(foo_proj.path, ".gitignore")
    with open(gitignore, "w") as fp:
        fp.write("unstaged\n")
    rc = qisrc_action("checkout", "devel", retcode=True)
    assert rc != 0
Esempio n. 35
0
def test_using_carbon_copy(qisrc_action, git_server):
    foo_repo = git_server.create_repo("foo.git", review=True)
    qisrc_action("init", git_server.manifest_url)
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    foo_git = TestGit(foo_proj.path)
    # Need to fetch gerrit remote at least once for gerrit/master to exist
    foo_git.fetch("--all")
    foo_git.commit_file("a.txt", "a")
    with mock.patch.object(qisys.command, "call") as mocked_call:
        qisrc_action("push", "--project", "foo", "--cc", "jdoe")
    set_reviewers_args =  mocked_call.call_args_list[2][0][0][7]
    assert "jdoe" in set_reviewers_args
Esempio n. 36
0
def test_pushing_custom_ref(qisrc_action, git_server):
    foo_repo = git_server.create_repo("foo.git", review=True)
    qisrc_action("init", git_server.manifest_url)
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    foo_git = TestGit(foo_proj.path)
    foo_git.checkout("-b", "perso")
    foo_git.commit_file("a.txt", "a")
    _, sha1 = foo_git.call("log", "-1", "--pretty=%H", raises=False)
    foo_git.commit_file("b.txt", "b")
    qisrc_action("push", "--project", "foo", "HEAD~1:master")
    (_, remote) = foo_git.call("ls-remote", "gerrit", "refs/for/master", raises=False)
    assert remote == "%s\trefs/for/master" % sha1
Esempio n. 37
0
def test_fixed_ref_behind(qisrc_action, git_server, record_messages):
    """ Test Fixed Ref Behind """
    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.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 = qisrc.git.Git(foo_proj.path)
    git.call("reset", "--hard", "HEAD~1")
    qisrc_action("status")
    assert record_messages.find("fixed ref v0.1 -1")
Esempio n. 38
0
def test_fixed_ref_local_changes(qisrc_action, git_server, record_messages):
    git_server.create_repo("foo.git")
    git_server.push_file("foo.git", "a.txt", "a")
    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.push_tag("foo.git", "v.01")
    record_messages.reset()
    rc = qisrc_action("sync", retcode=True)
    assert rc != 0
    assert record_messages.find("unstaged changes")
Esempio n. 39
0
def test_removing_forked_project(qisrc_action, git_server):
    git_server.create_repo("booz")
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("booz", "devel")
    qisrc_action("init", git_server.manifest_url, "--branch", "devel")
    git_worktree = TestGitWorkTree()
    booz_proj = git_worktree.get_git_project("booz")
    git = qisrc.git.Git(booz_proj.path)
    assert git.get_current_branch() == "devel"
    git_server.change_branch("booz", "master")
    qisrc_action("sync", "-a", retcode=True)
    qisrc_action("checkout", "devel")
    assert git.get_current_branch() == "master"
Esempio n. 40
0
def test_uses_build_deps_by_default(qisrc_action, git_server):
    """ Test Uses Build Deps By Default """
    git_server.add_qibuild_test_project("world")
    git_server.add_qibuild_test_project("hello")
    git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)
    # Crete some changes in foo and world
    git_server.push_file("foo.git", "foo.txt", "unrelated changes")
    git_server.push_file("world.git", "world.txt", "dependency has been updated")
    # Sync hello
    qisrc_action.chdir("hello")
    qisrc_action("sync")
    qisrc_action.chdir(qisrc_action.root)
    git_worktree = TestGitWorkTree()
    # foo is not a dep, should not have changed:
    foo_proj = git_worktree.get_git_project("foo")
    foo_txt = os.path.join(foo_proj.path, "foo.txt")
    assert not os.path.exists(foo_txt)
    # World is a dep of hello:
    world_proj = git_worktree.get_git_project("world")
    world_txt = os.path.join(world_proj.path, "world.txt")
    assert os.path.exists(world_txt)
Esempio n. 41
0
def test_changing_branch_of_repo_under_code_review(qisrc_action, git_server,
                                                   record_messages):
    git_server.create_repo("foo.git", review=True)
    qisrc_action("init", git_server.manifest_url)
    git_server.change_branch("foo.git", "devel")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    git = TestGit(foo_proj.path)
    git.checkout("-b", "devel")
    record_messages.reset()
    qisrc_action("sync")
    assert record_messages.find("default branch changed")
    assert not record_messages.find("now using code review")
Esempio n. 42
0
def test_fixed_ref(qisrc_action, git_server):
    git_server.create_repo("foo.git")
    git_server.push_tag("foo.git", "v0.1")
    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.commit_file("a.txt", "a", "test")
    qisrc_action("reset")
    _, actual = git.call("rev-parse", "HEAD", raises=False)
    _, expected = git.call("rev-parse", "v0.1", raises=False)
    assert actual == expected
Esempio n. 43
0
def test_keeps_staged_changes(qisrc_action, git_server):
    git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)
    qisrc_action("sync")
    git_worktree = TestGitWorkTree()
    foo = git_worktree.get_git_project("foo")
    test_git = TestGit(foo.path)
    staged_file = os.path.join(foo.path, "staged")
    with open(staged_file, "w") as f:
        f.write("I'm going to stage stuff")
    test_git.add(staged_file)
    foo.sync()
    assert os.path.exists(staged_file)
Esempio n. 44
0
def test_incorrect_branch_still_fetches(qisrc_action, git_server):
    git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)
    qisrc_action("sync")
    git_worktree = TestGitWorkTree()
    foo = git_worktree.get_git_project("foo")
    test_git = TestGit(foo.path)
    test_git.checkout("-b", "wip")
    git_server.push_file("foo.git", "foo.txt", "some change")
    previous_sha1 = test_git.get_ref_sha1("refs/remotes/origin/master")
    foo.sync()
    new_sha1 = test_git.get_ref_sha1("refs/remotes/origin/master")
    assert previous_sha1 != new_sha1
Esempio n. 45
0
def test_raises_when_not_on_correct_branch(git_server, qisrc_action,
                                           record_messages):
    """ Test Raises When Not On Correct Branch """
    git_server.create_repo("foo")
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo", "devel")
    qisrc_action("init", git_server.manifest_url, "--branch", "devel")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    git = TestGit(foo_proj.path)
    git.checkout("-B", "perso")
    error = qisrc_action("rebase", "--branch", "master", "--all", raises=True)
    assert " * foo" in error
    assert record_messages.find("skipped")
Esempio n. 46
0
def test_qisrc_checkout_with_ref_to_branch(qisrc_action, git_server):
    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.set_fixed_ref("foo.git", "v0.1")
    qisrc_action("init", manifest_url)
    git_server.switch_manifest_branch("devel")
    git_server.set_branch("foo.git", "devel")
    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
    qisrc_action("checkout", "devel")
    foo_git = qisrc.git.Git(foo_proj.path)
    assert foo_git.get_current_branch() == "devel"
    bar_proj = git_worktree.get_git_project("bar")
    bar_git = qisrc.git.Git(bar_proj.path)
    assert bar_git.get_current_branch() == "master"
Esempio n. 47
0
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
Esempio n. 48
0
def test_check_adding_group(qisrc_action, git_server):
    """ Test Check Adding Group """
    git_server.create_repo("a.git")
    git_server.create_group("default", ["b'.git"], default=True)
    qisrc_action("init", git_server.manifest_url)
    # Edit the manifest.xml to set code review for foo
    srv_xml = git_server.src.join("manifest", "manifest.xml")
    manifest = qisrc.manifest.Manifest(srv_xml.strpath)
    editable_path = qisrc_action.tmpdir.join("manifest.xml")
    manifest.manifest_xml = editable_path.strpath
    manifest.configure_group("foo", ["a.git"])
    qisrc_action("add-group", "foo")
    qisrc_action("check-manifest", editable_path.strpath)
    git_worktree = TestGitWorkTree()
    assert git_worktree.get_git_project("a")
Esempio n. 49
0
def test_happy_rebase(git_server, qisrc_action):
    git_server.create_repo("foo")
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo", "devel")
    qisrc_action("init", git_server.manifest_url, "--branch", "devel")
    git_server.push_file("foo", "master.txt", "master")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    git = TestGit(foo_proj.path)
    git.commit_file("devel.txt", "devel")
    git.push()
    git.fetch()
    qisrc_action("rebase", "--branch", "master", "--all")
    rc, out = git.log("--pretty=oneline", raises=False)
    assert len(out.splitlines()) == 3
Esempio n. 50
0
def test_when_moved(git_server, qisrc_action, record_messages):  # pylint: disable=unused-argument
    git_server.create_repo("foo")
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo", "devel")
    git_server.move_repo("foo", "lib/foo")
    qisrc_action("init", git_server.manifest_url, "--branch", "devel")
    git_server.push_file("foo", "master.txt", "master")
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("lib/foo")
    git = TestGit(foo_proj.path)
    git.commit_file("devel.txt", "devel")
    git.push()
    qisrc_action("rebase", "--branch", "master", "--all")
    rc, out = git.log("--pretty=oneline", raises=False)
    assert len(out.splitlines()) == 3
Esempio n. 51
0
def test_not_under_code_review_ask_user(qisrc_action, git_server, interact):
    foo_repo = git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    foo_git = TestGit(foo_proj.path)
    foo_git.commit_file("a.txt", "a")
    interact.answers = [False, True]
    qisrc_action("push", "--project", "foo")
    _, sha1 = foo_git.call("log", "-1", "--pretty=%H", raises=False)
    (_, remote) = foo_git.call("ls-remote", "origin", "master", raises=False)
    assert remote != "%s\trefs/heads/master" % sha1
    qisrc_action("push", "--project", "foo")
    (_, remote) = foo_git.call("ls-remote", "origin", "master", raises=False)
    assert remote == "%s\trefs/heads/master" % sha1
Esempio n. 52
0
def test_publish_changes(qisrc_action, git_server):
    """ Test Publish Changes """
    _foo_repo = git_server.create_repo("foo.git", review=True)
    qisrc_action("init", git_server.manifest_url)
    git_worktree = TestGitWorkTree()
    foo_proj = git_worktree.get_git_project("foo")
    foo_git = TestGit(foo_proj.path)
    foo_git.commit_file("a.txt", "a")
    qisrc_action("push", "--project", "foo")
    _, sha1 = foo_git.call("log", "-1", "--pretty=%H", raises=False)
    (_, remote) = foo_git.call("ls-remote",
                               "gerrit",
                               "refs/for/master",
                               raises=False)
    assert remote == "%s\trefs/for/master" % sha1
Esempio n. 53
0
def test_when_not_on_a_branch(git_server, qisrc_action, record_messages):
    """ Test When Not On a Branch """
    git_server.create_repo("foo.git")
    git_server.switch_manifest_branch("devel")
    git_server.change_branch("foo.git", "devel")
    git_server.push_file("foo.git", "devel",
                         "this is devel\n", branch="devel",
                         message="start developing")
    qisrc_action("init", git_server.manifest_url, "--branch", "devel")
    git_worktree = TestGitWorkTree()
    foo1 = git_worktree.get_git_project("foo")
    git = qisrc.git.Git(foo1.path)
    git.checkout("HEAD~1")
    record_messages.reset()
    qisrc_action("log", "--all", "master")
    assert record_messages.find("Not on a branch")
Esempio n. 54
0
def test_qisrc_rm_group(qisrc_action, git_server):
    git_server.create_group("mygroup", ["a", "b"])
    git_server.create_group("foobar", ["foo", "bar", "baz"])
    qisrc_action("init", git_server.manifest_url,
                "--group", "mygroup",
                "--group", "foobar")
    git_worktree = TestGitWorkTree()
    a_proj = git_worktree.get_git_project("a")
    b_proj = git_worktree.get_git_project("b")
    assert len(git_worktree.git_projects) == 5
    qisrc_action("rm-group", "foobar")
    git_worktree = TestGitWorkTree()
    assert len(git_worktree.git_projects) == 2
    # Better safe than sorry ...
    assert os.path.exists(a_proj.path)
    assert os.path.exists(b_proj.path)
Esempio n. 55
0
def test_build_deps_not_top_dir(cd_to_tmpdir, args):
    args.dep_types = "default"
    build_worktree = TestBuildWorkTree()
    dep_proj = build_worktree.create_project("dep")
    git = qisrc.git.Git(dep_proj.path)
    git.init()
    foo = build_worktree.create_project("foo", src="top/foo", build_depends=["dep"])
    top_proj = build_worktree.worktree.add_project("top")
    git = qisrc.git.Git(top_proj.path)
    git.init()
    git_worktree = TestGitWorkTree()
    top_proj = git_worktree.get_git_project("top")
    dep_proj = git_worktree.get_git_project("dep")
    with qisys.sh.change_cwd(cd_to_tmpdir.join("top", "foo").strpath):
        projs =  get_git_projects(git_worktree, args,
                                  use_build_deps=True)
        assert projs == [dep_proj, top_proj]
Esempio n. 56
0
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_sync_branch_devel_no_ff(qisrc_action, git_server, test_git):
    """ Test Sync Branc Devel No Fast Forward """
    # Case where master can't be fast-forwarded, does nothing except warning
    git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)
    git_server.push_file("foo.git", "foo.txt", "a super change")
    git_worktree = TestGitWorkTree()
    foo1 = git_worktree.get_git_project("foo")
    test_git = TestGit(foo1.path)
    test_git.commit_file("foo.git", "div.txt", "diverging from master")
    master_sha1 = test_git.get_ref_sha1("refs/heads/master")
    test_git.call("checkout", "-b", "devel")
    test_git.commit_file("developing.txt", "like a boss")
    git_server.push_file("foo.git", "foobar.txt", "some other change")
    qisrc_action("sync", "--rebase-devel")
    # Master HEAD is untouched
    assert test_git.get_ref_sha1("refs/heads/master") == master_sha1
Esempio n. 58
0
def test_sync_reset(qisrc_action, git_server):
    git_server.create_repo("bar")
    git_server.create_repo("baz")
    qisrc_action("init", git_server.manifest_url)
    git_worktree = TestGitWorkTree()
    bar_proj = git_worktree.get_git_project("bar")
    baz_proj = git_worktree.get_git_project("baz")
    bar_git = TestGit(bar_proj.path)
    baz_git = TestGit(baz_proj.path)
    bar_git.checkout("-B", "devel")
    baz_git.commit_file("unrelated.txt", "unrelated\n")
    git_server.push_file("bar", "bar.txt", "this is bar\n")
    qisrc_action("sync", "--reset")
    assert bar_git.get_current_branch() == "master"
    assert bar_git.read_file("bar.txt") == "this is bar\n"
    # pylint: disable-msg=E1101
    with pytest.raises(Exception):
        baz_git.read_file("unrelated.txt")
def test_sync_branch_devel_unclean(qisrc_action, git_server, test_git):
    """ Test Sync Branch Devel UnClean """
    # Case where the worktree isn't clean
    git_server.create_repo("foo.git")
    qisrc_action("init", git_server.manifest_url)
    git_server.push_file("foo.git", "foo.txt", "a super change")
    git_server.push_file("foo.git", "bar.txt", "a super bugfix")
    git_worktree = TestGitWorkTree()
    foo1 = git_worktree.get_git_project("foo")
    test_git = TestGit(foo1.path)
    test_git.call("checkout", "-b", "devel")
    test_git.commit_file("developing.txt", "like a boss")
    git_server.push_file("foo.git", "foobar.txt", "some other change")
    wip_txt = os.path.join(foo1.path, "wip.txt")
    open(wip_txt, 'w').close()
    qisys.script.run_action("qisrc.actions.sync", ["--rebase-devel"])
    # Master has been fast-forwarded and I haven't lost my WIP
    assert os.path.exists(wip_txt)
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