Allow StGIT to be installed in a local directory
[stgit] / stgit / commands / export.py
index db7b560..ebcc77a 100644 (file)
@@ -27,10 +27,27 @@ from stgit import stack, git
 
 
 help = 'exports a series of patches to <dir> (or patches)'
-usage = """%prog [options] [<dir>]"""
+usage = """%prog [options] [<dir>]
+
+Export the applied patches into a given directory (defaults to
+'patches') in a standard unified GNU diff format. A template file
+(defaulting to '.git/patchexport.tmpl or
+/usr/share/stgit/templates/patchexport.tmpl') can be used for the
+patch format. The following variables are supported in the template
+file:
+
+  %(description)s - patch description
+  %(diffstat)s    - the diff statistics
+  %(authname)s    - author's name
+  %(authemail)s   - author's e-mail
+  %(authdate)s    - patch creation date
+  %(commname)s    - committer's name
+  %(commemail)s   - committer's e-mail
+
+'export' can also generate a diff for a range of patches."""
 
 options = [make_option('-n', '--numbered',
-                       help = 'number the patch names',
+                       help = 'prefix the patch names with order numbers',
                        action = 'store_true'),
            make_option('-d', '--diff',
                        help = 'append .diff to the patch names',
@@ -99,6 +116,21 @@ def func(parser, options, args):
     if zpadding < 2:
         zpadding = 2
 
+    # get the template
+    if options.template:
+        patch_tmpl_list = [options.template]
+    else:
+        patch_tmpl_list = []
+
+    patch_tmpl_list += [os.path.join(git.base_dir, 'patchexport.tmpl'),
+                        os.path.join(sys.prefix,
+                                     'share/stgit/templates/patchexport.tmpl')]
+    tmpl = ''
+    for patch_tmpl in patch_tmpl_list:
+        if os.path.isfile(patch_tmpl):
+            tmpl = file(patch_tmpl).read()
+            break
+
     patch_no = 1;
     for p in patches:
         pname = p
@@ -109,16 +141,6 @@ def func(parser, options, args):
         pfile = os.path.join(dirname, pname)
         print >> series, pname
 
-        # get the template
-        if options.template:
-            patch_tmpl = options.template
-        else:
-            patch_tmpl = os.path.join(git.base_dir, 'patchexport.tmpl')
-        if os.path.isfile(patch_tmpl):
-            tmpl = file(patch_tmpl).read()
-        else:
-            tmpl = ''
-
         # get the patch description
         patch = crt_series.get_patch(p)