Print this page
10328 git pbchk falls over with no changesets


 108     for elt in p:
 109         if elt[0] == '*':
 110             if elt.endswith('(no branch)'):
 111                 return None
 112             return elt.split()[1]
 113 
 114 def git_parent_branch(branch):
 115     """Return the parent of the current git branch.
 116 
 117     If this branch tracks a remote branch, return the remote branch which is
 118     tracked.  If not, default to origin/master."""
 119 
 120     if not branch:
 121         return None
 122 
 123     p = git(["for-each-ref", "--format=%(refname:short) %(upstream:short)",
 124             "refs/heads/"])
 125 
 126     if not p:
 127         sys.stderr.write("Failed finding git parent branch\n")
 128         sys.exit(err)
 129 
 130     for line in p:
 131         # Git 1.7 will leave a ' ' trailing any non-tracking branch
 132         if ' ' in line and not line.endswith(' \n'):
 133             local, remote = line.split()
 134             if local == branch:
 135                 return remote
 136     return 'origin/master'
 137 
 138 def git_comments(parent):
 139     """Return a list of any checkin comments on this git branch"""
 140 
 141     p = git('log --pretty=tformat:%%B:SEP: %s..' % parent)
 142 
 143     if not p:
 144         sys.stderr.write("Failed getting git comments\n")
 145         sys.exit(err)
 146 
 147     return [x.strip() for x in p if x != ':SEP:\n']
 148 
 149 def git_file_list(parent, paths=None):
 150     """Return the set of files which have ever changed on this branch.
 151 
 152     NB: This includes files which no longer exist, or no longer actually
 153     differ."""
 154 
 155     p = git("log --name-only --pretty=format: %s.. %s" %
 156              (parent, ' '.join(paths)))
 157 
 158     if not p:
 159         sys.stderr.write("Failed building file-list from git\n")
 160         sys.exit(err)
 161 
 162     ret = set()
 163     for fname in p:
 164         if fname and not fname.isspace() and fname not in ret:
 165             ret.add(fname.strip())
 166 
 167     return ret
 168 
 169 def not_check(root, cmd):
 170     """Return a function which returns True if a file given as an argument
 171     should be excluded from the check named by 'cmd'"""
 172 
 173     ignorefiles = list(filter(os.path.exists,
 174                          [os.path.join(root, ".git", "%s.NOT" % cmd),
 175                           os.path.join(root, "exception_lists", cmd)]))
 176     return Ignore.ignore(root, ignorefiles)
 177 
 178 def gen_files(root, parent, paths, exclude):
 179     """Return a function producing file names, relative to the current
 180     directory, of any file changed on this branch (limited to 'paths' if




 108     for elt in p:
 109         if elt[0] == '*':
 110             if elt.endswith('(no branch)'):
 111                 return None
 112             return elt.split()[1]
 113 
 114 def git_parent_branch(branch):
 115     """Return the parent of the current git branch.
 116 
 117     If this branch tracks a remote branch, return the remote branch which is
 118     tracked.  If not, default to origin/master."""
 119 
 120     if not branch:
 121         return None
 122 
 123     p = git(["for-each-ref", "--format=%(refname:short) %(upstream:short)",
 124             "refs/heads/"])
 125 
 126     if not p:
 127         sys.stderr.write("Failed finding git parent branch\n")
 128         sys.exit(1)
 129 
 130     for line in p:
 131         # Git 1.7 will leave a ' ' trailing any non-tracking branch
 132         if ' ' in line and not line.endswith(' \n'):
 133             local, remote = line.split()
 134             if local == branch:
 135                 return remote
 136     return 'origin/master'
 137 
 138 def git_comments(parent):
 139     """Return a list of any checkin comments on this git branch"""
 140 
 141     p = git('log --pretty=tformat:%%B:SEP: %s..' % parent)
 142 
 143     if not p:
 144         sys.stderr.write("No outgoing changesets found - missing -p option?\n");
 145         sys.exit(1)
 146 
 147     return [x.strip() for x in p if x != ':SEP:\n']
 148 
 149 def git_file_list(parent, paths=None):
 150     """Return the set of files which have ever changed on this branch.
 151 
 152     NB: This includes files which no longer exist, or no longer actually
 153     differ."""
 154 
 155     p = git("log --name-only --pretty=format: %s.. %s" %
 156              (parent, ' '.join(paths)))
 157 
 158     if not p:
 159         sys.stderr.write("Failed building file-list from git\n")
 160         sys.exit(1)
 161 
 162     ret = set()
 163     for fname in p:
 164         if fname and not fname.isspace() and fname not in ret:
 165             ret.add(fname.strip())
 166 
 167     return ret
 168 
 169 def not_check(root, cmd):
 170     """Return a function which returns True if a file given as an argument
 171     should be excluded from the check named by 'cmd'"""
 172 
 173     ignorefiles = list(filter(os.path.exists,
 174                          [os.path.join(root, ".git", "%s.NOT" % cmd),
 175                           os.path.join(root, "exception_lists", cmd)]))
 176     return Ignore.ignore(root, ignorefiles)
 177 
 178 def gen_files(root, parent, paths, exclude):
 179     """Return a function producing file names, relative to the current
 180     directory, of any file changed on this branch (limited to 'paths' if