Mercurial > dotfiles
comparison install.py @ 514:fc35cae2fb52
Support other branches than master for git repos
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 04 May 2022 15:03:48 -0700 |
parents | b8eeae888aab |
children | 6d5e2a583502 |
comparison
equal
deleted
inserted
replaced
513:b8eeae888aab | 514:fc35cae2fb52 |
---|---|
1 import os | 1 import os |
2 import os.path | 2 import os.path |
3 import re | |
3 import sys | 4 import sys |
4 import stat | 5 import stat |
5 import shutil | 6 import shutil |
6 import argparse | 7 import argparse |
7 import functools | 8 import functools |
162 | 163 |
163 for name, url in cfg.items(cfg_section_name): | 164 for name, url in cfg.items(cfg_section_name): |
164 path = os.path.join(bundle_dir, name) | 165 path = os.path.join(bundle_dir, name) |
165 if url.startswith('[local]'): | 166 if url.startswith('[local]'): |
166 pass | 167 pass |
167 elif url.startswith('[git]'): | 168 elif url.startswith('[git'): |
168 clone_git(url[len('[git]'):], path, force=force) | 169 clone_git(url, path, force=force) |
169 else: | 170 else: |
170 clone_hg(url, path, force=force) | 171 clone_hg(url, path, force=force) |
171 print() | 172 print() |
172 | 173 |
173 existing_plugins.pop(name, None) | 174 existing_plugins.pop(name, None) |
346 if not os.path.exists(os.path.join(path, cnt)): | 347 if not os.path.exists(os.path.join(path, cnt)): |
347 return False | 348 return False |
348 return True | 349 return True |
349 | 350 |
350 | 351 |
352 re_git_url_prefix = re.compile(r'^\[git(\:(?P<branch>[^\]]+))?\](?P<url>.*)$') | |
353 | |
354 # TODO: support for submodules | |
351 def clone_git(url, path, force=False): | 355 def clone_git(url, path, force=False): |
356 m = re_git_url_prefix.match(url) | |
357 if not m: | |
358 raise Exception("Not a git url: %s" % url) | |
359 url, branch = m.group('url'), (m.group('branch') or 'master') | |
360 | |
352 if _is_non_empty_dir_with(path, '.git'): | 361 if _is_non_empty_dir_with(path, '.git'): |
353 if not force: | 362 if not force: |
354 print("git pull origin master %s" % path) | 363 print("git pull origin %s %s" % (branch, path)) |
355 subprocess.check_call(['git', 'pull', 'origin', 'master'], | 364 subprocess.check_call(['git', 'pull', 'origin', branch], |
356 cwd=path) | 365 cwd=path) |
357 return | 366 return |
358 else: | 367 else: |
359 print("Deleting existing: %s" % path) | 368 print("Deleting existing: %s" % path) |
360 shutil.rmtree(path, onerror=_on_error_try_make_readable) | 369 shutil.rmtree(path, onerror=_on_error_try_make_readable) |
388 if not cfg.has_section('subrepos'): | 397 if not cfg.has_section('subrepos'): |
389 return | 398 return |
390 | 399 |
391 for path, url in cfg.items('subrepos'): | 400 for path, url in cfg.items('subrepos'): |
392 full_path = _p(path) | 401 full_path = _p(path) |
393 if url.startswith('[git]'): | 402 if url.startswith('[git'): |
394 clone_git(url[len('[git]'):], full_path, force=force) | 403 clone_git(url, full_path, force=force) |
395 else: | 404 else: |
396 clone_hg(url, full_path, force=force) | 405 clone_hg(url, full_path, force=force) |
397 print() | 406 print() |
398 | 407 |
399 | 408 |