Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: ensure_dependencies.py

Issue 6068640302497792: Issue 2311 - Track remote Git branches when required (Closed)
Left Patch Set: Addressed feedback Created May 6, 2015, 12:46 p.m.
Right Patch Set: Simplify regexp some more Created May 6, 2015, 3:08 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 3
4 # This Source Code Form is subject to the terms of the Mozilla Public 4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this 5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 7
8 import sys 8 import sys
9 import os 9 import os
10 import posixpath 10 import posixpath
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 source = source.rstrip("/") 90 source = source.rstrip("/")
91 if not source.endswith(".git"): 91 if not source.endswith(".git"):
92 source += ".git" 92 source += ".git"
93 subprocess.check_call(["git", "clone", "--quiet", source, target]) 93 subprocess.check_call(["git", "clone", "--quiet", source, target])
94 94
95 def get_revision_id(self, repo, rev="HEAD"): 95 def get_revision_id(self, repo, rev="HEAD"):
96 command = ["git", "rev-parse", "--revs-only", rev + '^{commit}'] 96 command = ["git", "rev-parse", "--revs-only", rev + '^{commit}']
97 return subprocess.check_output(command, cwd=repo).strip() 97 return subprocess.check_output(command, cwd=repo).strip()
98 98
99 def pull(self, repo): 99 def pull(self, repo):
100 # First perform a fetch so we have a list of remote branch names and tags 100 # Fetch tracked branches, new tags and the list of available remote branches
Sebastian Noack 2015/05/06 13:24:08 This comment isn't 100% accurate. I think it shoul
101 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) 101 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po)
102 # Next we need to ensure all remote branches are tracked 102 # Next we need to ensure all remote branches are tracked
103 newly_tracked = False 103 newly_tracked = False
104 remotes = subprocess.check_output(["git", "branch", "--remotes"], cwd=repo) 104 remotes = subprocess.check_output(["git", "branch", "--remotes"], cwd=repo)
105 for match in re.finditer(r"(?:^|\s)(origin/((?!HEAD(?:$|\s))\S+))", remotes) : 105 for match in re.finditer(r"^\s*(origin/(\S+))$", remotes, re.M):
106 remote, local = match.groups() 106 remote, local = match.groups()
107 with open(os.devnull, "wb") as devnull: 107 with open(os.devnull, "wb") as devnull:
108 if subprocess.call(["git", "branch", "--track", local, remote], 108 if subprocess.call(["git", "branch", "--track", local, remote],
109 cwd=repo, stdout=devnull, stderr=devnull) == 0: 109 cwd=repo, stdout=devnull, stderr=devnull) == 0:
110 newly_tracked = True 110 newly_tracked = True
111 # Finally fetch any newly tracked remote branches 111 # Finally fetch any newly tracked remote branches
112 if newly_tracked: 112 if newly_tracked:
113 subprocess.check_call(["git", "fetch", "--quiet", "origin"], cwd=repo) 113 subprocess.check_call(["git", "fetch", "--quiet", "origin"], cwd=repo)
114 114
115 def update(self, repo, rev): 115 def update(self, repo, rev):
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 args = parser.parse_args() 317 args = parser.parse_args()
318 318
319 if args.quiet: 319 if args.quiet:
320 logging.disable(logging.INFO) 320 logging.disable(logging.INFO)
321 321
322 repos = args.repos 322 repos = args.repos
323 if not len(repos): 323 if not len(repos):
324 repos = [os.path.dirname(__file__)] 324 repos = [os.path.dirname(__file__)]
325 for repo in repos: 325 for repo in repos:
326 resolve_deps(repo) 326 resolve_deps(repo)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld