summaryrefslogtreecommitdiffstats
path: root/subcmds/init.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-08-27 01:10:59 -0400
committerMike Frysinger <vapier@google.com>2019-08-28 03:54:11 +0000
commitae6cb08ae52d488a4cc6892f811c1c1acf8c3c12 (patch)
treec927415df288d9bf9076e758835db53cc633597d /subcmds/init.py
parent3fc157285cb61d6a4faa55dc4f011fb94d598c20 (diff)
downloadgit-repo-ae6cb08ae52d488a4cc6892f811c1c1acf8c3c12.tar.gz
split out cli validation from executionv1.13.5
A common pattern in our subcommands is to verify the arguments & options before executing things. For some subcommands, that check stage is quite long which makes the execution function even bigger. Lets split that logic out of the execute phase so it's easier to manage these. This is most noticeable in the sync subcommand whose Execute func is quite large, and the option checking makes up ~15% of it. The manifest command's Execute can be simplified significantly as the optparse configuration always sets output_file to a string. Change-Id: I7097847ff040e831345e63de6b467ee17609990e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/234834 Reviewed-by: David Pursehouse <dpursehouse@collab.net> Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'subcmds/init.py')
-rw-r--r--subcmds/init.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/subcmds/init.py b/subcmds/init.py
index eaa6da50..32663a04 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -436,18 +436,17 @@ to update the working directory files.
436 print(' rm -r %s/.repo' % self.manifest.topdir) 436 print(' rm -r %s/.repo' % self.manifest.topdir)
437 print('and try again.') 437 print('and try again.')
438 438
439 def Execute(self, opt, args): 439 def ValidateOptions(self, opt, args):
440 git_require(MIN_GIT_VERSION, fail=True)
441
442 if opt.reference: 440 if opt.reference:
443 opt.reference = os.path.expanduser(opt.reference) 441 opt.reference = os.path.expanduser(opt.reference)
444 442
445 # Check this here, else manifest will be tagged "not new" and init won't be 443 # Check this here, else manifest will be tagged "not new" and init won't be
446 # possible anymore without removing the .repo/manifests directory. 444 # possible anymore without removing the .repo/manifests directory.
447 if opt.archive and opt.mirror: 445 if opt.archive and opt.mirror:
448 print('fatal: --mirror and --archive cannot be used together.', 446 self.OptionParser.error('--mirror and --archive cannot be used together.')
449 file=sys.stderr) 447
450 sys.exit(1) 448 def Execute(self, opt, args):
449 git_require(MIN_GIT_VERSION, fail=True)
451 450
452 self._SyncManifest(opt) 451 self._SyncManifest(opt)
453 self._LinkManifest(opt.manifest_name) 452 self._LinkManifest(opt.manifest_name)