From 745b4ad660f8050045b521c4e15b7d3ac0b3d70e Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Tue, 6 Oct 2015 15:23:19 -0700 Subject: Fix gitc-init behavior With gitc-init, a gitc client may be specified using '-c'. If we're not currently in that client, we need to change directories so that we don't affect the local checkout, and to ensure that repo is checked out in the new client. This also makes '-c' optional if already in a gitc client, to match the rest of the init options. Change-Id: Ib514ad9fd101698060ae89bb035499800897e9bd --- subcmds/gitc_init.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'subcmds/gitc_init.py') diff --git a/subcmds/gitc_init.py b/subcmds/gitc_init.py index 4f9d7344..2726eaec 100644 --- a/subcmds/gitc_init.py +++ b/subcmds/gitc_init.py @@ -21,6 +21,7 @@ import gitc_utils from command import GitcAvailableCommand from manifest_xml import GitcManifest from subcmds import init +import wrapper class GitcInit(init.Init, GitcAvailableCommand): @@ -55,18 +56,15 @@ use for this GITC client. help='Optional manifest file to use for this GITC client.') g.add_option('-c', '--gitc-client', dest='gitc_client', - help='The name for the new gitc_client instance.') + help='The name of the gitc_client instance to create or modify.') def Execute(self, opt, args): - if not opt.gitc_client: - print('fatal: gitc client (-c) is required', file=sys.stderr) + gitc_client = gitc_utils.parse_clientdir(os.getcwd()) + if not gitc_client or (opt.gitc_client and gitc_client != opt.gitc_client): + print('fatal: Please update your repo command. See go/gitc for instructions.', file=sys.stderr) sys.exit(1) self.client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(), - opt.gitc_client) - if not os.path.exists(gitc_utils.get_gitc_manifest_dir()): - os.makedirs(gitc_utils.get_gitc_manifest_dir()) - if not os.path.exists(self.client_dir): - os.mkdir(self.client_dir) + gitc_client) super(GitcInit, self).Execute(opt, args) manifest_file = self.manifest.manifestFile @@ -77,8 +75,8 @@ use for this GITC client. sys.exit(1) manifest_file = opt.manifest_file - manifest = GitcManifest(self.repodir, opt.gitc_client) + manifest = GitcManifest(self.repodir, gitc_client) manifest.Override(manifest_file) gitc_utils.generate_gitc_manifest(None, manifest) print('Please run `cd %s` to view your GITC client.' % - os.path.join(gitc_utils.GITC_FS_ROOT_DIR, opt.gitc_client)) + os.path.join(wrapper.Wrapper().GITC_FS_ROOT_DIR, gitc_client)) -- cgit v1.2.3-54-g00ecf