diff options
author | Dan Willemsen <dwillemsen@google.com> | 2015-10-06 15:23:19 -0700 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2015-10-07 15:43:22 -0700 |
commit | 745b4ad660f8050045b521c4e15b7d3ac0b3d70e (patch) | |
tree | 643e836eafdde0c08e1eec540eab6ae23b2ef29e /repo | |
parent | 4c5f74e4521679d1dcc31c575d417387b9c51c87 (diff) | |
download | git-repo-745b4ad660f8050045b521c4e15b7d3ac0b3d70e.tar.gz |
Fix gitc-init behaviorv1.12.32
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
Diffstat (limited to 'repo')
-rwxr-xr-x | repo | 38 |
1 files changed, 34 insertions, 4 deletions
@@ -109,6 +109,7 @@ 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_CONFIG_FILE = '/gitc/.config' | 111 | GITC_CONFIG_FILE = '/gitc/.config' |
112 | GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' | ||
112 | 113 | ||
113 | 114 | ||
114 | import errno | 115 | import errno |
@@ -221,7 +222,7 @@ def _GitcInitOptions(init_optparse): | |||
221 | help='Optional manifest file to use for this GITC client.') | 222 | help='Optional manifest file to use for this GITC client.') |
222 | g.add_option('-c', '--gitc-client', | 223 | g.add_option('-c', '--gitc-client', |
223 | dest='gitc_client', | 224 | dest='gitc_client', |
224 | help='The name for the new gitc_client instance.') | 225 | help='The name of the gitc_client instance to create or modify.') |
225 | 226 | ||
226 | _gitc_manifest_dir = None | 227 | _gitc_manifest_dir = None |
227 | def get_gitc_manifest_dir(): | 228 | def get_gitc_manifest_dir(): |
@@ -238,6 +239,28 @@ def get_gitc_manifest_dir(): | |||
238 | pass | 239 | pass |
239 | return _gitc_manifest_dir | 240 | return _gitc_manifest_dir |
240 | 241 | ||
242 | def gitc_parse_clientdir(gitc_fs_path): | ||
243 | """Parse a path in the GITC FS and return its client name. | ||
244 | |||
245 | @param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR. | ||
246 | |||
247 | @returns: The GITC client name | ||
248 | """ | ||
249 | if gitc_fs_path == GITC_FS_ROOT_DIR: | ||
250 | return None | ||
251 | if not gitc_fs_path.startswith(GITC_FS_ROOT_DIR): | ||
252 | manifest_dir = get_gitc_manifest_dir() | ||
253 | if manifest_dir == '': | ||
254 | return None | ||
255 | if manifest_dir[-1] != '/': | ||
256 | manifest_dir += '/' | ||
257 | if gitc_fs_path == manifest_dir: | ||
258 | return None | ||
259 | if not gitc_fs_path.startswith(manifest_dir): | ||
260 | return None | ||
261 | return gitc_fs_path.split(manifest_dir)[1].split('/')[0] | ||
262 | return gitc_fs_path.split(GITC_FS_ROOT_DIR)[1].split('/')[0] | ||
263 | |||
241 | class CloneFailure(Exception): | 264 | class CloneFailure(Exception): |
242 | """Indicate the remote clone of repo itself failed. | 265 | """Indicate the remote clone of repo itself failed. |
243 | """ | 266 | """ |
@@ -276,10 +299,13 @@ def _Init(args, gitc_init=False): | |||
276 | _print('fatal: GITC filesystem is not available. Exiting...', | 299 | _print('fatal: GITC filesystem is not available. Exiting...', |
277 | file=sys.stderr) | 300 | file=sys.stderr) |
278 | sys.exit(1) | 301 | sys.exit(1) |
279 | if not opt.gitc_client: | 302 | gitc_client = opt.gitc_client |
303 | if not gitc_client: | ||
304 | gitc_client = gitc_parse_clientdir(os.getcwd()) | ||
305 | if not gitc_client: | ||
280 | _print('fatal: GITC client (-c) is required.', file=sys.stderr) | 306 | _print('fatal: GITC client (-c) is required.', file=sys.stderr) |
281 | sys.exit(1) | 307 | sys.exit(1) |
282 | client_dir = os.path.join(gitc_manifest_dir, opt.gitc_client) | 308 | client_dir = os.path.join(gitc_manifest_dir, gitc_client) |
283 | if not os.path.exists(client_dir): | 309 | if not os.path.exists(client_dir): |
284 | os.makedirs(client_dir) | 310 | os.makedirs(client_dir) |
285 | os.chdir(client_dir) | 311 | os.chdir(client_dir) |
@@ -772,9 +798,13 @@ def _SetDefaultsTo(gitdir): | |||
772 | 798 | ||
773 | 799 | ||
774 | def main(orig_args): | 800 | def main(orig_args): |
775 | repo_main, rel_repo_dir = _FindRepo() | ||
776 | cmd, opt, args = _ParseArguments(orig_args) | 801 | cmd, opt, args = _ParseArguments(orig_args) |
777 | 802 | ||
803 | repo_main, rel_repo_dir = None, None | ||
804 | # Don't use the local repo copy, make sure to switch to the gitc client first. | ||
805 | if cmd != 'gitc-init': | ||
806 | repo_main, rel_repo_dir = _FindRepo() | ||
807 | |||
778 | wrapper_path = os.path.abspath(__file__) | 808 | wrapper_path = os.path.abspath(__file__) |
779 | my_main, my_git = _RunSelf(wrapper_path) | 809 | my_main, my_git = _RunSelf(wrapper_path) |
780 | 810 | ||