Index: ensure_dependencies.py |
diff --git a/ensure_dependencies.py b/ensure_dependencies.py |
index 9f2bcc7b7d8feec57b10e4c6d8b62989171ac8ff..852025cd741df9bfcaf3633723d80ab8c1fc55b7 100755 |
--- a/ensure_dependencies.py |
+++ b/ensure_dependencies.py |
@@ -97,7 +97,20 @@ class Git(): |
return subprocess.check_output(command, cwd=repo).strip() |
def pull(self, repo): |
+ # First perform a fetch so we have a list of remote branch names and tags |
Sebastian Noack
2015/05/06 13:24:08
This comment isn't 100% accurate. I think it shoul
|
subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=repo) |
+ # Next we need to ensure all remote branches are tracked |
+ newly_tracked = False |
+ remotes = subprocess.check_output(["git", "branch", "--remotes"], cwd=repo) |
+ for match in re.finditer(r"(?:^|\s)(origin/((?!HEAD(?:$|\s))\S+))", remotes): |
+ remote, local = match.groups() |
+ with open(os.devnull, "wb") as devnull: |
+ if subprocess.call(["git", "branch", "--track", local, remote], |
+ cwd=repo, stdout=devnull, stderr=devnull) == 0: |
+ newly_tracked = True |
+ # Finally fetch any newly tracked remote branches |
+ if newly_tracked: |
+ subprocess.check_call(["git", "fetch", "--quiet", "origin"], cwd=repo) |
def update(self, repo, rev): |
subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) |