Allow a backtracking branch to upload any package version
[invirt/packages/invirt-dev.git] / invirtibuilder
index a42ce55..e1c3d80 100755 (executable)
@@ -129,7 +129,7 @@ def sbuildAll(package, ref, workdir):
         sbuild(package, ref, 'i386', workdir)
 
 
-def tagSubmodule(pocket, package, principal, version, env):
+def tagSubmodule(pocket, package, commit, principal, version, env):
     """Tag a new version of a submodule.
 
     If this pocket does not allow_backtracking, then this will create
@@ -153,26 +153,32 @@ def tagSubmodule(pocket, package, principal, version, env):
 
         c.captureOutput(
             ['git', 'tag', '-m', tag_msg, commit],
-            stdout=None,
-            env=env)
+            env=env,
+            cwd=b.getRepo(package))
 
 
-def updateSubmoduleBranch(pocket, package, ref):
+def updateSubmoduleBranch(pocket, package, commit):
     """Update the appropriately named branch in the submodule."""
     branch = b.pocketToGit(pocket)
     c.captureOutput(
-        ['git', 'update-ref', 'refs/heads/%s' % branch, ref], cwd=b.getRepo(package))
+        ['git', 'update-ref', 'refs/heads/%s' % branch, commit], cwd=b.getRepo(package))
 
 
 def uploadBuild(pocket, workdir):
     """Upload all build products in the work directory."""
+    force = config.build.pockets[pocket].get('allow_backtracking', False)
     apt = b.pocketToApt(pocket)
     for changes in glob.glob(os.path.join(workdir, '*.changes')):
-        c.captureOutput(['reprepro-env',
-                       '--ignore=wrongdistribution',
-                       'include',
-                       apt,
-                       changes])
+        upload = ['reprepro-env', '--ignore=wrongdistribution',
+                  'include', apt, changes]
+        try:
+            c.captureOutput(upload)
+        except subprocess.CalledProcessError, e:
+            if not force:
+                raise
+            package = deb822.Changes(open(changes).read())['Binary']
+            c.captureOutput(['reprepro-env', 'remove', apt, package])
+            c.captureOutput(upload)
 
 
 def updateSuperproject(pocket, package, commit, principal, version, env):