2365 share safe feature. |
2365 share safe feature. |
2366 |
2366 |
2367 Returns 0 on success, 1 if NAME does not exist. |
2367 Returns 0 on success, 1 if NAME does not exist. |
2368 |
2368 |
2369 """ |
2369 """ |
2370 |
2370 edit_level = config_command.find_edit_level(ui, repo, opts) |
2371 editopts = ('edit', 'local', 'global', 'shared', 'non_shared') |
2371 if edit_level is not None: |
2372 if any(opts.get(o) for o in editopts): |
2372 return config_command.edit_config(ui, repo, edit_level) |
2373 cmdutil.check_at_most_one_arg(opts, *editopts[1:]) |
|
2374 if opts.get('local'): |
|
2375 if not repo: |
|
2376 raise error.InputError( |
|
2377 _(b"can't use --local outside a repository") |
|
2378 ) |
|
2379 paths = [repo.vfs.join(b'hgrc')] |
|
2380 elif opts.get('global'): |
|
2381 paths = rcutil.systemrcpath() |
|
2382 elif opts.get('shared'): |
|
2383 if not repo.shared(): |
|
2384 raise error.InputError( |
|
2385 _(b"repository is not shared; can't use --shared") |
|
2386 ) |
|
2387 if requirements.SHARESAFE_REQUIREMENT not in repo.requirements: |
|
2388 raise error.InputError( |
|
2389 _( |
|
2390 b"share safe feature not enabled; " |
|
2391 b"unable to edit shared source repository config" |
|
2392 ) |
|
2393 ) |
|
2394 paths = [vfsmod.vfs(repo.sharedpath).join(b'hgrc')] |
|
2395 elif opts.get('non_shared'): |
|
2396 paths = [repo.vfs.join(b'hgrc-not-shared')] |
|
2397 else: |
|
2398 paths = rcutil.userrcpath() |
|
2399 |
|
2400 for f in paths: |
|
2401 if os.path.exists(f): |
|
2402 break |
|
2403 else: |
|
2404 if opts.get('global'): |
|
2405 samplehgrc = uimod.samplehgrcs[b'global'] |
|
2406 elif opts.get('local'): |
|
2407 samplehgrc = uimod.samplehgrcs[b'local'] |
|
2408 else: |
|
2409 samplehgrc = uimod.samplehgrcs[b'user'] |
|
2410 |
|
2411 f = paths[0] |
|
2412 util.writefile(f, util.tonativeeol(samplehgrc)) |
|
2413 |
|
2414 editor = ui.geteditor() |
|
2415 ui.system( |
|
2416 b"%s \"%s\"" % (editor, f), |
|
2417 onerr=error.InputError, |
|
2418 errprefix=_(b"edit failed"), |
|
2419 blockedtag=b'config_edit', |
|
2420 ) |
|
2421 return |
|
2422 ui.pager(b'config') |
2373 ui.pager(b'config') |
2423 fm = ui.formatter(b'config', pycompat.byteskwargs(opts)) |
2374 fm = ui.formatter(b'config', pycompat.byteskwargs(opts)) |
2424 for t, f in rcutil.rccomponents(): |
2375 for t, f in rcutil.rccomponents(): |
2425 if t == b'path': |
2376 if t == b'path': |
2426 ui.debug(b'read config from: %s\n' % f) |
2377 ui.debug(b'read config from: %s\n' % f) |