Chad has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/403220 )

Change subject: grumble grumble submodules
......................................................................

grumble grumble submodules

Change-Id: I39d2a9196722bf468c574e388a5321a25e923616
---
M make-release/branch.py
1 file changed, 22 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/release 
refs/changes/20/403220/1

diff --git a/make-release/branch.py b/make-release/branch.py
index 8aff26f..c27a33b 100755
--- a/make-release/branch.py
+++ b/make-release/branch.py
@@ -18,6 +18,7 @@
 
 from pygerrit.rest import GerritRestAPI
 
+GIT_BIN = '/usr/bin/git'
 with open("make-release.yaml") as conf:
     CONFIG = yaml.safe_load(conf)
 
@@ -29,27 +30,29 @@
         auth=HTTPDigestAuth(CONFIG['username'], CONFIG['password']))
 
 
-def get_branchpoint(branch, repository, default):
-    try:
-        return CONFIG['manual_branch_points'][branch][repository]
-    except KeyError:
-        return default
-
-
 def create_branch(repository, branch, revision):
     """Create a branch for a given repo."""
-    # If we've got a sub-submodule we care about, branch it first so we can
-    # do some magic stuff
+    try:
+        revision = CONFIG['manual_branch_points'][branch][repository]
+    except KeyError:
+        pass
+
+    # If we're dealing with sub-submodules, branch those and then update
+    # our repo as appropriate
     try:
         subrepo = CONFIG['sub_submodules'][repository]
         create_branch(subrepo, branch, revision)
+        with clone_then_commit('repository', branch) as repodir:
+            subprocess.check_call([GIT_BIN, 'submodule', 'update' '--init', 
subrepo])
+            os.chdir(os.path.join(repodir, subrepo))
+            subprocess.check_call([GIT_BIN, 'checkout', branch])
+            os.chdir(repodir)
+            subprocess.check_call([GIT_BIN, 'add', subrepo])
     except KeyError:
         # This is the normal case, actually
         pass
 
     try:
-        revision = get_branchpoint(branch, repository, revision)
-
         print('Branching {} to {} from {}'.format(repository, branch, 
revision))
         _get_client().put(
             '/projects/%s/branches/%s' % (
@@ -84,32 +87,30 @@
 
 
 @contextmanager
-def clone(repository):
+def clone_then_commit(repository, branch):
+    """Clone a repository into a temporary directory"""
     url = CONFIG['clone_base'] + '/' + repository
     temp = tempfile.mkdtemp()
-    subprocess.check_call(['/usr/bin/git', 'clone', url, temp])
+    subprocess.check_call([GIT_BIN, 'clone', '-b', branch, url, temp])
     cwd = os.getcwd()
     os.chdir(temp)
     yield temp
+    subprocess.check_call(
+        [GIT_BIN, 'commit', '-a', '-m', 'Creating new %s branch' % branch])
     os.chdir(cwd)
-    shutil.rmtree(temp)
 
 
 def do_core_work(branch, bundle, version):
     """Add submodules, bump $wgVersion, etc"""
-    cwd = os.getcwd()
-    with clone('core'):
+    with clone_then_commit('core', branch):
         for submodule in bundle:
             url = CONFIG['clone_base'] + '/' + submodule
-            subprocess.check_call(['/usr/bin/git', 'submodule', 'add',
+            subprocess.check_call([GIT_BIN, 'submodule', 'add',
                                    '--force', '--branch', branch, url,
                                    submodule])
         # something with defaultsettings
-        subprocess.check_call(['/usr/bin/git', 'commit', '-a', '-m',
-                               'Creating new %s branch' % branch])
-        subprocess.check_call(['/usr/bin/git', 'push', 'origin',
+        subprocess.check_call([GIT_BIN, 'push', 'origin',
                                'HEAD:refs/for/%s' % branch])
-    os.chdir(cwd)
 
 
 def parse_args():

-- 
To view, visit https://gerrit.wikimedia.org/r/403220
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I39d2a9196722bf468c574e388a5321a25e923616
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/release
Gerrit-Branch: master
Gerrit-Owner: Chad <ch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to