add --git-posttag to git-buildpackage
authorGuido Guenther <agx@sigxcpu.org>
Mon, 22 Jan 2007 18:06:22 +0000 (19:06 +0100)
committerGuido Guenther <agx@bogon.sigxcpu.org>
Mon, 22 Jan 2007 18:06:22 +0000 (19:06 +0100)
for easy push after a sucessful build

TODO
debian/changelog
docs/manpages/git-buildpackage.sgml
gbp.conf
git-buildpackage
git_buildpackage/__init__.py
git_buildpackage/config.py

diff --git a/TODO b/TODO
index 2c885d594846bb9932a910407957f46035936d8f..7301b776e02b815e76668026feb0226e47c9b2ab 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,7 +1,5 @@
 - git-buildpackage:
   - allow to export the hole source tree to tmpdir before building
-  - easy push/pull to/from remote repositories (like alioth) after a
-    successful build/for getting the sources (--git-post-tag-hook)
 - git-import-orig:
   - allow to import from an unpacked source tree
 - git-import-dsc:
index 584d3db8db262b5f5a93ccfda0245c466314a1db..f9d44174bb008bae6eef6ec532d406645d99cbf1 100644 (file)
@@ -1,3 +1,12 @@
+git-buildpackage (0.2.25) unstable; urgency=low
+
+  * UNRELEASED
+  * posttag suport for git-buildpackage: use --git-posttag to run a command
+    after a successfull build with tag (e.g. --git-posttag='git-push --tags
+    git.alioth.org')
+
+ -- Guido Guenther <agx@sigxcpu.org>  Fri, 19 Jan 2007 00:07:14 +0100
+
 git-buildpackage (0.2.24) unstable; urgency=low
 
   * add XS-Vcs-Git
index ea7db3e1ae081f3ced5fee7fcbbad34c7faa9523..751cf447ecf348249369d020e669c486524fc4d4 100644 (file)
@@ -28,6 +28,7 @@
       <arg><option>--git-cleaner=</option><replaceable>CLEAN_CMD</replaceable></arg>
       <arg><option>--git-sign-tags</option></arg>
       <arg><option>--git-keyid=</option><replaceable>gpg-keyid</replaceable></arg>
+      <arg><option>--git-posttag=</option><replaceable>command</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
   <refsect1>
          <para>use this keyid for gpg signing tags</para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><option>--git-posttag=</option><replaceable>command</replaceable>
+        </term>
+        <listitem>
+         <para>excecute <replaceable>command</replaceable> after tagging a new version</para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
   <refsect1>
index 02357fac2c5ee9247c97e78a88b3d2535599c3f3..98d8aa5411e16599e22aa61b06a2bfd7f65e31e6 100644 (file)
--- a/gbp.conf
+++ b/gbp.conf
@@ -15,6 +15,8 @@
 #sign-tags = True
 # Keyid to GPG sign tags with
 #keyid = 0xdeadbeef
+# Push to a remote repository after a successful tag:
+#posttag = git-push git.example.com
 
 # Special options for git-import-orig
 [git-import-orig]
index b07cb52d6a75ed81478d59ddedc708f22c662761..cd3749d6c5eec1d95d8ee458d7d57a6d86fdd68a 100755 (executable)
@@ -82,6 +82,8 @@ def main(argv):
                       help="branch the debian patch is being developed on, default is '%(debian-branch)s'")
     parser.add_config_file_option(option_name="sign-tags", dest="sign_tag",
                       help="sign git tags", action="store_true")
+    parser.add_config_file_option(option_name="posttag", dest="posttag_hook",
+                      help="hook to execute after a successfull tag operation")
     parser.add_config_file_option(option_name="keyid", dest="keyid",
                       help="GPG keyid to sign tags with")
     (options, args) = parser.parse_args(args)
@@ -97,7 +99,7 @@ def main(argv):
 
     try:
         if not options.ignore_new:
-            Command(options.clean_cmd)()
+            Command(options.clean_cmd, shell=True)()
             (ret, out) = repo.is_clean()
             if not ret:
                 print >>sys.stderr, "You have uncommitted changes in your source tree:"
@@ -116,7 +118,7 @@ def main(argv):
             if not create_orig(cp, output_dir, options.upstream_branch):
                 raise GbpError
 
-        Command(options.build_cmd, [ '-i\.git/', '-I.git' ] + dpkg_args)()
+        Command(options.build_cmd, [ '-i\.git/', '-I.git' ] + dpkg_args, shell=True)()
         if options.tag:
             try:
                 version = cp['Version']
@@ -125,6 +127,8 @@ def main(argv):
             else:
                 print "Tagging", version
                 GitTag(options.sign_tag, options.keyid)(sanitize_version(version))
+                if(options.posttag_hook):
+                    Command(options.posttag_hook, shell=True)()
     except CommandExecFailed:
         return 1
     except GbpError, err:
index 74814bdacea6b91f3dd0e77f3409ab46db78776d..4cac9cf5089b773227fba9d21b4a6a23ffea7418 100644 (file)
@@ -17,25 +17,30 @@ class Command(object):
     Wraps a shell command, so we don't have to store any kind of command line options in 
     one of the git-buildpackage commands
     """
-    verbose=False
+    verbose = False
 
-    def __init__(self, cmd, args=[]):
-        self.cmd=cmd.split()
-        self.args=args
-        self.run_error="Couldn't run '%s'" % (" ".join(self.cmd+args))
+    def __init__(self, cmd, args=[], shell=False):
+        self.cmd = cmd
+        self.args = args
+        self.run_error = "Couldn't run '%s'" % (" ".join([self.cmd] + self.args))
+        self.shell = shell
 
     def __run(self, args):
+        """run self.cmd adding args as additional arguments"""
         try:
             if self.verbose:
                 print self.cmd, self.args, args
-            retcode = subprocess.call(self.cmd + self.args + args)
+            cmd = [ self.cmd ] + self.args + args
+            if self.shell: # subprocess.call only cares about the first argument if shell=True
+                cmd = " ".join(cmd)
+            retcode = subprocess.call(cmd, shell=self.shell)
             if retcode < 0:
-                print >>sys.stderr, "%s was terminated by signal %d" % (self.cmd[0],  -retcode)
+                print >>sys.stderr, "%s was terminated by signal %d" % (self.cmd,  -retcode)
             elif retcode > 0:
-                print >>sys.stderr, "%s returned %d" % (self.cmd[0],  retcode)
+                print >>sys.stderr, "%s returned %d" % (self.cmd,  retcode)
         except OSError, e:
             print >>sys.stderr, "Execution failed:", e
-            retcode=1
+            retcode = 1
         if retcode:
             print >>sys.stderr,self.run_error
         return retcode
@@ -48,28 +53,28 @@ class Command(object):
 class UnpackTGZ(Command):
     """Wrap tar to Unpack a gzipped tar archive"""
     def __init__(self, tgz, dir):
-        self.tgz=tgz
-        self.dir=dir
+        self.tgz = tgz
+        self.dir = dir
         Command.__init__(self, 'tar', [ '-C', dir, '-zxf', tgz ])
-        self.run_error="Couldn't unpack %s" % (self.tgz,)
+        self.run_error = "Couldn't unpack %s" % self.tgz
 
 
 class RemoveTree(Command):
     "Wrap rm to remove a whole directory tree"
     def __init__(self, tree):
-        self.tree=tree
+        self.tree = tree
         Command.__init__(self, 'rm', [ '-rf', tree ])
-        self.run_error="Couldn't remove %s" % (self.tree,)
+        self.run_error = "Couldn't remove %s" % self.tree
 
 
 class Dch(Command):
     """Wrap dch and set a specific version"""
     def __init__(self, version, msg):
-        args=['-v', version]
+        args = ['-v', version]
         if msg:
             args.append(msg)
         Command.__init__(self, 'dch', args)
-        self.run_error="Dch failed."
+        self.run_error = "Dch failed."
 
 
 class DpkgSourceExtract(Command):
@@ -81,7 +86,7 @@ class DpkgSourceExtract(Command):
         Command.__init__(self, 'dpkg-source', ['-x'])
     
     def __call__(self, dsc, output_dir):
-        self.run_error="Couldn't extract %s" % (dsc,)
+        self.run_error = "Couldn't extract %s" % dsc
         Command.__call__(self, [dsc, output_dir])
 
 
@@ -91,9 +96,9 @@ class GitLoadDirs(Command):
         Command.__init__(self, 'git_load_dirs')
 
     def __call__(self, dir, log=''):
-        self.dir=dir
-        self.run_error="Couldn't import %s" % self.dir
-        args=[ [],['-L', log] ] [len(log) > 0]
+        self.dir = dir
+        self.run_error = "Couldn't import %s" % self.dir
+        args =[ [],['-L', log] ] [len(log) > 0]
         Command.__call__(self, args+[dir])
 
 
@@ -106,39 +111,39 @@ class GitCommand(Command):
 class GitInitDB(GitCommand):
     """Wrap git-init-db"""
     def __init__(self):
-        GitCommand.__init__(self,'init-db')
-        self.run_error="Couldn't init git repository"
+        GitCommand.__init__(self, 'init-db')
+        self.run_error = "Couldn't init git repository"
 
 
 class GitShowBranch(GitCommand):
     """Wrap git-show-branch"""
     def __init__(self):
-        GitCommand.__init__(self,'branch')
-        self.run_error="Couldn't list branches"
+        GitCommand.__init__(self, 'branch')
+        self.run_error = "Couldn't list branches"
 
 
 class GitBranch(GitCommand):
     """Wrap git-branch"""
     def __init__(self):
-        GitCommand.__init__(self,'branch')
+        GitCommand.__init__(self, 'branch')
 
     def __call__(self, branch):
-        self.run_error="Couldn't create branch %s" % (branch,)
+        self.run_error = "Couldn't create branch %s" % (branch,)
         GitCommand.__call__(self, [branch])
 
 
 class GitCheckoutBranch(GitCommand):
     """Wrap git-checkout in order tos switch to a certain branch"""
     def __init__(self, branch):
-        GitCommand.__init__(self,'checkout', [branch])
-        self.branch=branch
-        self.run_error="Couldn't switch to %s branch" % self.branch
+        GitCommand.__init__(self, 'checkout', [branch])
+        self.branch = branch
+        self.run_error = "Couldn't switch to %s branch" % self.branch
 
 
 class GitPull(GitCommand):
     """Wrap git-pull"""
     def __init__(self, repo, branch):
-        GitCommand.__init__(self,'pull', [repo, branch]) 
+        GitCommand.__init__(self, 'pull', [repo, branch]) 
         self.run_error = "Couldn't pull %s to %s" % (branch, repo)
 
 
@@ -150,7 +155,7 @@ class GitTag(GitCommand):
         self.keyid = keyid
 
     def __call__(self, version, msg="Tagging %(version)s"):
-        self.run_error="Couldn't tag %s" % (version,)
+        self.run_error = "Couldn't tag %s" % (version,)
         if self.sign_tag:
             if self.keyid:
                 sign_opts = [ '-u', self.keyid ]
@@ -171,11 +176,11 @@ class GitAdd(GitCommand):
 class GitCommitAll(GitCommand):
     """Wrap git-commit to commit all changes"""
     def __init__(self):
-        GitCommand.__init__(self,'commit', ['-a'])
+        GitCommand.__init__(self, 'commit', ['-a'])
 
     def __call__(self, msg=''):
         args = [ [], ['-m', msg] ][len(msg) > 0]
-        self.run_error="Couldn't commit -a %s" % " ".join(args)
+        self.run_error = "Couldn't commit -a %s" % " ".join(args)
         GitCommand.__call__(self, args)
 
 
index cff425538daa219872a881051b3d1aa1680d1082..67b2be155252d85f513bb2d2bae27896cbddca4a 100644 (file)
@@ -29,6 +29,7 @@ class GBPOptionParser(OptionParser):
                'upstream-branch' : 'upstream',
                'sign-tags'          : '',              # empty means False
                'keyid'              : '',
+               'posttag'         : '',
              }
     config_files=['/etc/git-buildpackage/gbp.conf',
                   os.path.expanduser('~/.gbp.conf'),