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


Python sh.git函数代码示例

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


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

示例1: set_remote_url

def set_remote_url(git_dir, url):
    try:
        git('-C', git_dir, 'remote', 'set-url', 'origin', url)
    except ErrorReturnCode as e:
        return failed_util_call_results(e)
    else:
        return succeeded_util_call_results(None) 
开发者ID:MyPureCloud,项目名称:translation-process-automation,代码行数:7,代码来源:commands.py

示例2: pull

    def pull(self, remote, env={}, branch=None):
        """
        Pull a branch from a given remote

        Given a remote, env and branch, pull branch
        from remote and add the environment variables
        in the env dict to the environment of the
        "git pull" command.

        If no branch is given, the current branch
        will be updated.
        """
        if branch:
            branch_to_pull = branch
        else:
            branch_to_pull = self.current_branch()

        # if there is no PKEY, we don't need to override env
        # We are explicit about what we are pushing, since the default behavior
        # is different in different versions of Git and/or by configuration
        if env["PKEY"]:
            new_env = os.environ.copy()
            new_env.update(env)
            git(self.gitdir, self.gitwd, "pull", remote, "{}:{}".format(branch_to_pull,branch_to_pull), _env=new_env)
        else:
            git(self.gitdir, self.gitwd, "pull", remote, "{}:{}".format(branch_to_pull,branch_to_pull))

        new_sha      = git(self.gitdir, self.gitwd, "rev-parse","HEAD")
        return new_sha.strip()
开发者ID:OpenTreeOfLife,项目名称:phylesystem-api,代码行数:29,代码来源:gitdata.py

示例3: branch_exists

 def branch_exists(self, branch):
     """Returns true or false depending on if a branch exists"""
     try:
         git(self.gitdir, self.gitwd, "rev-parse", branch)
     except sh.ErrorReturnCode:
         return False
     return True
开发者ID:OpenTreeOfLife,项目名称:peyotl,代码行数:7,代码来源:git_action.py

示例4: setUp

 def setUp(self):
     super(TestServerOk, self).setUp()
     self.dir = tempfile.mkdtemp()
     sh.cd(self.dir)
     sh.git.init()
     sh.git('config', 'user.name', '"Guido"')
     sh.git('config', 'user.email', '"[email protected]"')
     sh.touch('README')
     sh.git.add('.')
     sh.git.commit('-am', 'first commit')
     sh.git.tag('-a', 'jenkins-release-1', '-m', 'Release 1')
     sh.touch('file1')
     sh.git.add('.')
     sh.git.commit('-am', 'second commit #777 #123')
     sh.git.tag('-a', 'jenkins-release-2', '-m', 'Release 2', _env={"GIT_COMMITTER_DATE": "2006-04-07T22:13:13"})
     sh.touch('file2')
     sh.git.add('.')
     sh.git.commit('-am', '#67 third commit')
     sh.git.tag('-a', 'jenkins-release-3', '-m', 'Release 3')
     self.prepare_client()
     self.valid_data = {
         'build_number': '42',
         'build_tag': 'jenkins-release-2',
         'previous_tag': 'jenkins-release-1',
         'job_url': 'http://jenkins_url/jobs/2/',
         'repo': self.dir,
         'instance': 'TestServer',
     }
开发者ID:futurecolors,项目名称:redmine-releasedate,代码行数:28,代码来源:test_releasedate.py

示例5: create_or_checkout_branch

    def create_or_checkout_branch(self, gh_user, study_id, parent_sha, force_branch_name=False):
        if force_branch_name:
            #@TEMP deprecated
            branch = "{ghu}_study_{rid}".format(ghu=gh_user, rid=study_id)
            if not self.branch_exists(branch):
                try:
                    git(self.gitdir, self.gitwd, "branch", branch, parent_sha)
                    _LOG.debug('Created branch "{b}" with parent "{a}"'.format(b=branch, a=parent_sha))
                except:
                    raise ValueError('parent sha not in git repo')
            self.checkout(branch)
            return branch

        frag = "{ghu}_study_{rid}_".format(ghu=gh_user, rid=study_id)
        branch = self._find_head_sha(frag, parent_sha)
        _LOG.debug('Found branch "{b}" for sha "{s}"'.format(b=branch, s=parent_sha))
        if not branch:
            branch = frag + '0'
            i = 1
            while self.branch_exists(branch):
                branch = frag + str(i)
                i += 1
            _LOG.debug('lowest non existing branch =' + branch)
            try:
                git(self.gitdir, self.gitwd, "branch", branch, parent_sha)
                _LOG.debug('Created branch "{b}" with parent "{a}"'.format(b=branch, a=parent_sha))
            except:
                raise ValueError('parent sha not in git repo')
        self.checkout(branch)
        _LOG.debug('Checked out branch "{b}"'.format(b=branch))
        return branch
开发者ID:rvosa,项目名称:peyotl,代码行数:31,代码来源:git_actions.py

示例6: _create_simple_commit

 def _create_simple_commit(self, message):
     """ Creates a simple commit with an empty test file.
         :param message: Commit message for the commit. """
     test_filename = "test-file-" + str(uuid4())
     touch(test_filename, _cwd=self.tmp_git_repo)
     git("add", test_filename, _cwd=self.tmp_git_repo)
     git("commit", "-m", message, _cwd=self.tmp_git_repo)
开发者ID:Hawatel,项目名称:gitlint,代码行数:7,代码来源:integration_test.py

示例7: isRepo

def isRepo():
    """ Returns if the cwd is a git repo """
    try:
        git("rev-parse", "--is-inside-work-tree")
        return 1
    except:
        return 0
开发者ID:Alpha59,项目名称:GitHub,代码行数:7,代码来源:gitCommands.py

示例8: grab_changesets

    def grab_changesets(self, path, url, changesets):
        """
        Inherited method :func:`~DepotOperations.grab_changesets`
        """
        logger.debug('Grabbing changesets from %s to %s' % (url, path))
        # Force handling it as a bare repository so even current branch can be
        # overwritten by fetch
        git_path = os.path.join(
            path,
            sh.git('rev-parse', '--git-dir', _cwd=path).strip())
        logger.debug("Executing git -c core.bare=true fetch " + url + " +refs/*:refs/* on " + git_path)
        output = sh.git('-c', 'core.bare=true', 'fetch',
                        url,
                        '+refs/*:refs/*',
                        _cwd=git_path,
                        _err_to_out=True)
        logger.debug("Output:\n%s" % output)
        if sh.git('rev-parse', '--is-bare-repository', _cwd=path).strip() == 'false':
            self._clear_working_copy(path)
        self._save_state(path)

        for c in changesets:
            try:
                sh.git('log', '-1', c, _cwd=path, _tty_out=False)
            except sh.ErrorReturnCode as e:
                logger.debug('Error checking changeset %s: %s', c, e)
                return False
        return True
开发者ID:mrodm,项目名称:python-repoman,代码行数:28,代码来源:depot_operations.py

示例9: fetch

    def fetch(self):
        LOG.debug('Fetching repo uri %s' % self.repo['uri'])

        if os.path.exists(self.folder):
            os.chdir(self.folder)
            uri = str(sh.git('config', '--get', 'remote.origin.url')).strip()
            if uri != self.repo['uri']:
                LOG.debug('Repo uri %(uri)s differs from cloned %(old)s',
                          {'uri': self.repo['uri'], 'old': uri})
                os.chdir('..')
                shutil.rmtree(self.folder)

        if not os.path.exists(self.folder):
            os.chdir(self.sources_root)
            try:
                sh.git('clone', self.repo['uri'])
            except sh.ErrorReturnCode as e:
                LOG.error('Unable to clone git repo %s. Ignore it',
                          self.repo['uri'])
                LOG.exception(e)
            os.chdir(self.folder)
        else:
            os.chdir(self.folder)
            try:
                sh.git('fetch')
            except sh.ErrorReturnCode as e:
                LOG.error('Unable to fetch git repo %s. Ignore it',
                          self.repo['uri'])
                LOG.exception(e)

        self.get_release_index()
开发者ID:Mingkii,项目名称:stackalytics,代码行数:31,代码来源:vcs.py

示例10: skipUnlessHasGit

def skipUnlessHasGit(obj):
    # Test git presence
    try:
        sh.git(version=True, _out='/dev/null')
        return lambda func: func
    except sh.CommandNotFound:
        return unittest.skip("Git is not installed")
开发者ID:affinitic,项目名称:BitBucket-api,代码行数:7,代码来源:repository.py

示例11: test_write

    def test_write(self):
        def cleanup_write():
            git.checkout("master")
            git.branch("-D","johndoe_study_9998")
            git.branch("-D","johndoe_study_9999")

        self.addCleanup(cleanup_write)

        author   = "John Doe <[email protected]>"
        content  = '{"foo":"bar"}'
        study_id = 9999
        branch   = "johndoe_study_%s" % study_id
        new_sha  = self.gd.write_study(study_id,content,branch,author)
        self.assertTrue( new_sha != "", "new_sha is non-empty")
        self.assertEqual(len(new_sha), 40, "SHA is 40 chars")
        self.assertEqual( content, self.gd.fetch_study(9999), "correct content found via fetch_study")

        author   = "John Doe <[email protected]>"
        content  = '{"foo2":"bar2"}'
        study_id = 9998
        branch   = "johndoe_study_%s" % study_id
        new_sha  = self.gd.write_study(study_id,content,branch,author)

        merge_base_sha1 = git("merge-base","johndoe_study_9999","johndoe_study_9998").strip()

        master_sha1     = git("rev-parse","master").strip()

        self.assertEqual(master_sha1, merge_base_sha1, "Verify that writing new study branches from master and not the current branch")
开发者ID:infosucker,项目名称:api.opentreeoflife.org,代码行数:28,代码来源:test_gitdata.py

示例12: test_git_dir_from_subdir

    def test_git_dir_from_subdir(self):
        sh.git('init')
        sh.mkdir('foo')
        expected = os.path.join(os.getcwd(), '.git')

        sh.cd('foo')
        self.assertEqual(expected, git_dir())
开发者ID:themalkolm,项目名称:git-boots,代码行数:7,代码来源:test_git_dir.py

示例13: main

def main():
    if len(sys.argv) == 2:
        sh.cd(sys.argv[1])
        print(sh.git("status"))
        print("(Y/n): Are you sure you want to reset this directory?")
        temp = str(input("Local changes will be deleted: "))
        if temp=="y" or temp =="Y":
            print(sh.git.reset("--hard", "HEAD"))
            print(sh.git.clean("-f"))
            print(sh.git.pull)
            print(sh.git("status"))
        else:
            sys.exit(0)

    else:
        print(sh.git("status"))
        print("(Y/n): Are you sure you want to reset this directory?")
        temp = str(input("Local changes will be deleted: "))
        if temp=="y" or temp =="Y":
            print(sh.git.reset("--hard", "HEAD"))
            print(sh.git.clean("-f"))
            print(sh.git.pull)
            print(sh.git("status"))
        else:
            sys.exit(0)
开发者ID:michaelrinos,项目名称:Python-Personal,代码行数:25,代码来源:BashScript.py

示例14: clone

def clone(root, uniqname, project):
	into='/tmp/'+root
	mkdir('-p', into)
	url='[email protected]:' + uniqname + '/' + project
	to_path=into + '/' + uniqname

	if 'rerun' in sys.argv:
		if os.path.exists(to_path):
			print('cached {}'.format(to_path))
			repo = git.Repo(to_path)
			return repo, to_path

	print('clone {}/{}'.format(uniqname, project))
	try:
		repo = git.Repo.clone_from(
				url=url,
				to_path=to_path,
				)
		return repo, to_path
	except:
		# Fall back to sh path to grab the error
		try:
			sh.git('clone', url, to_path)
		except sh.ErrorReturnCode as e:
			if 'Connection closed by remote host' in e.stderr.decode('utf8'):
				# gitlab rate-limited us
				time.sleep(3)
				return clone(root, uniqname, project)
			raise

		# Since we're hammering the gitlab server, rarely the first will
		# timeout, but this second chance will succeed. Create a repo object
		# from the path in that case.
		repo = git.Repo(to_path)
		return repo, to_path
开发者ID:c4cs,项目名称:assignments,代码行数:35,代码来源:grade.py

示例15: give_user_ztanesh

def give_user_ztanesh(unix_user):
    """
    Make sure our UNIX user runs ZtaneSH shell it is more productive to work with Plone sites.

    https://github.com/miohtama/ztanesh
    """
    from sh import git
    from sh import chsh

    home = get_unix_user_home(unix_user)

    # Install ZtaneSH
    if not os.path.exists("%s/tools" % home):

        print "Installing ZtaneSH for user %s" % unix_user

        with sudo(i=True, u=unix_user, _with=True):
            cd(home)
            git("clone", "git://github.com/miohtama/ztanesh.git", "tools")
            setup = "%s/tools/zsh-scripts/setup.zsh" % home
            run = Command(setup)
            run()

    # Set user default shell
    with sudo:
        chsh("-s", "/bin/zsh", unix_user)
开发者ID:miohtama,项目名称:senorita.plonetool,代码行数:26,代码来源:main.py


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