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

Side by Side Diff: ensure_dependencies.py

Issue 6068640302497792: Issue 2311 - Track remote Git branches when required (Closed)
Patch Set: Make Git.pull track all remote branches Created May 6, 2015, 11:02 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
101 subprocess.check_call(["git", "fetch", "--quiet"], cwd=repo)
102 # Next we need to ensure all remote branches are tracked
103 remotes = subprocess.check_output(["git", "branch", "--remotes"], cwd=repo)
104 for match in re.finditer(r"origin/(\S+)", remotes):
105 remote, local = match.group(0), match.group(1)
106 if local not in ["HEAD", "master"]:
107 with open(os.devnull, "w") as devnull:
108 subprocess.call(["git", "branch", "--track", local, remote],
109 cwd=repo, stdout=devnull, stderr=devnull)
110 # Finally we need to actually fetch all the remote branches and tags
100 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) 111 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po)
101 112
102 def update(self, repo, rev): 113 def update(self, repo, rev):
103 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) 114 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo)
104 115
105 def ignore(self, target, repo): 116 def ignore(self, target, repo):
106 module = os.path.relpath(target, repo) 117 module = os.path.relpath(target, repo)
107 exclude_file = os.path.join(repo, ".git", "info", "exclude") 118 exclude_file = os.path.join(repo, ".git", "info", "exclude")
108 _ensure_line_exists(exclude_file, module) 119 _ensure_line_exists(exclude_file, module)
109 120
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 args = parser.parse_args() 314 args = parser.parse_args()
304 315
305 if args.quiet: 316 if args.quiet:
306 logging.disable(logging.INFO) 317 logging.disable(logging.INFO)
307 318
308 repos = args.repos 319 repos = args.repos
309 if not len(repos): 320 if not len(repos):
310 repos = [os.path.dirname(__file__)] 321 repos = [os.path.dirname(__file__)]
311 for repo in repos: 322 for repo in repos:
312 resolve_deps(repo) 323 resolve_deps(repo)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld