Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command alias doesn't work in repo-level config #2414

Closed
martinvonz opened this issue Oct 22, 2023 · 2 comments
Closed

Command alias doesn't work in repo-level config #2414

martinvonz opened this issue Oct 22, 2023 · 2 comments
Labels
🐛bug Something isn't working

Comments

@martinvonz
Copy link
Owner

martinvonz commented Oct 22, 2023

Description

I'm filing this on @ppwwyyxx's behalf. Copying from #982 (comment):

This is what I got:

❯ 14:18 cd $(mktemp -d) ; jj init --git
Initialized repo in "."
❯ 14:18 echo 'aliases.foo = ["diff"]' > .jj/repo/config.toml
❯ 14:18 jj config list aliases.foo
❯ 14:18 jj config --no-pager list aliases.foo
aliases.foo=["diff"]
❯ 14:18 jj foo
error: unrecognized subcommand 'foo'

Usage: jj [OPTIONS] [COMMAND]

For more information, try '--help'.

Specifications

  • Platform: unknown
  • Version: 0.10.0-8dbe12da2a6d771d3409b19b76bf0f8781e6b218
@martinvonz
Copy link
Owner Author

I have no idea what the problem could be here. @ppwwyyxx, can you think of anything unusual in your setup? What else do you have in your config? Is jj a shell alias? What shell do you use?

@yuja
Copy link
Collaborator

yuja commented Oct 23, 2023

There's a TODO about this. The repository path isn't determined until the command arguments gets parsed.

jj/cli/src/cli_util.rs

Lines 2783 to 2802 in 171896a

let config = layered_configs.merge();
ui.reset(&config)?;
let string_args = expand_args(ui, &self.app, std::env::args_os(), &config)?;
let (matches, args) = parse_args(
ui,
&self.app,
&self.tracing_subscription,
&string_args,
&mut layered_configs,
)?;
for process_global_args_fn in self.process_global_args_fns {
process_global_args_fn(ui, &matches)?;
}
let maybe_workspace_loader = init_workspace_loader(&cwd, &args.global_args);
if let Ok(loader) = &maybe_workspace_loader {
// TODO: maybe show error/warning if repo config contained command alias
layered_configs.read_repo_config(loader.repo_path())?;
}
let config = layered_configs.merge();

Possible workarounds:

  • show warning (as the comment says)
  • load temporary repo config from cwd and use it only for command alias expansion
  • parse command arguments without aliases as much as possible, and use -R to load temporary repo config

In any case, it's better to show warning if the repository path was different from the one we use for alias expansion.

@PhilipMetzger PhilipMetzger added the 🐛bug Something isn't working label Oct 25, 2023
yuja added a commit to yuja/jj that referenced this issue Dec 23, 2023
… aliases

This is basically the same as Mercurial's workaround. I don't know about Git,
but arguments order is very restricted in git, so -C path can be parsed prior
to alias expansion. In hg and jj, doing that would be messy and unreliable.

Closes martinvonz#2414
yuja added a commit to yuja/jj that referenced this issue Dec 23, 2023
… aliases

This is basically the same as Mercurial's workaround. I don't know about Git,
but arguments order is very restricted in git, so -C path can be parsed prior
to alias expansion. In hg and jj, doing that would be messy and unreliable.

Closes martinvonz#2414
yuja added a commit to yuja/jj that referenced this issue Dec 23, 2023
… aliases

This is basically the same as Mercurial's workaround. I don't know about Git,
but arguments order is very restricted in git, so -C path can be parsed prior
to alias expansion. In hg and jj, doing that would be messy and unreliable.

Closes martinvonz#2414
@yuja yuja closed this as completed in 30b5e88 Dec 23, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 8, 2024
## [0.13.0] - 2024-01-03

### Breaking changes

* `jj git fetch` no longer imports new remote branches as local branches. Set
  `git.auto-local-branch = true` to restore the old behavior.

### New features

* Information about new and resolved conflicts is now printed by every command.

* `jj branch` has gained a new `rename` subcommand that allows changing a branch
  name atomically. `jj branch help rename` for details.

### Fixed bugs

* Command aliases can now be loaded from repository config relative to the
  current working directory.
  [#2414](martinvonz/jj#2414)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants