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

Side by Side Diff: ensure_dependencies.py

Issue 29356341: Issue 4503 - ensure_dependencies.py fails for git submodule
Patch Set: Created Oct. 7, 2016, 11:54 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 config.read(config_path) 70 config.read(config_path)
71 71
72 if not config.has_section("ui"): 72 if not config.has_section("ui"):
73 config.add_section("ui") 73 config.add_section("ui")
74 74
75 config.set("ui", "ignore.dependencies", ignore_path) 75 config.set("ui", "ignore.dependencies", ignore_path)
76 with open(config_path, "w") as stream: 76 with open(config_path, "w") as stream:
77 config.write(stream) 77 config.write(stream)
78 78
79 module = os.path.relpath(target, repo) 79 module = os.path.relpath(target, repo)
80 _ensure_line_exists(ignore_path, module) 80 _ensure_line_exists(ignore_path, module)
anton 2016/10/07 19:11:43 probably should add try except here too
81 81
82 class Git(): 82 class Git():
83 def istype(self, repodir): 83 def istype(self, repodir):
84 return os.path.exists(os.path.join(repodir, ".git")) 84 return os.path.exists(os.path.join(repodir, ".git"))
85 85
86 def clone(self, source, target): 86 def clone(self, source, target):
87 source = source.rstrip("/") 87 source = source.rstrip("/")
88 if not source.endswith(".git"): 88 if not source.endswith(".git"):
89 source += ".git" 89 source += ".git"
90 subprocess.check_call(["git", "clone", "--quiet", source, target]) 90 subprocess.check_call(["git", "clone", "--quiet", source, target])
91 91
92 def get_revision_id(self, repo, rev="HEAD"): 92 def get_revision_id(self, repo, rev="HEAD"):
93 command = ["git", "rev-parse", "--revs-only", rev + '^{commit}'] 93 command = ["git", "rev-parse", "--revs-only", rev + '^{commit}']
94 return subprocess.check_output(command, cwd=repo).strip() 94 return subprocess.check_output(command, cwd=repo).strip()
95 95
96 def pull(self, repo): 96 def pull(self, repo):
97 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) 97 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po)
98 98
99 def update(self, repo, rev): 99 def update(self, repo, rev):
100 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) 100 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo)
101 101
102 def ignore(self, target, repo): 102 def ignore(self, target, repo):
103 module = os.path.relpath(target, repo) 103 module = os.path.relpath(target, repo)
104 exclude_file = os.path.join(repo, ".git", "info", "exclude") 104 exclude_file = os.path.join(repo, ".git", "info", "exclude")
105 _ensure_line_exists(exclude_file, module) 105 try:
106 _ensure_line_exists(exclude_file, module)
107 except IOError, e:
108 if e.errno != errno.ENOENT and e.errno != errno.ENOTDIR:
109 raise
110 logging.warning("File %s doesn't exist, skipping ignore" % exclude_file)
111 return
106 112
107 repo_types = OrderedDict(( 113 repo_types = OrderedDict((
108 ("hg", Mercurial()), 114 ("hg", Mercurial()),
109 ("git", Git()), 115 ("git", Git()),
110 )) 116 ))
111 117
112 def parse_spec(path, line): 118 def parse_spec(path, line):
113 if "=" not in line: 119 if "=" not in line:
114 logging.warning("Invalid line in file %s: %s" % (path, line)) 120 logging.warning("Invalid line in file %s: %s" % (path, line))
115 return None, None 121 return None, None
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 args = parser.parse_args() 296 args = parser.parse_args()
291 297
292 if args.quiet: 298 if args.quiet:
293 logging.disable(logging.INFO) 299 logging.disable(logging.INFO)
294 300
295 repos = args.repos 301 repos = args.repos
296 if not len(repos): 302 if not len(repos):
297 repos = [os.path.dirname(__file__)] 303 repos = [os.path.dirname(__file__)]
298 for repo in repos: 304 for repo in repos:
299 resolve_deps(repo) 305 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