当前位置: 首页>>代码示例>>Python>>正文


Python git.get_current_branch函数代码示例

本文整理汇总了Python中qisrc.git.get_current_branch函数的典型用法代码示例。如果您正苦于以下问题:Python get_current_branch函数的具体用法?Python get_current_branch怎么用?Python get_current_branch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_current_branch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_using_force_when_not_an_a_branch

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"
开发者ID:Mhalla,项目名称:qibuild,代码行数:12,代码来源:test_qisrc_checkout.py

示例2: test_get_current_branch

 def test_get_current_branch(self):
     bar_url = create_git_repo(self.tmp, "bar")
     work = os.path.join(self.tmp, "work")
     qibuild.sh.mkdir(work)
     bar_src = os.path.join(work, "bar")
     git = qisrc.git.Git(bar_src)
     git.clone(bar_url)
     self.assertEqual(git.get_current_branch(), "master")
     push_readme_v2(self.tmp, "bar", "master")
     git.pull()
     self.assertEqual(git.get_current_branch(), "master")
     git.checkout("-f", "HEAD~1")
     self.assertEqual(git.get_current_branch(), None)
开发者ID:sanyaade-research-hub,项目名称:qibuild,代码行数:13,代码来源:test_git.py

示例3: test_removing_forked_project

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"
开发者ID:Mhalla,项目名称:qibuild,代码行数:13,代码来源:test_qisrc_sync.py

示例4: test_switch_manifest_branch

def test_switch_manifest_branch(tmpdir, git_server):
    git_server.switch_manifest_branch("devel")
    assert git_server.manifest_branch == "devel"
    foo_clone = tmpdir.mkdir("foo")
    git = qisrc.git.Git(foo_clone.strpath)
    git.clone(git_server.manifest_url, "--branch", git_server.manifest_branch)
    assert git.get_current_branch() == "devel"
开发者ID:alkino,项目名称:qibuild,代码行数:7,代码来源:test_fixture.py

示例5: do

def do(args):
    """ Main entry point """
    git_worktree = qisrc.parsers.get_git_worktree(args)
    git_projects = qisrc.parsers.get_git_projects(git_worktree, args)
    for git_project in git_projects:
        maintainers = qisrc.maintainers.get(git_project)
        if not maintainers:
            mess = """\
The project in {src} has no maintainer.
Please edit {qiproject_xml} to silence this warning
"""
            ui.warning(mess.format(src=git_project.src, qiproject_xml=git_project.qiproject_xml), end="")
        reviewers = [x["email"] for x in maintainers]
        reviewers.extend(args.reviewers or list())
        git = qisrc.git.Git(git_project.path)
        current_branch = git.get_current_branch()
        if not current_branch:
            ui.error("Not currently on any branch")
            sys.exit(2)
        if git_project.review:
            qisrc.review.push(
                git_project,
                current_branch,
                bypass_review=(not args.review),
                dry_run=args.dry_run,
                reviewers=reviewers,
                topic=args.topic,
            )
        else:
            if args.dry_run:
                git.push("-n")
            else:
                git.push()
开发者ID:Fantomatic,项目名称:qibuild,代码行数:33,代码来源:push.py

示例6: test_untracked_would_be_overwritten

    def test_untracked_would_be_overwritten(self):
        bar_url = create_git_repo(self.tmp, "bar")
        work = os.path.join(self.tmp, "work")
        qibuild.sh.mkdir(work)
        bar_src = os.path.join(work, "bar")
        git = qisrc.git.Git(bar_src)
        git.clone(bar_url)

        # Create untracked, conflicting changes
        a_file = os.path.join(bar_src, "a_file")
        with open(a_file, "w") as fp:
            fp.write("a_file\n")

        upstream_src = os.path.join(self.tmp, "src", "bar")
        upstream_file = os.path.join(upstream_src, "a_file")
        with open(upstream_file, "w") as fp:
            fp.write("upstream file\n")
        upstream_git = qisrc.git.Git(upstream_src)
        upstream_git.call("add", "a_file")
        upstream_git.call("commit", "-m", "Add a file")
        upstream_git.call("push", bar_url, "master:master")

        err = git.update_branch("master", "origin")
        self.assertTrue(err)
        self.assertTrue("untracked working tree files" in err)
        self.assertEqual(git.get_current_branch(), "master")
开发者ID:sanyaade-research-hub,项目名称:qibuild,代码行数:26,代码来源:test_git.py

示例7: test_qisrc_checkout_with_branch_to_ref

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
开发者ID:aldebaran,项目名称:qibuild,代码行数:27,代码来源:test_qisrc_checkout.py

示例8: push_submodule

    def push_submodule(self, project, submodule_url, destination_dir,
                       branch="master", fast_forward=True,
                       message=None):
        """
        Push a submodule to the given project.
        It is assumed that the project has been created.
        """
        src = project.replace(".git", "")
        repo_src = self.src.join(src)
        git = qisrc.git.Git(repo_src.strpath)
        if git.get_current_branch() != branch:
            git.checkout("--force", "-B", branch)
        if not fast_forward:
            git.reset("--hard", "HEAD~1")

        to_write = repo_src.join(destination_dir)
        if to_write.exists():
            raise RuntimeError("path %s already exists" % destination_dir)

        if not message:
            message = "Add submodule %s" % destination_dir

        git.call("submodule", "add", submodule_url, destination_dir)
        git.add(destination_dir)
        git.commit("--message", message)
        if fast_forward:
            git.push("origin", "%s:%s" % (branch, branch))
        else:
            git.push("origin", "--force", "%s:%s" % (branch, branch))
开发者ID:aldebaran,项目名称:qibuild,代码行数:29,代码来源:conftest.py

示例9: test_safe_checkout

def test_safe_checkout(cd_to_tmpdir, git_server):
    git_server.create_repo("foo.git")
    git = TestGit()
    git.clone(git_server.srv.join("foo.git").strpath)
    ok, mess = git.safe_checkout("devel", "origin")
    assert git.get_current_branch() == "devel"
    assert ok
开发者ID:Phlogistique,项目名称:qibuild,代码行数:7,代码来源:test_git.py

示例10: diff_worktree

def diff_worktree(git_worktree, git_projects, branch, cmd=None):
    """ Run  `git <cmd> local_branch..remote_branch` for every project

    """
    if not cmd:
        cmd = ["log"]
    remote_projects = git_worktree.get_projects_on_branch(branch)
    for git_project in git_projects:
        remote_project = remote_projects.get(git_project.src)
        if not remote_project:
            continue
        git = qisrc.git.Git(git_project.path)
        local_branch = git.get_current_branch()
        remote_branch = remote_project.default_branch.name
        remote_ref = "%s/%s" % (remote_project.default_remote.name, remote_branch)
        rc, out = git.call("merge-base", local_branch, remote_ref, raises=False)
        if rc != 0:
            continue
        merge_base = out.strip()
        full_cmd = cmd + ["%s..%s" % (merge_base, local_branch)]

        color = ui.config_color(sys.stdout)
        if color:
            full_cmd.append("--color=always")
        rc, out = git.call(*full_cmd, raises=False)
        if rc != 0:
            continue
        if not out:
            continue
        ui.info(ui.bold, git_project.src)
        ui.info(ui.bold, "-" * len(git_project.src))
        ui.info(out)
        ui.info()
开发者ID:Grimy,项目名称:qibuild,代码行数:33,代码来源:diff.py

示例11: test_switching_from_fixed_ref_to_branch_local_changes

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"
开发者ID:aldebaran,项目名称:qibuild,代码行数:28,代码来源:test_qisrc_sync.py

示例12: check_state

def check_state(project, untracked):
    """ Check and register the state of a project. """
    state_project = ProjectState(project)
    git = qisrc.git.Git(project.path)
    if not git.is_valid():
        state_project.valid = False
        return state_project
    state_project.clean = git.is_clean(untracked=untracked)
    if project.fixed_ref:
        state_project.ahead, state_project.behind = stat_fixed_ref(git, project.fixed_ref)
        state_project.fixed_ref = project.fixed_ref
        _set_status(git, state_project, untracked=untracked)
        return state_project
    state_project.current_branch = git.get_current_branch()
    state_project.tracking = git.get_tracking_branch()
    if project.default_remote and project.default_branch:
        state_project.manifest_branch = "%s/%s" % (project.default_remote.name, project.default_branch.name)
    if state_project.current_branch is None:
        state_project.not_on_a_branch = True
        return state_project
    if project.default_branch:
        if state_project.current_branch != project.default_branch.name:
            state_project.incorrect_proj = True
    (state_project.ahead, state_project.behind) = stat_tracking_remote(
        git,
        state_project.current_branch,
        state_project.tracking)
    if state_project.incorrect_proj:
        (state_project.ahead_manifest, state_project.behind_manifest) = stat_tracking_remote(
            git, state_project.current_branch, "%s/%s" % (
                project.default_remote.name, project.default_branch.name))
    _set_status(git, state_project, untracked=untracked)
    return state_project
开发者ID:aldebaran,项目名称:qibuild,代码行数:33,代码来源:status.py

示例13: do

def do(args):
    """ Main entry point """
    git_worktree = qisrc.parsers.get_git_worktree(args)
    git_project = qisrc.parsers.get_one_git_project(git_worktree, args)
    git = qisrc.git.Git(git_project.path)
    current_branch = git.get_current_branch()
    if not current_branch:
        ui.error("Not currently on any branch")
        sys.exit(2)
    if git_project.review:
        maintainers = qisrc.maintainers.get(git_project, warn_if_none=True)
        reviewers = [x['email'] for x in maintainers]
        reviewers.extend(args.reviewers or list())
        # Prefer gerrit logins or groups instead of e-mails
        reviewers = [x.split("@")[0] for x in reviewers]
        qisrc.review.push(git_project, current_branch,
                          bypass_review=(not args.review),
                          dry_run=args.dry_run, reviewers=reviewers,
                          topic=args.topic)
    else:
        if args.dry_run:
            git.push("-n")
        else:
            if args.review and not args.yes:
                mess = """\
The project is not under code review.
Are you sure you want to run `git push` ?
This action cannot be undone\
"""
                answer = qisys.interact.ask_yes_no(mess, default=False)
                if answer:
                    git.push()
            else:
                git.push()
开发者ID:aldebaran,项目名称:qibuild,代码行数:34,代码来源:push.py

示例14: test_wrong_branch_unstaged

    def test_wrong_branch_unstaged(self):
        bar_url = create_git_repo(self.tmp, "bar")
        work = os.path.join(self.tmp, "work")
        qibuild.sh.mkdir(work)
        bar_src = os.path.join(work, "bar")
        git = qisrc.git.Git(bar_src)
        git.clone(bar_url)

        # Checkout a 'next' branch with unstaged changes
        git.checkout("-b", "next")
        write_readme(bar_src, "bar on next\n")
        push_readme_v2(self.tmp, "bar", "master")

        err = git.update_branch("master", "origin")
        self.assertFalse(err)

        # Check we are still on next with our
        # unstaged changes back
        self.assertEqual(git.get_current_branch(), "next")
        readme = read_readme(bar_src)
        self.assertEqual(readme, "bar on next\n")

        # Check that master is up to date
        git.checkout("-f", "master")
        readme = read_readme(bar_src)
        self.assertEqual(readme, "bar v2 on master\n")
开发者ID:sanyaade-research-hub,项目名称:qibuild,代码行数:26,代码来源:test_git.py

示例15: check_state

def check_state(project, untracked):
    """Check and register the state of a project."""
    state_project = ProjectState(project)

    git = qisrc.git.Git(project.path)

    if not git.is_valid():
        state_project.valid = False
        return state_project

    state_project.clean = git.is_clean(untracked = untracked)
    state_project.current_branch = git.get_current_branch()
    state_project.tracking = git.get_tracking_branch()

    #clean worktree, but is the current branch sync with the remote one?
    if state_project.clean:
        if state_project.current_branch is None:
            state_project.not_on_a_branch = True
            return state_project

        if state_project.current_branch != project.branch:
            state_project.incorrect_proj = True

        (state_project.ahead, state_project.behind) = stat_tracking_remote(git,
                state_project.current_branch, state_project.tracking)

    if not state_project.sync_and_clean:
        out = git.get_status(untracked)
        if out is not None:
            state_project.status = [ x[:3]
                    for x in out.splitlines() if len(x.strip()) > 0 ]

    return state_project
开发者ID:bithium,项目名称:qibuild,代码行数:33,代码来源:status.py


注:本文中的qisrc.git.get_current_branch函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。