diff options
| author | Dan Willemsen <dwillemsen@google.com> | 2015-08-12 23:25:20 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-08-12 23:25:20 +0000 |
| commit | 5d0c3a614edc3f3d5967cfc07c7981da7013ea91 (patch) | |
| tree | 8429fdb99432ff237a45a79d7ae126ad8098fa6c /repo | |
| parent | 2635c0e3b6d0fb7a48d892fe9528197eb13bc98b (diff) | |
| parent | 1efc2b4a0157b5c23317e5e7a51643016133cff5 (diff) | |
| download | git-repo-5d0c3a614edc3f3d5967cfc07c7981da7013ea91.tar.gz | |
Merge "GITC: Add gitc-init subcommand to repo."
Diffstat (limited to 'repo')
| -rwxr-xr-x | repo | 27 |
1 files changed, 24 insertions, 3 deletions
| @@ -108,6 +108,7 @@ S_repo = 'repo' # special repo repository | |||
| 108 | S_manifests = 'manifests' # special manifest repository | 108 | S_manifests = 'manifests' # special manifest repository |
| 109 | REPO_MAIN = S_repo + '/main.py' # main script | 109 | REPO_MAIN = S_repo + '/main.py' # main script |
| 110 | MIN_PYTHON_VERSION = (2, 6) # minimum supported python version | 110 | MIN_PYTHON_VERSION = (2, 6) # minimum supported python version |
| 111 | GITC_MANIFEST_DIR = '/usr/local/google/gitc' | ||
| 111 | 112 | ||
| 112 | 113 | ||
| 113 | import errno | 114 | import errno |
| @@ -212,14 +213,25 @@ group.add_option('--config-name', | |||
| 212 | dest='config_name', action="store_true", default=False, | 213 | dest='config_name', action="store_true", default=False, |
| 213 | help='Always prompt for name/e-mail') | 214 | help='Always prompt for name/e-mail') |
| 214 | 215 | ||
| 216 | def _GitcInitOptions(init_optparse): | ||
| 217 | g = init_optparse.add_option_group('GITC options') | ||
| 218 | g.add_option('-f', '--manifest-file', | ||
| 219 | dest='manifest_file', | ||
| 220 | help='Optional manifest file to use for this GITC client.') | ||
| 221 | g.add_option('-c', '--gitc-client', | ||
| 222 | dest='gitc_client', | ||
| 223 | help='The name for the new gitc_client instance.') | ||
| 224 | |||
| 215 | class CloneFailure(Exception): | 225 | class CloneFailure(Exception): |
| 216 | """Indicate the remote clone of repo itself failed. | 226 | """Indicate the remote clone of repo itself failed. |
| 217 | """ | 227 | """ |
| 218 | 228 | ||
| 219 | 229 | ||
| 220 | def _Init(args): | 230 | def _Init(args, gitc_init=False): |
| 221 | """Installs repo by cloning it over the network. | 231 | """Installs repo by cloning it over the network. |
| 222 | """ | 232 | """ |
| 233 | if gitc_init: | ||
| 234 | _GitcInitOptions(init_optparse) | ||
| 223 | opt, args = init_optparse.parse_args(args) | 235 | opt, args = init_optparse.parse_args(args) |
| 224 | if args: | 236 | if args: |
| 225 | init_optparse.print_usage() | 237 | init_optparse.print_usage() |
| @@ -242,6 +254,15 @@ def _Init(args): | |||
| 242 | raise CloneFailure() | 254 | raise CloneFailure() |
| 243 | 255 | ||
| 244 | try: | 256 | try: |
| 257 | if gitc_init: | ||
| 258 | client_dir = os.path.join(GITC_MANIFEST_DIR, opt.gitc_client) | ||
| 259 | if not os.path.exists(client_dir): | ||
| 260 | os.makedirs(client_dir) | ||
| 261 | os.chdir(client_dir) | ||
| 262 | if os.path.exists(repodir): | ||
| 263 | # This GITC Client has already initialized repo so continue. | ||
| 264 | return | ||
| 265 | |||
| 245 | os.mkdir(repodir) | 266 | os.mkdir(repodir) |
| 246 | except OSError as e: | 267 | except OSError as e: |
| 247 | if e.errno != errno.EEXIST: | 268 | if e.errno != errno.EEXIST: |
| @@ -732,11 +753,11 @@ def main(orig_args): | |||
| 732 | _Help(args) | 753 | _Help(args) |
| 733 | if not cmd: | 754 | if not cmd: |
| 734 | _NotInstalled() | 755 | _NotInstalled() |
| 735 | if cmd == 'init': | 756 | if cmd == 'init' or cmd == 'gitc-init': |
| 736 | if my_git: | 757 | if my_git: |
| 737 | _SetDefaultsTo(my_git) | 758 | _SetDefaultsTo(my_git) |
| 738 | try: | 759 | try: |
| 739 | _Init(args) | 760 | _Init(args, gitc_init=(cmd == 'gitc-init')) |
| 740 | except CloneFailure: | 761 | except CloneFailure: |
| 741 | shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True) | 762 | shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True) |
| 742 | sys.exit(1) | 763 | sys.exit(1) |
