Mercurial > dotfiles
diff 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 |
line wrap: on
line diff
--- a/install.py Sun Nov 14 21:59:48 2021 -0800 +++ b/install.py Wed May 04 15:03:48 2022 -0700 @@ -1,5 +1,6 @@ import os import os.path +import re import sys import stat import shutil @@ -164,8 +165,8 @@ path = os.path.join(bundle_dir, name) if url.startswith('[local]'): pass - elif url.startswith('[git]'): - clone_git(url[len('[git]'):], path, force=force) + elif url.startswith('[git'): + clone_git(url, path, force=force) else: clone_hg(url, path, force=force) print() @@ -348,11 +349,19 @@ return True +re_git_url_prefix = re.compile(r'^\[git(\:(?P<branch>[^\]]+))?\](?P<url>.*)$') + +# TODO: support for submodules def clone_git(url, path, force=False): + m = re_git_url_prefix.match(url) + if not m: + raise Exception("Not a git url: %s" % url) + url, branch = m.group('url'), (m.group('branch') or 'master') + if _is_non_empty_dir_with(path, '.git'): if not force: - print("git pull origin master %s" % path) - subprocess.check_call(['git', 'pull', 'origin', 'master'], + print("git pull origin %s %s" % (branch, path)) + subprocess.check_call(['git', 'pull', 'origin', branch], cwd=path) return else: @@ -390,8 +399,8 @@ for path, url in cfg.items('subrepos'): full_path = _p(path) - if url.startswith('[git]'): - clone_git(url[len('[git]'):], full_path, force=force) + if url.startswith('[git'): + clone_git(url, full_path, force=force) else: clone_hg(url, full_path, force=force) print()