Skip to content
Snippets Groups Projects
Commit cce717a9 authored by Simon Glass's avatar Simon Glass Committed by Tom Rini
Browse files

buildman: Produce a sensible error message when branch is missing


Rather than a backtrace, produce a nice error message when an invalid
branch is provided to buildman.

Signed-off-by: default avatarSimon Glass <sjg@chromium.org>
parent 2a08b740
No related branches found
No related tags found
No related merge requests found
...@@ -111,6 +111,10 @@ def DoBuildman(options, args): ...@@ -111,6 +111,10 @@ def DoBuildman(options, args):
print col.Color(col.RED, str) print col.Color(col.RED, str)
sys.exit(1) sys.exit(1)
count = gitutil.CountCommitsInBranch(options.git_dir, options.branch) count = gitutil.CountCommitsInBranch(options.git_dir, options.branch)
if count is None:
str = "Branch '%s' not found or has no upstream" % options.branch
print col.Color(col.RED, str)
sys.exit(1)
count += 1 # Build upstream commit also count += 1 # Build upstream commit also
if not count: if not count:
......
...@@ -56,10 +56,14 @@ def GetUpstream(git_dir, branch): ...@@ -56,10 +56,14 @@ def GetUpstream(git_dir, branch):
Returns: Returns:
Name of upstream branch (e.g. 'upstream/master') or None if none Name of upstream branch (e.g. 'upstream/master') or None if none
""" """
remote = command.OutputOneLine('git', '--git-dir', git_dir, 'config', try:
'branch.%s.remote' % branch) remote = command.OutputOneLine('git', '--git-dir', git_dir, 'config',
merge = command.OutputOneLine('git', '--git-dir', git_dir, 'config', 'branch.%s.remote' % branch)
'branch.%s.merge' % branch) merge = command.OutputOneLine('git', '--git-dir', git_dir, 'config',
'branch.%s.merge' % branch)
except:
return None
if remote == '.': if remote == '.':
return merge return merge
elif remote and merge: elif remote and merge:
...@@ -78,9 +82,11 @@ def GetRangeInBranch(git_dir, branch, include_upstream=False): ...@@ -78,9 +82,11 @@ def GetRangeInBranch(git_dir, branch, include_upstream=False):
branch: Name of branch branch: Name of branch
Return: Return:
Expression in the form 'upstream..branch' which can be used to Expression in the form 'upstream..branch' which can be used to
access the commits. access the commits. If the branch does not exist, returns None.
""" """
upstream = GetUpstream(git_dir, branch) upstream = GetUpstream(git_dir, branch)
if not upstream:
return None
return '%s%s..%s' % (upstream, '~' if include_upstream else '', branch) return '%s%s..%s' % (upstream, '~' if include_upstream else '', branch)
def CountCommitsInBranch(git_dir, branch, include_upstream=False): def CountCommitsInBranch(git_dir, branch, include_upstream=False):
...@@ -90,9 +96,12 @@ def CountCommitsInBranch(git_dir, branch, include_upstream=False): ...@@ -90,9 +96,12 @@ def CountCommitsInBranch(git_dir, branch, include_upstream=False):
git_dir: Directory containing git repo git_dir: Directory containing git repo
branch: Name of branch branch: Name of branch
Return: Return:
Number of patches that exist on top of the branch Number of patches that exist on top of the branch, or None if the
branch does not exist.
""" """
range_expr = GetRangeInBranch(git_dir, branch, include_upstream) range_expr = GetRangeInBranch(git_dir, branch, include_upstream)
if not range_expr:
return None
pipe = [['git', '--git-dir', git_dir, 'log', '--oneline', '--no-decorate', pipe = [['git', '--git-dir', git_dir, 'log', '--oneline', '--no-decorate',
range_expr], range_expr],
['wc', '-l']] ['wc', '-l']]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment