← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:restore-db-upgrade-outside-vcs into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:restore-db-upgrade-outside-vcs into launchpad:master.

Commit message:
Restore support for upgrade.py outside VCS branch

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/428983

`database/schema/upgrade.py` used to support running outside a VCS branch, in which case it would record the `branch_nick` and `revid` columns of new `LaunchpadDatabaseRevision` columns as NULL.  I accidentally dropped this support when removing bzr support from this script in commit 8651d7420e9254733234e84e84933c806521a4fc, but it's still useful to have: in particular, Launchpad trees deployed via charms don't currently have a `.git` directory, but it's handy to be able to run `upgrade.py` from them anyway.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:restore-db-upgrade-outside-vcs into launchpad:master.
diff --git a/database/schema/upgrade.py b/database/schema/upgrade.py
index 7c139cc..ee21fb1 100755
--- a/database/schema/upgrade.py
+++ b/database/schema/upgrade.py
@@ -286,16 +286,20 @@ def get_vcs_details():
     """
     global _vcs_details_cache
     if _vcs_details_cache is None:
-        branch_nick = subprocess.check_output(
-            ["git", "rev-parse", "--abbrev-ref", "HEAD"],
-            cwd=SCHEMA_DIR,
-            universal_newlines=True,
-        ).rstrip("\n")
-        revision_id = subprocess.check_output(
-            ["git", "rev-parse", "HEAD"],
-            cwd=SCHEMA_DIR,
-            universal_newlines=True,
-        ).rstrip("\n")
+        top = os.path.dirname(os.path.dirname(SCHEMA_DIR))
+        if os.path.exists(os.path.join(top, ".git")):
+            branch_nick = subprocess.check_output(
+                ["git", "rev-parse", "--abbrev-ref", "HEAD"],
+                cwd=SCHEMA_DIR,
+                universal_newlines=True,
+            ).rstrip("\n")
+            revision_id = subprocess.check_output(
+                ["git", "rev-parse", "HEAD"],
+                cwd=SCHEMA_DIR,
+                universal_newlines=True,
+            ).rstrip("\n")
+        else:
+            branch_nick, revision_id = None, None
         _vcs_details_cache = (branch_nick, revision_id)
     return _vcs_details_cache