def GetUpstream(git_dir, branch): """Returns the name of the upstream for a branch Args: git_dir: Git directory containing repo branch: Name of branch Returns: Name of upstream branch (e.g. 'upstream/master') or None if none """ try: remote = command.OutputOneLine('git', '--git-dir', git_dir, 'config', 'branch.%s.remote' % branch) merge = command.OutputOneLine('git', '--git-dir', git_dir, 'config', 'branch.%s.merge' % branch) except: return None if remote == '.': return merge elif remote and merge: leaf = merge.split('/')[-1] return '%s/%s' % (remote, leaf) else: raise ValueError, ("Cannot determine upstream branch for branch " "'%s' remote='%s', merge='%s'" % (branch, remote, merge))
def GetHead(): """Get the hash of the current HEAD Returns: Hash of HEAD """ return command.OutputOneLine('git', 'show', '-s', '--pretty=format:%H')
def LocateArchUrl(self, fetch_arch): """Find a toolchain available online Look in standard places for available toolchains. At present the only standard place is at kernel.org. Args: arch: Architecture to look for, or 'list' for all Returns: If fetch_arch is 'list', a tuple: Machine architecture (e.g. x86_64) List of toolchains else URL containing this toolchain, if avaialble, else None """ arch = command.OutputOneLine('uname', '-m') base = 'https://www.kernel.org/pub/tools/crosstool/files/bin' versions = ['7.3.0', '6.4.0', '4.9.4'] links = [] for version in versions: url = '%s/%s/%s/' % (base, arch, version) print('Checking: %s' % url) response = urllib.request.urlopen(url) html = tools.ToString(response.read()) parser = MyHTMLParser(fetch_arch) parser.feed(html) if fetch_arch == 'list': links += parser.links elif parser.arch_link: return url + parser.arch_link if fetch_arch == 'list': return arch, links return None
def GetDefaultUserEmail(): """Gets the user.email from the global .gitconfig file. Returns: User's email found in .gitconfig file, or None if none """ uemail = command.OutputOneLine('git', 'config', '--global', 'user.email') return uemail
def GetDefaultUserName(): """Gets the user.name from .gitconfig file. Returns: User name found in .gitconfig file, or None if none """ uname = command.OutputOneLine('git', 'config', '--global', 'user.name') return uname
def GetAliasFile(): """Gets the name of the git alias file. Returns: Filename of git alias file, or None if none """ fname = command.OutputOneLine('git', 'config', 'sendemail.aliasesfile') if fname: fname = os.path.join(GetTopLevel(), fname.strip()) return fname
def GetDefaultSubjectPrefix(): """Gets the format.subjectprefix from local .git/config file. Returns: Subject prefix found in local .git/config file, or None if none """ sub_prefix = command.OutputOneLine('git', 'config', 'format.subjectprefix', raise_on_error=False) return sub_prefix
def GetTopLevel(): """Return name of top-level directory for this git repo. Returns: Full path to git top-level directory This test makes sure that we are running tests in the right subdir >>> os.path.realpath(os.path.dirname(__file__)) == \ os.path.join(GetTopLevel(), 'tools', 'patman') True """ return command.OutputOneLine('git', 'rev-parse', '--show-toplevel')