def get_git_repo_url(gitdir): command = f"(cd {gitdir}; git remote show origin -n)" output = run_command(command) for line in output.split('\n'): m = re.search("URL:\s+(\S+)", line) if m: return m.group(1) return None
def confirm_commit(commit, repo): command = f"cd {repo} ; git rev-list HEAD --not --remotes $(git config --get branch.$(git symbolic-ref --short HEAD).remote)" out = run_command(command) if out == "": return True commits = out.split() if commit in commits: return False return True
def get_commit(commit, repo, force=False): command = f"cd {repo}; git diff-tree --no-renames --pretty=email -r -p --cc --stat {commit}" data = run_command(command) if data == "": return None if not force and not confirm_commit(commit, repo): raise LocalCommitException( "Commit is not in the remote repository. Use -f to override.") return data
def get_tag(commit, repo): command = f"(cd {repo};git name-rev --refs=refs/tags/v* {commit})" tag = run_command(command) if tag == "": return None m = re.search("tags/([a-zA-Z0-9\.-]+)\~?\S*$", tag) if m: return m.group(1) m = re.search("(undefined)", tag) if m: return m.group(1) return None
def get_next_tag(repo): command = f"(cd {repo} ; git tag -l 'v[0-9]*')" tag = run_command(command) if tag == "": return None lines = tag.split() lines.sort(key=key_version) lasttag = lines[len(lines) - 1] m = re.search("v([0-9]+)\.([0-9]+)(|-rc([0-9]+))$", lasttag) if m: # Post-release commit with no rc, it'll be rc1 if m.group(3) == "": nexttag = "v%s.%d-rc1" % (m.group(1), int(m.group(2)) + 1) else: nexttag = "v%s.%d or v%s.%s-rc%d (next release)" % \ (m.group(1), int(m.group(2)), m.group(1), m.group(2), int(m.group(4)) + 1) return nexttag return None
def get_git_config(gitdir, var): command = f"(cd {gitdir}; git config {var})" return run_command(command).strip()
def get_diffstat(message): return run_command("diffstat -p1", input=message)
def canonicalize_commit(commit, repo): return run_command(f"cd {repo} ; git show -s {commit}^{{}} --pretty=%H")