chiark / gitweb /
Allow 'show' and 'id' to work on non-StGIT branches (bug #10011)
authorCatalin Marinas <catalin.marinas@gmail.com>
Fri, 7 Dec 2007 21:19:24 +0000 (21:19 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Fri, 7 Dec 2007 21:19:24 +0000 (21:19 +0000)
Some clean-up to only access the current series object if needed.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/common.py
stgit/commands/show.py
t/t2400-diff.sh

index bf804e6763b720bf2d706ebbd26486563e608ddb..78a364fdee8d4831d4b039f034de5d41246148ee 100644 (file)
@@ -77,6 +77,14 @@ def git_id(crt_series, rev):
     """
     if not rev:
         return None
+
+    # try a GIT revision first
+    try:
+        return git.rev_parse(rev + '^{commit}')
+    except git.GitException:
+        pass
+
+    # try an StGIT patch name
     try:
         patch, branch, patch_id = parse_rev(rev)
         if branch == None:
@@ -103,7 +111,10 @@ def git_id(crt_series, rev):
             return series.get_base()
     except RevParseException:
         pass
-    return git.rev_parse(rev + '^{commit}')
+    except stack.StackException:
+        pass
+
+    raise CmdException, 'Unknown patch or revision: %s' % rev
 
 def check_local_changes():
     if git.local_changes():
index e6814d38c870919e98025eec127c5434fed55028..72d1be387f02678011ba3fb67202cfd1d4f2e673 100644 (file)
@@ -46,23 +46,21 @@ options = [make_option('-b', '--branch',
 def func(parser, options, args):
     """Show commit log and diff
     """
-    applied = crt_series.get_applied()
-    unapplied = crt_series.get_unapplied()
-
     if options.applied:
-        patches = applied
+        patches = crt_series.get_applied()
     elif options.unapplied:
-        patches = unapplied
+        patches = crt_series.get_unapplied()
     elif len(args) == 0:
         patches = ['HEAD']
     else:
-        if len(args) == 1 and args[0].find('..') == -1 \
-               and not crt_series.patch_exists(args[0]):
-            # it might be just a commit id
+        if len(args) == 1 and args[0].find('..') == -1:
+            # single patch or commit id
             patches = args
         else:
-            patches = parse_patches(args, applied + unapplied +\
-                                crt_series.get_hidden(), len(applied))
+            applied = crt_series.get_applied()
+            unapplied = crt_series.get_unapplied()
+            patches = parse_patches(args, applied + unapplied + \
+                                    crt_series.get_hidden(), len(applied))
 
     if options.show_opts:
         show_flags = options.show_opts.split()
index 6d9ed98ecf4edf7524961e5f82b0143cd806dd48..fbcefe185834a35fc7591ace20570998c8d0dedd 100755 (executable)
@@ -4,7 +4,7 @@ test_description='Run "stg diff"'
 
 . ./test-lib.sh
 
-test_expect_failure 'Diff with no StGit data' '
+test_expect_success 'Diff with no StGit data' '
     stg diff
 '
 
@@ -13,7 +13,7 @@ test_expect_success 'Make some local changes' '
     git add foo.txt
 '
 
-test_expect_failure 'Diff with some local changes' '
+test_expect_success 'Diff with some local changes' '
     stg diff
 '