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


Python git.Git类代码示例

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


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

示例1: remote_repo_creator

        def remote_repo_creator(self):
            rw_daemon_repo_dir = tempfile.mktemp(prefix="daemon_repo-%s-" % func.__name__)
            rw_repo_dir = tempfile.mktemp(prefix="daemon_cloned_repo-%s-" % func.__name__)

            rw_daemon_repo = self.rorepo.clone(rw_daemon_repo_dir, shared=True, bare=True)
            # recursive alternates info ?
            rw_repo = rw_daemon_repo.clone(rw_repo_dir, shared=True, bare=False, n=True)
            try:
                rw_repo.head.commit = working_tree_ref
                rw_repo.head.reference.checkout()

                # prepare for git-daemon
                rw_daemon_repo.daemon_export = True

                # this thing is just annoying !
                with rw_daemon_repo.config_writer() as crw:
                    section = "daemon"
                    try:
                        crw.add_section(section)
                    except Exception:
                        pass
                    crw.set(section, "receivepack", True)

                # Initialize the remote - first do it as local remote and pull, then
                # we change the url to point to the daemon.
                d_remote = Remote.create(rw_repo, "daemon_origin", rw_daemon_repo_dir)
                d_remote.fetch()

                base_daemon_path, rel_repo_dir = osp.split(rw_daemon_repo_dir)

                remote_repo_url = Git.polish_url("git://localhost:%s/%s" % (GIT_DAEMON_PORT, rel_repo_dir))
                with d_remote.config_writer as cw:
                    cw.set('url', remote_repo_url)

                with git_daemon_launched(Git.polish_url(base_daemon_path, is_cygwin=False),  # No daemon in Cygwin.
                                         '127.0.0.1',
                                         GIT_DAEMON_PORT):
                    # Try listing remotes, to diagnose whether the daemon is up.
                    rw_repo.git.ls_remote(d_remote)

                    with cwd(rw_repo.working_dir):
                        try:
                            return func(self, rw_repo, rw_daemon_repo)
                        except:
                            log.info("Keeping repos after failure: \n  rw_repo_dir: %s \n  rw_daemon_repo_dir: %s",
                                     rw_repo_dir, rw_daemon_repo_dir)
                            rw_repo_dir = rw_daemon_repo_dir = None
                            raise

            finally:
                rw_repo.git.clear_cache()
                rw_daemon_repo.git.clear_cache()
                del rw_repo
                del rw_daemon_repo
                import gc
                gc.collect()
                if rw_repo_dir:
                    rmtree(rw_repo_dir)
                if rw_daemon_repo_dir:
                    rmtree(rw_daemon_repo_dir)
开发者ID:andy-maier,项目名称:GitPython,代码行数:60,代码来源:helper.py

示例2: full_remote

 def full_remote(self):
     # alextodo. wrap the calls to git commit
     repo = Git(self.path)
     cmd = ['git', 'remote', '-v']
     remote = repo.execute(cmd).split('(fetch)')[0]
     remote = remote or ''
     return remote.strip()
开发者ID:Doula,项目名称:Bambino,代码行数:7,代码来源:appenv.py

示例3: build_command

def build_command(config_file, strict, site_dir, tags, default, latest):
    """Build the MkDocs documentation"""

    cli.configure_logging(level=logging.INFO)

    g = Git()
    tags = tags or g.tag().splitlines()

    log.info("Building %s to /", default)
    g.checkout(default)
    _build(_load_config(config_file, strict, site_dir), default, tags)

    log.info("Building %s to /latest", latest)
    g.checkout(default)
    _build(_load_config(config_file, strict, site_dir), latest, tags, 'latest')

    for tag in sorted(tags):

        g.checkout(tag)

        if not os.path.exists("mkdocs.yml"):
            log.warning("Unable to build %s, as no mkdocs.yml was found", tag)
            continue

        site_dir = "v{0}".format(tag)
        log.info("Building %s to /%s", tag, site_dir)
        _build(_load_config(config_file, strict, site_dir), tag, tags, site_dir)

    g.checkout('master')
开发者ID:d0ugal,项目名称:mkdocs-versioned,代码行数:29,代码来源:cli.py

示例4: processCommitHook

    def processCommitHook(self, req):
        self.env.log.debug("processCommitHook")
        status = self.closestatus
        if not status:
            status = 'closed'

        if self.autofetch:
            repodir = RepositoryManager(self.env).repository_dir
            if not os.path.isabs(repodir):
                repodir = os.path.join(self.env.path, repodir)
            # TODO: This was the previous code, the repo options is probably unecessary now.
			# repodir = "%s/%s" % (self.repo, reponame)
            self.env.log.debug("Autofetching: %s" % repodir)
            repo = Git(repodir)

            try:
              self.env.log.debug("Fetching repo %s" % self.repo)
              repo.execute(['git', 'fetch'])
              try:
                self.env.log.debug("Resyncing local repo")
                self.env.get_repository('').sync()
              except:
                self.env.log.error("git sync failed!")
            except:
              self.env.log.error("git fetch failed!")

        data = req.args.get('payload')
         
        if data:
            jsondata = simplejson.loads(data)
            reponame = jsondata['repository']['name']

            for i in jsondata['commits']:
                self.hook.process(i, status, self.enable_revmap,reponame)
开发者ID:mickelangelo,项目名称:github-trac,代码行数:34,代码来源:github.py

示例5: pull

def pull(ctx):
    """Pull dotfile changes from GitHub"""

    VerboseLog('Running pull()', ctx)
    check_init(ctx)

    if not os.path.exists(trackfile_path()):
        click.secho('Pssst...you aren\'t tracking any files.\nTry running `dot track [filename]`\n.', fg='yellow', bold=True)
        ctx.abort()

    with open(trackfile_path(), 'r') as trf:
        for line in trf:
            line = line.rstrip()
            VerboseLog('Copying ' + dot_dir_path() + '/' + line + ' to ' + home() + '/' + line, ctx)
            if os.path.exists(dot_dir_path() + '/' + line):
                shutil.copyfile(dot_dir_path() + '/' + line, home() + '/' + line)

    VerboseLog('Creating Git class object, running git.pull()', ctx)
    git = Git(home(), Conf('options', 'gitname'), Conf('options', 'reponame'))
    return_code = git.pull()

    VerboseLog('git.pull() return code was ' + str(return_code), ctx)

    if return_code == 0:
        click.secho('\ndotfiles pulled.\n', fg='green')
    else:
        click.secho('\nThere was an error pulling the dotfiles.\n', fg='red')
开发者ID:kylefrost,项目名称:dot-cli,代码行数:27,代码来源:cli.py

示例6: processCommitHook

    def processCommitHook(self, req):
        self.env.log.debug("processCommitHook")
        status = self.closestatus
        if not status:
            status = 'closed'

        data = req.args.get('payload')
        branches = (parse_qs(req.query_string).get('branches') or self.branches).split(',')
        self.env.log.debug("Using branches: %s", branches)

        if data:
            jsondata = simplejson.loads(data)
            ref = jsondata['ref'].split('/')[-1]

            if ref in branches or 'all' in branches:
                for i in jsondata['commits']:
                    self.hook.process(i, status, jsondata)
            else:
                self.env.log.debug("Not running hook, ref %s is not in %s", ref, branches)

        if self.autofetch:
            repo = Git(self.repo)

            try:
              repo.execute(['git', 'fetch'])
            except:
              self.env.log.debug("git fetch failed!")
开发者ID:dnarvaez,项目名称:github-trac,代码行数:27,代码来源:github.py

示例7: register

    def register(self, stock):
        dir, branch = self._parse_stock(stock)
        if not isdir(dir):
            raise Error("not a directory `%s'" % dir)

        try:
            git = Git(dir)
        except Git.Error:
            git = None

        if (not git and branch) or (git and branch and not git.show_ref(branch)):
            raise Error("no such branch `%s' at `%s'" % (branch, dir))

        if git and not branch:
            branch = basename(git.symbolic_ref("HEAD"))

        stock_name = basename(abspath(dir))
        if branch:
            stock_name += "#" + branch

        if self.stocks.has_key(stock_name):
            raise Error("stock already registered under name `%s'" % stock_name)

        stock_path = join(self.path, stock_name)
        Stock.create(stock_path, dir)
        self._load_stock(stock_path)
开发者ID:qrntz,项目名称:pool,代码行数:26,代码来源:pool.py

示例8: push

def push(ctx):
    """Push dotfile changes to GitHub"""

    VerboseLog('Running push()', ctx)
    check_init(ctx)

    if not os.path.exists(trackfile_path()):
        VerboseLog('.trackfile does not exist.', ctx)
        click.secho('Pssst...you aren\'t tracking any files.\nTry running `dot track [filename]`\n.', fg='yellow', bold=True)
        ctx.abort()

    with open(trackfile_path(), 'r') as trf:
        for line in trf:
            line = line.rstrip()
            VerboseLog('Copying ' + line + ' to ' + dot_dir_path() + '/' + line, ctx)
            if os.path.exists(home() + '/' + line):
                shutil.copyfile(home() + '/' + line, dot_dir_path() + '/' + line)

    VerboseLog('Creating Git class object, running git.push()', ctx)
    git = Git(home(), Conf('options', 'gitname'), Conf('options', 'reponame'))
    return_code = git.push(Conf('options', 'time'))

    VerboseLog('git.push() return codes were ' +
                str(return_code[0]) + ' ' + 
                str(return_code[1]) + ' ' + 
                str(return_code[2]), ctx)

    if return_code[1] != 0 and return_code[2] == 0:
        click.echo('No dotfile changes to push.')
    elif return_code[2] != 0:
        click.secho('\nThere was a problem pushing the changes.\n', fg='red')
    else:
        click.secho('\ndotfiles pushed.\n', fg='green')
开发者ID:kylefrost,项目名称:dot-cli,代码行数:33,代码来源:cli.py

示例9: branches

def branches():
    g = Git(PROJECT_DIR)
    send('重新获取远程分支中.....')
    g.fetch(REMOTE_NAME)
    send('获取成功')
    branch_names = g.branch('-a').split('\n')
    return jsonify(branch_names)
开发者ID:barrysfinalhome,项目名称:pythonStudy,代码行数:7,代码来源:deploy_server.py

示例10: previous

def previous(rel_ver):
    """
    Given a release version, find the previous version based on the latest Git
    tag that is strictly a lower version than the given release version.
    """
    if DEBUG:
        print 'Calculating previous release version (option -p was specified).'
    version_loose = LooseVersion('0.0.0')
    rel_ver_loose = LooseVersion(rel_ver)
    gexc = Git('.')
    tags = gexc.execute(['git', 'tag',
                         '--list', '1.*',
                         '--sort', '-version:refname'])
    for tag in tags.splitlines():
        previous_tag_match = PREVIOUS_TAG_RE.match(tag)
        if previous_tag_match:
            version_new = {}
            version_new['major'] = int(previous_tag_match.group('vermaj'))
            version_new['minor'] = int(previous_tag_match.group('vermin'))
            version_new['patch'] = int(previous_tag_match.group('verpatch'))
            new_version_loose = LooseVersion(str(version_new['major']) + '.' +
                                             str(version_new['minor']) + '.' +
                                             str(version_new['patch']))
            if new_version_loose < rel_ver_loose:
                version_loose = new_version_loose
                if DEBUG:
                    print 'Found new best version "' + str(version_loose) \
                            + '" from tag "' + tag + '"'
                return str(version_loose)

    return str(version_loose)
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:31,代码来源:calc_release_version.py

示例11: watch

def watch(build_queue):
    while True:
        debug.set_prefix("repository_watcher")
        debug.message("Retrieving projects")
        try:
            projects = Api.get_projects()

            for project in projects:
                debug.message("Check repository status for project %s" % project["Name"])
                repository = Git(get_path(project), get_origin_url(project))
                commit_count = handle_incoming_commits(repository.check_for_new_commits_on_origin(), project,
                                                       repository, build_queue)
                if commit_count > 0:
                    repository.merge_origin()

                # Add <initial_nr_commits> commits if this is a new repository
                if project["Commits"] is None or len(project["Commits"]) == 0:
                    handle_incoming_commits(
                        repository.get_commits(registry.config["repositories"]["initial_nr_commits"]), project,
                        repository, build_queue)

        except ValueError, e:
            debug.exception("Error retrieving projects", e)
        except GitError, e:
            debug.exception("Error with Git repository", e)
开发者ID:marijngiesen,项目名称:deploy,代码行数:25,代码来源:repository.py

示例12: merged_refs

    def merged_refs(self, skip=[]):
        """
        Returns a list of remote refs that have been merged into the master
        branch.

        The "master" branch may have a different name than master. The value of
        ``self.master_name`` is used to determine what this name is.
        """
        origin = self._origin

        master = self._master_ref(origin)
        refs = self._filtered_remotes(
            origin, skip=['HEAD', self.master_branch] + skip)
        merged = []

        for ref in refs:
            upstream = '{origin}/{master}'.format(
                origin=origin.name, master=master.remote_head)
            head = '{origin}/{branch}'.format(
                origin=origin.name, branch=ref.remote_head)
            cmd = Git(self.repo.working_dir)
            # Drop to the git binary to do this, it's just easier to work with
            # at this level.
            (retcode, stdout, stderr) = cmd.execute(
                ['git', 'cherry', upstream, head],
                with_extended_output=True, with_exceptions=False)
            if retcode == 0 and not stdout:
                # This means there are no commits in the branch that are not
                # also in the master branch. This is ready to be deleted.
                merged.append(ref)

        return merged
开发者ID:Mondego,项目名称:pyreco,代码行数:32,代码来源:allPythonContent.py

示例13: prepare_repository

def prepare_repository(project):
    debug.message("Checkout commit %s" % project["commit"], indent=1)

    repo = Git(repository.get_path(project), repository.get_origin_url(project))

    # Check out the correct commit and create a reference to it (deployed)
    repo.checkout_commit(project["commit"])
开发者ID:marijngiesen,项目名称:deploy,代码行数:7,代码来源:buildqueue.py

示例14: processCommitHook

    def processCommitHook(self, req):
        self.env.log.debug("processCommitHook")
        status = self.closestatus
        if not status:
            status = 'closed'
	
        data = req.args.get('payload')
	jsondata = simplejson.loads(data)
		
	repoName = jsondata['repository']['name']

        if self.autofetch:
	    if data:
	    	jsondata = simplejson.loads(data)
		self.env.log.debug(jsondata['repository']['name']);
	        repo = Git(self.gitreposdir+repoName+"/.git")

            try:
              self.env.log.debug("Fetching repo %s" % self.repo)
              repo.execute(['git', 'fetch'])
              try:
                self.env.log.debug("Resyncing local repo")
                self.env.get_repository(repoName).sync()
              except:
                self.env.log.error("git sync failed!")
            except:
              self.env.log.error("git fetch failed!")

        jsondata = simplejson.loads(data)

         
        if jsondata:
            if jsondata['ref'] == "refs/heads/master" or re.search('-stable$', jsondata['ref']):
                for i in jsondata['commits']:
                    self.hook.process(i, status)
开发者ID:toutantic,项目名称:github-trac,代码行数:35,代码来源:github.py

示例15: post

 def post(self, project_name):
     try:
         project = Projects(project_name)
         git = Git(project)
         git.clear_repo()
         self.write(cyclone.escape.json_encode({"status": "ok"}))
     except Exception, e:
         self.write(cyclone.escape.json_encode({"status": "fail", "error": str(e)}))
开发者ID:rsampaio,项目名称:bricklayer,代码行数:8,代码来源:rest.py


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