Add "stg id" support for "{public}" ref
[stgit] / stgit / commands / id.py
index 284589a..654ff72 100644 (file)
@@ -15,26 +15,28 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-import sys, os
-from optparse import OptionParser, make_option
-
-from stgit.commands.common import *
-from stgit.utils import *
-from stgit import stack, git
-
-
-help = 'print the hash value of a GIT id'
-usage = """%prog [options] [id]
-
-Print the hash value of a GIT id (defaulting to HEAD). In addition to
-the standard GIT id's like heads and tags, this command also accepts
-'base[@<branch>]' and '[<patch>[@<branch>]][//[bottom | top]]'. If no
-'top' or 'bottom' are passed and <patch> is a valid patch name, 'top'
-will be used by default."""
-
-options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one')]
-
+from stgit.out import out
+from stgit.commands import common
+from stgit.lib import stack
+from stgit import argparse
+
+help = 'Print the git hash value of a StGit reference'
+kind = 'repo'
+usage = ['[options] [id]']
+description = """
+Print the SHA1 value of a Git id (defaulting to HEAD). In addition to the
+standard Git id's like heads and tags, this command also accepts
+'[<branch>:]<patch>' for the id of a patch, '[<branch>:]\{base\}' for the base
+of the stack and '[<branch>:]\{public\}' for the public branch corresponding
+to the stack (see the 'publish' command for details). If no branch is
+specified, it defaults to the current one. The bottom of a patch is accessible
+with the '[<branch>:]<patch>^' format."""
+
+args = [argparse.applied_patches, argparse.unapplied_patches,
+        argparse.hidden_patches]
+options = []
+
+directory = common.DirectoryHasRepositoryLib()
 
 def func(parser, options, args):
     """Show the applied patches
@@ -46,4 +48,4 @@ def func(parser, options, args):
     else:
         parser.error('incorrect number of arguments')
 
-    print git_id(id_str)
+    out.stdout(common.git_commit(id_str, directory.repository).sha1)