]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
buildman: Produce a sensible error message when branch is missing
authorSimon Glass <sjg@chromium.org>
Wed, 8 May 2013 08:06:08 +0000 (08:06 +0000)
committerTom Rini <trini@ti.com>
Tue, 14 May 2013 19:37:58 +0000 (15:37 -0400)
Rather than a backtrace, produce a nice error message when an invalid
branch is provided to buildman.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/buildman/control.py
tools/patman/gitutil.py

index 3e5f56c2802c731deb310d093afbb42b26ab5359..4319ce77d31a8bccd247ea42b18d1112d3779d25 100644 (file)
@@ -111,6 +111,10 @@ def DoBuildman(options, args):
             print col.Color(col.RED, str)
             sys.exit(1)
         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
 
     if not count:
index e31da1548dcf87c8a822385d818b8afc5a8878d0..b7f673955218ef3a49aee8ad5427353b8e6c2a27 100644 (file)
@@ -56,10 +56,14 @@ def GetUpstream(git_dir, branch):
     Returns:
         Name of upstream branch (e.g. 'upstream/master') or None if none
     """
-    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)
+    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:
@@ -78,9 +82,11 @@ def GetRangeInBranch(git_dir, branch, include_upstream=False):
         branch: Name of branch
     Return:
         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)
+    if not upstream:
+        return None
     return '%s%s..%s' % (upstream, '~' if include_upstream else '', branch)
 
 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
         branch: Name of branch
     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)
+    if not range_expr:
+        return None
     pipe = [['git', '--git-dir', git_dir, 'log', '--oneline', '--no-decorate',
              range_expr],
             ['wc', '-l']]