• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python git.checkout函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: cleanup_merge

        def cleanup_merge():
            git.checkout("master")
            # if something failed, the branch might still exist
            if self.gd.branch_exists("to_merge_1"):
                git.branch("-D", "to_merge_1")

            git.branch("-D", "base_branch")
开发者ID:infosucker,项目名称:api.opentreeoflife.org,代码行数:7,代码来源:test_gitdata.py


示例2: test_merge

    def test_merge(self):
        def cleanup_merge():
            git.checkout("master")
            # if something failed, the branch might still exist
            if self.gd.branch_exists("to_merge_1"):
                git.branch("-D", "to_merge_1")

            git.branch("-D", "base_branch")

        self.addCleanup(cleanup_merge)

        git.checkout("-b", "to_merge_1")
        git.checkout("-b", "base_branch")

        file = open("foo.txt", "w")
        file.write("ABC\n")
        file.close()

        git.add("foo.txt")

        git.commit("-m","Test commit")

        new_sha = self.gd.merge("to_merge_1", "base_branch")

        self.assertTrue( new_sha != "", "new_sha=%s is non-empty" % new_sha)
        self.assertEqual(len(new_sha), 40, "SHA is 40 chars")

        self.assertTrue(True, "Merge succeeded")
开发者ID:infosucker,项目名称:api.opentreeoflife.org,代码行数:28,代码来源:test_gitdata.py


示例3: _create_git

    def _create_git(self):
        """create a book from a git repo"""

        if not os.path.exists(self.path):
            LOG.info(("Creating book {0} from {1}, branch: {2}" +
                     "").format(self.path, self.git, self.branch))
            git.clone(self.git, self.path)
        else:
            LOG.info("Book {0} already exists".format(self.path))

        cwd = os.getcwd()
        os.chdir(self.path)

        if self.skiprepourlcheck:
            remote_match_found = False
            for remote in git("remote", "-v"):
                remote_parts = remote.split()

                if Url(remote_parts[1]) == Url(self.git):
                    remote_match_found = True

            if remote_match_found:
                LOG.debug('Found {0} in the list of remotes for {1}'.format(self.git, self.path))
            else:
                LOG.error('ERROR: {0} wasn\'t found in the list of remotes for {1}'.format(self.git, self.path))

        if not self._check_branch():
            LOG.info("Switching {0} to branch {1}".format(self.path,
                                                          self.branch))
            git.fetch
            git.checkout(self.branch)

        os.chdir(cwd)
开发者ID:gitshelf,项目名称:gitshelf,代码行数:33,代码来源:book.py


示例4: run

    def run(self):

        global _DEFAULT_PATH
        global _RESET_PATHS

        if 'path' in self.options:
            tut_path = self.options['path']
        elif _DEFAULT_PATH is not None:
            tut_path = _DEFAULT_PATH
        else:
            raise Exception("No tut path specified.")

        # paths are relative to the project root
        rel_path, tut_path = self.state.document.settings.env.relfn2path(
            tut_path)

        curdir = os.getcwd()
        os.chdir(tut_path)

        # if this is the first time visiting this repo
        if tut_path not in _RESET_PATHS:
            # record the current branch
            _RESET_PATHS[tut_path] = \
                git('name-rev', 'HEAD').strip().split()[-1]

        git.checkout(self.arguments[0].strip().lower())
        sphinx.pycode.ModuleAnalyzer.cache = {}

        os.chdir(curdir)

        return []
开发者ID:AnthonyTruchet,项目名称:tut,代码行数:31,代码来源:sphinx.py


示例5: create

def create(version_number):
    heading1("Creating new version based on Fedora " + version_number + "\n")

    # Update git and create new version.
    heading2("Updating master branch.")
    print(git.checkout("master"))
    print(git.pull())  # Bring branch current.

    heading2("Creating new branch")
    print(git.checkout("-b" + version_number))  # Create working branch.

    # Get kickstart files.
    heading2("Creating fedora-kickstarts directory\n")
    mkdir("-p", (base_dir + "/fedora-kickstarts/"))
    cd(base_dir + "/fedora-kickstarts/")

    heading2("Downloading Fedora kickstart files.")
    ks_base = "https://pagure.io/fedora-kickstarts/raw/f" \
              + version_number + "/f"

    for file in ks_files:
        file_path = ks_base + "/fedora-" + file

        print ("Downloading " + file_path)
        curl("-O", file_path)
开发者ID:RobbHendershot,项目名称:tananda-os-builder,代码行数:25,代码来源:tananda_os_builder.py


示例6: commit

    def commit(self, objects, message):
        # validate commit message
        if not message or not isinstance(message, basestring):
            raise ValueError("Commit message should not be empty or not string")

        env = os.environ.copy()
        env.update({
                'GIT_WORK_TREE': self.repo,
                'GIT_DIR': '%s/.git' % self.repo,
        })

        git.gc("--prune", _env=env)
        git.checkout("HEAD", _env=env)

        # pull and push from and to the remote
        git.pull("origin", "master", _env=env)

        for obj in objects:
            git.add("-A", obj, _env=env)

        try:
            git.commit("-m", message, _env=env)
        except Exception:
            pass

        git.push(_env=env)
开发者ID:Codevolve,项目名称:pyolite,代码行数:26,代码来源:git.py


示例7: newest_study_id

    def newest_study_id(self):
        "Return the numeric part of the newest study_id"
        os.chdir(self.repo)

        git.checkout("master")
        dirs = []
        # first we look for studies already in our master branch
        for f in os.listdir("study/"):
            if os.path.isdir("study/%s" % f):
                # ignore alphabetic prefix, o = created by opentree API
                if f[0].isalpha():
                    dirs.append(int(f[1:]))
                else:
                    dirs.append(int(f))

        # next we must look at local branch names for new studies
        # without --no-color we get terminal color codes in the branch output
        branches = git.branch("--no-color")
        branches = [ b.strip() for b in branches ]
        for b in branches:
            mo = re.match(".+_o(\d+)",b)
            if mo:
                dirs.append(int(mo.group(1)))

        dirs.sort()
        return dirs[-1]
开发者ID:infosucker,项目名称:api.opentreeoflife.org,代码行数:26,代码来源:gitdata.py


示例8: start

    def start(self, name, starting_point=None):
        """Start a new step (branch)."""

        # make sure this is not a known checkpoint
        if name in self.points():
            raise TutException("Duplicate checkpoint.")

        # make sure the repo is clean
        if self._repo_dirty():
            raise TutException("Dirty tree.")

        # create the new branch
        git.branch(name)

        if starting_point is None:
            args = ('-b', name)
        else:
            args = ('-b', name, starting_point, '--track')

        # add the branch to config
        config = self._config()
        points = config['points']
        if self.current():
            points.insert(points.index(self.current()) + 1, name)
        else:
            points.append(name)

        self._update_config(
            config,
            log='Adding new point %s' % name,
        )

        # checkout the new branch
        git.checkout(name)
开发者ID:austinvernsonger,项目名称:tut,代码行数:34,代码来源:model.py


示例9: publish_site

 def publish_site(self):
       tmp_branch = '__dynamo_deploy__'
       detached_branch = None
       
       git.checkout(self.target_branch)
       self._add_and_commit_site('dist')
       git.push('origin', self.target_branch)
       git.checkout('@{-1}')
开发者ID:Larusso,项目名称:xbmc-dynamo,代码行数:8,代码来源:publish.py


示例10: checkout

def checkout(branch):
    print "Checking out "+branch
    try:        
        git.checkout('-b',branch)
    except:
        # Branch already exists, check skip creation flag
        git.checkout(branch)
        pass
开发者ID:tim-kretschmer-c2fo,项目名称:ci-test,代码行数:8,代码来源:make_history.py


示例11: __init__

 def __init__(self, settings):
     self.settings = settings
     # Into the context
     if not os.path.exists(self.settings.local_dir):
         git.clone(self.settings.repo_url, self.settings.local_dir)
     cd(settings.local_dir)
     # Make sure checkout the right branch
     git.checkout(settings.branch)
     self.__current_commit = ""
开发者ID:WhiteIsClosing,项目名称:plib,代码行数:9,代码来源:ci.py


示例12: test_current_returns_none_on_unknown_branch

    def test_current_returns_none_on_unknown_branch(self):
        t = tut.model.Tut(self._testpath)
        t.init()
        t.start('step1')

        git.checkout('master')

        self.assertNotIn('master', t.points())
        self.assertEqual(t.current(), None)
开发者ID:austinvernsonger,项目名称:tut,代码行数:9,代码来源:test_model.py


示例13: install_addon

    def install_addon(self, addon):
        addonPath = os.path.join(self.get_addon_path(), addon.name)
        if os.path.isdir(addonPath):
            # Folder already exists
            if not os.path.isdir(os.path.join(addonPath, '.git')):
                raise Exception('WARNING',
                                'ALREADY_INSTALLED_UNLINKED',
                                'Addon %s is already installed, but it\'s state is unknown.\nPlease reinstall with:\n' % addon.name + note('ofx reinstall %s' % addon.name))
            else:
                os.chdir(addonPath)
                currentSha = sh.git('rev-parse', 'HEAD').rstrip()
                remoteSha = addon.latest_commit['sha']

                if addon.version is not None:
                    try:
                        git.checkout(addon.version)
                    except Exception:
                        raise Exception('ERROR',
                                        'UNKNOWN_VERSION',
                                        'No version named %s found for %s' % (addon.version, addon.name))

                    print ok() + addon.name + ": %s checked out" % addon.version
                else:
                    if currentSha == remoteSha:
                        raise Exception('OK',
                                        'ALREADY_INSTALLED',
                                        'Addon %s is already installed and up to date' % addon.name)
                    else:
                        raise Exception('WARNING',
                                        'ALREADY_INSTALLED_OUTDATED',
                                        'Addon %s is already installed but is not up to date. Consider running:\n' % addon.name + note("ofx update %s" % addon.name))
        else:
            print '>> Cloning %s' % addon.clone_url
            os.chdir(self.get_addon_path())
            git.clone(addon.clone_url)
            os.chdir(addonPath)

            sha = sh.git('rev-parse', 'HEAD').rstrip()
            if not sha:
                raise Exception('ERROR', 'CLONE_ERROR', "Something went wrong while cloning from "+addon.clone_url)
            else:
                print ok()+addon.name + ": Clone done"
                
                if addon.version is not None:
                    try:
                        git.checkout(addon.version)
                    except Exception:
                        raise Exception('ERROR',
                                        'UNKNOWN_VERSION',
                                        'No version named %s found for %s' % (addon.version, addon.name))

                    print ok() + addon.name + ": %s checked out" % addon.version

                self.install_dependencies(addon)
            return True
开发者ID:HalfdanJ,项目名称:ofx,代码行数:55,代码来源:ofx.py


示例14: cleanup

def cleanup(app, exception):

    global _RESET_PATHS

    curdir = os.getcwd()
    try:
        for path in _RESET_PATHS:
            os.chdir(path)
            git.checkout(_RESET_PATHS[path])
    finally:
        os.chdir(curdir)
开发者ID:austinvernsonger,项目名称:tut,代码行数:11,代码来源:sphinx.py


示例15: start

    def start(self, name):
        """Start a new step (branch)."""

        # make sure this is not a known checkpoint
        if name in self.points():
            raise TutException("Duplicate checkpoint.")

        # make sure the repo is clean
        if self._repo_dirty():
            raise TutException("Dirty tree.")

        git.checkout('-b', name)
开发者ID:AnthonyTruchet,项目名称:tut,代码行数:12,代码来源:model.py


示例16: edit

    def edit(self, name):
        """Start editing the checkpoint point_name."""

        # make sure this is a known checkpoint
        if name not in self.points():
            raise TutException("Unknown checkpoint.")

        # make sure the repo is clean
        if self._repo_dirty():
            raise TutException("Dirty tree.")

        git.checkout(name)
开发者ID:AnthonyTruchet,项目名称:tut,代码行数:12,代码来源:model.py


示例17: repository

def repository(namespace, name, branch='master'):
    '''Returns a repository'''
    with TemporaryDirectory() as download_path:
        old_directory = str(pwd()).strip()
        try:
            git.clone('https://github.com/{0}/{1}.git'.format(namespace, name), download_path)
            cd(download_path)
            git.fetch('origin', branch)
            git.checkout(branch)
            yield (download_path, git('rev-parse', 'HEAD'), redis.Dict(key="{0}.{1}".format(namespace, name)))
        except ErrorReturnCode_128:
            mkdir(download_path)
            yield (None, None, None)
        cd(old_directory)
开发者ID:timothycrosley,项目名称:simple_ci,代码行数:14,代码来源:simple_ci.py


示例18: test_merge_conflict

    def test_merge_conflict(self):
        def cleanup_merge_conflict():
            git.checkout("master")
            # if something failed, the branch might still exist
            if self.gd.branch_exists("to_merge_1"):
                git.branch("-D", "to_merge_1")

            if self.gd.branch_exists("to_merge_2"):
                git.branch("-D", "to_merge_2")

        self.addCleanup(cleanup_merge_conflict)

        git.checkout("master")
        git.checkout("-b", "to_merge_1")

        file = open("foo.txt", "w")
        file.write("ABC\n")
        file.close()

        git.add("foo.txt")
        git.commit("-m","Test commit")

        git.checkout("master")

        git.checkout("-b", "to_merge_2")

        file = open("foo.txt", "w")
        file.write("XYZ\n")
        file.close()

        git.add("foo.txt")
        git.commit("-m","Test commit")

        self.assertRaises(MergeException, lambda:  self.gd.merge("to_merge_1", "to_merge_2") )
开发者ID:infosucker,项目名称:api.opentreeoflife.org,代码行数:34,代码来源:test_gitdata.py


示例19: add_to_blacklist

    def add_to_blacklist(self, items_to_blacklist, username, code_permissions):
        # Check if we're on master
        if git("rev-parse", "--abbrev-ref", "HEAD").strip() != "master":
            return (False, "Not currently on master.")

        # Check that we're up-to-date with origin (GitHub)
        git.remote.update()
        if git("rev-parse", "refs/remotes/origin/master").strip() != git("rev-parse", "master").strip():
            return (False, "HEAD isn't at tip of origin's master branch")

        # Check that blacklisted_websites.txt isn't modified locally. That could get ugly fast
        if "blacklisted_websites.txt" in git.status():  # Also ugly
            return (False, "blacklisted_websites.txt modified locally. This is probably bad.")

        # Store current commit hash
        current_commit = git("rev-parse", "HEAD").strip()

        # Add items to file
        with open("blacklisted_websites.txt", "a+") as blacklisted_websites:
            last_character = blacklisted_websites.read()[-1:]
            if last_character != "\n":
                blacklisted_websites.write("\n")
            blacklisted_websites.write("\n".join(items_to_blacklist) + "\n")

        # Checkout a new branch (mostly unnecessary, but may help if we create PRs in the future
        branch = "auto-blacklist-{0}".format(str(time.time()))
        git.checkout("-b", branch)

        # Clear HEAD just in case
        git.reset("HEAD")

        git.add("blacklisted_websites.txt")
        git.commit("-m", "Auto blacklist of {0} by {1} --autopull".format(", ".join(items_to_blacklist), username))

        if code_permissions:
            git.checkout("master")
            git.merge(branch)
            git.push()
        else:
            git.push("origin", branch)
            git.checkout("master")

            if GlobalVars.github_username is None or GlobalVars.github_password is None:
                return (False, "tell someone to set a GH password")

            payload = {"title": "{0}: Blacklist {1}".format(username, ", ".join(items_to_blacklist)),
                       "body": "{0} requests blacklist of domains: \n\n - {1}".format(username, "\n - ".join(items_to_blacklist)),
                       "head": branch,
                       "base": "master"}
            response = requests.post("https://api.github.com/repos/Charcoal-SE/SmokeDetector/pulls", auth=HTTPBasicAuth(GlobalVars.github_username, GlobalVars.github_password), data=json.dumps(payload))
            print(response.json())
            return (True, "You don't have code privileges, but I've [created a pull request for you]({0}).".format(response.json()["html_url"]))

        git.checkout(current_commit)  # Return to old commit to await CI. This will make Smokey think it's in reverted mode if it restarts

        if not code_permissions:
            return (False, "Unable to perform action due to lack of code-level permissions. [Branch pushed](https://github.com/Charcoal-SE/SmokeDetector/tree/{0}), PR at your leisure.".format(branch))

        return (True, "Blacklisted {0} - the entry will be applied via autopull if CI succeeds.".format(", ".join(items_to_blacklist)))
开发者ID:tripleee,项目名称:SmokeDetector,代码行数:59,代码来源:gitmanager.py


示例20: setUp

  def setUp(self):
    super(TestFileResolve, self).setUp()

    # Generate a conflict
    git.checkout(b='branch')
    utils_lib.write_file(FP_IN_CONFLICT, contents='branch')
    utils_lib.write_file(DIR_FP_IN_CONFLICT, contents='branch')
    git.add(FP_IN_CONFLICT, DIR_FP_IN_CONFLICT)
    git.commit(FP_IN_CONFLICT, DIR_FP_IN_CONFLICT, m='branch')
    git.checkout('master')
    utils_lib.write_file(FP_IN_CONFLICT, contents='master')
    utils_lib.write_file(DIR_FP_IN_CONFLICT, contents='master')
    git.add(FP_IN_CONFLICT, DIR_FP_IN_CONFLICT)
    git.commit(FP_IN_CONFLICT, DIR_FP_IN_CONFLICT, m='master')
    git.merge('branch', _ok_code=[1])
开发者ID:imoapps,项目名称:gitless,代码行数:15,代码来源:test_core.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python git.commit函数代码示例发布时间:2022-05-27
下一篇:
Python git.add函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap