示例#1
0
def show(args):
  if args.branches:
    branches = git.branches(all=args.all)
    merged_branches = git.branches(merged_into=args.unmerged) if args.unmerged else []
    width = max(len(x) for x in branches)
    for branch in git.branches(all=args.all):
      if branch in merged_branches: continue
      try:
        line_endings = get_line_endings(git.get_file(branch, args.file))
      except git.DoesNotExist:
        continue
      if (not args.lf and not args.crlf) or (args.lf and line_endings == 'lf')\
          or (args.crlf and line_endings == 'crlf'):
        print('{} {}'.format(branch.ljust(width), line_endings.upper()))
  else:
    print(get_line_endings(git.get_file(args.at, args.file)).upper())
示例#2
0
文件: get.py 项目: brettviren/garpi
def get_git(scheme,url,target,overwrite,tag):
    import git

    if os.path.exists(target + '/.git'):
        if not overwrite: return
    else:
        if len(scheme) == 1: giturl = url
        else: giturl = url[4:]
        git.clone(giturl,target)

    fs.goto(target)
    git.fetch()
    out = git.branch()
    for line in out.split('\n'):
        if not line: continue
        if line[0] != '*': continue
        out = line.split()[1]
        break
    #print out,tag
    if out != tag:
        lbranches,rbranches = git.branches()
        if tag in lbranches:
            git.checkout(tag)
        else:
            # git 1.5 does not put remotes/ like 1.6 does
            from exception import CommandFailure
            try:
                git.checkout('origin/'+tag,tag)
            except CommandFailure:
                git.checkout('remotes/origin/'+tag,tag)
    git.pull()
    fs.goback()
    return
示例#3
0
文件: git_repo.py 项目: tf198/pycart
    def get_base_context(self, repo, sha, path):
        d = {}

        self.repo = self.get_repo(repo)

        try:
            if sha in self.repo:  # explicit sha
                d['ref_name'] = sha[:10]
                d['ref_link'] = sha
                self.sha = self.repo.get_object(sha)

            else:
                d['ref_name'] = d['ref_link'] = sha
                self.sha = git.get_branch(self.repo, sha)
        except KeyError:
            logger.exception("Failed to find sha: {0}".format(sha))
            raise web.notfound('Bad SHA: {0}'.format(sha))

        d['repo'] = repo
        d['sha'] = self.sha.id
        d['branches'] = git.branches(self.repo)
        d['tags'] = git.tags(self.repo)
        d['sha_type'] = self.sha_type

        d['path'] = path.strip('/')
        d['breadcrumbs'] = d['path'].split('/') if path else []

        return d
示例#4
0
文件: gaudi.py 项目: brettviren/garpi
    def _git_checkout(self,tag,pkg=""):
        import fs,git
        fs.goto(os.path.join(fs.projects(),'gaudi',pkg))

        lbranches,rbranches = git.branches()
        if tag in lbranches:
            git.checkout(tag)
        else:
            git.checkout('origin/'+tag,tag)

        fs.goback()
        return
示例#5
0
文件: merge_hd.py 项目: jhford/uplift
def merge(repo_dir, gaia_url, branch_to, branch_from):
    git.delete_gaia(repo_dir)
    t = util.time_start()
    if os.path.exists(repo_dir):
        print "Updating Gaia"
        git.update_gaia(repo_dir, gaia_url)
        print "Updated Gaia in %0.2f seconds" % util.time_end(t)
    else:
        print "Creating Gaia"
        git.create_gaia(repo_dir, gaia_url)  # This is sadly broken
        print "Created Gaia in %0.2f seconds" % util.time_end(t)

    print "Merging %s into branch %s" % (branch_from, branch_to)
    if not branch_to in git.branches(repo_dir):
        print >> sys.stderr, "Asking to merge into a branch that doesn't exist (%s)" % branch_to
        return None
    if not branch_from in git.branches(repo_dir):
        print >> sys.stderr, "Asking to merge from a branch that doesn't exist (%s)" % branch_from
        return None

    git.checkout(repo_dir, branch_to)
    start_commit = git.get_rev(repo_dir)
    git.merge(repo_dir, branch_from, strategy="recursive")
    end_commit = git.get_rev(repo_dir)
    print "Merge range is %s..%s" % (start_commit[:7], end_commit[:7])
    print git.log(repo_dir, "%s..%s" % (start_commit, end_commit), pretty="oneline")
    print "Dry Run push"
    git.push(repo_dir, remote="origin", branches=[branch_to], dry_run=True)
    info = git.push(repo_dir, remote="origin", branches=[branch_to])
    print "Would be pusing to %s" % info["url"]
    for branch in info["branches"].keys():
        s, e = info["branches"][branch]
        print "  %s: %s..%s" % (branch, s, e)
    if util.ask_yn("Push for realises?"):
        info = git.push(repo_dir, remote="origin", branches=[branch_to], dry_run=False)
        print "Pushed to %s" % info["url"]
        for branch in info["branches"].keys():
            s, e = info["branches"][branch]
            print "  %s: %s..%s" % (branch, s, e)
        comment(repo_dir, branch_to, "%s..%s" % (start_commit, end_commit))
示例#6
0
文件: merge_hd.py 项目: jhford/uplift
def comment(repo_dir, branch_to, commit_range, dry_run=False):
    all_commits = git.log(repo_dir, commit_range, pretty="%H").strip().split("\n")
    comments = {}
    commits_without_bugs = []

    assert branch_to in git.branches(repo_dir), "branch parameter must be a branch"

    i = 0
    for commit in all_commits:
        i += 1
        print "bug %d of %d" % (i, len(all_commits))
        bug_ids = guess_bug_id(repo_dir, commit)
        if bug_ids is None or len(bug_ids) == 0:
            commits_without_bugs.append(commit)
        else:
            for bug_id in bug_ids:
                if not bug_id in comments.keys():
                    comments[bug_id] = []
                comments[bug_id].append(commit)

    failed_bugs = []

    for bug_id in comments.keys():
        comment = []
        flags = branch_logic.flags_to_set([branch_to])
        for commit in comments[bug_id]:
            comment.append("v1.1.0hd: %s" % commit)
        comment = "\n".join(comment)
        print "Commenting on bug %s with:\ntext: %s\nflags: %s" % (bug_id, comment, flags)
        if not dry_run:
            try:
                bzapi.update_bug(bug_id, comment=comment, values=flags)
            except:
                failed_bugs.append(bug_id)
    print "The following commits do not have a bug associated with them:\n%s" % commits_without_bugs
    print "Failed to comment on the following bugs:\n%s" % failed_bugs