8965 Commits

Author SHA1 Message Date
Yuya Nishihara
d46c384db2 changelog: remove redundant entry about macOS config path
It's documented as deprecation, and is not actually a "bug".
2025-05-05 13:15:10 +00:00
Daniel Luz
87f6db0a70 completion: revset expression completer 2025-05-05 02:54:51 +00:00
Yuya Nishihara
8936a7bc4b templater: unify property conversion traits
We could define separate traits for conversion "from" and "to", but there aren't
many users who benefit from precise trait bounds.
2025-05-05 01:16:41 +00:00
Yuya Nishihara
780f9e547d templater: call property wrap_() functions directly, delete old forwarding fns
This patch replaces single-char L type aliases with P, and renames the L aliases
where that makes sense. Many of the P aliases will be removed later by
introducing generic wrap<T>() trait.
2025-05-05 01:16:41 +00:00
Yuya Nishihara
b611c313aa templater: move non-core wrap_*() functions to property types, leverage macro
Since the return type is now Self, we can reuse impl_wrap_property_fns!() macro
for non-core types.
2025-05-05 01:16:41 +00:00
Yuya Nishihara
7643364a76 templater: move core wrap_*() functions to property wrapper type
I think this was remainder of the old design where wrap_*() functions took
&TemplateLanguage as self argument. Since the wrapper type implements accessor
functions like .try_into_boolean(), it makes sense that the same type implements
::wrap_boolean(), etc.

These .wrap_<T>() functions will become generic over T.
2025-05-05 01:16:41 +00:00
Yuya Nishihara
577a484d1d templater: remove unneeded trait bound from build_lambda_expression()
This function just passes P down to the build_body() callback transparently.
2025-05-05 01:16:41 +00:00
Nils Koch
deb4f1ba79 docs: update git compatibility docs for commit signing 2025-05-04 22:52:24 +00:00
Martin von Zweigbergk
103d05149d cli: add "$schema" line when creating new config file
It seems like a small usability improvement if users don't need to
enter the "$schema" link manually when they create a new config file.

This doesn't help existing users.
2025-05-04 17:14:10 +00:00
Nicole Patricia Mazzuca
05fa4bc0a3 docs: add some more info on signing
I was asked about this in Discord, so I wanted to make sure to have the
information available in the docs and not just the code.
2025-05-03 11:27:36 +00:00
Ilya Grigoriev
4f3d890bee docs cli reference: update and pin clap-markdown, include aliases in reference
clap-markdown doesn't follow semver, so I pinned the version exactly.
2025-05-03 00:35:12 +00:00
Nicole Patricia Mazzuca
b568bb67f0 config: deprecate macOS legacy platform configs 2025-05-02 20:05:24 +00:00
Nicole Patricia Mazzuca
6f6496ba83 config: default to XDG config files on macOS
Support existing users with the "legacy" config directory, as well.
This will be deprecated in a latter commit.
2025-05-02 20:05:24 +00:00
Nicole Patricia Mazzuca
f9966a644b config: switch to etcetera from dirs 2025-05-02 20:05:24 +00:00
Nicole Patricia Mazzuca
19f997a466 config: change how config paths are represented
This change, from an enum to a struct, is a more accurate representation
of the actual way that a ConfigPath works; additionally, it lets us add
different information without modifying every single enumeration field.
2025-05-02 20:05:24 +00:00
Steve Fink
0eceed9832 restore, diffedit: do not output "Created ..." message, which dates back to before we couldn't lookup by change id. 2025-05-01 21:11:31 +00:00
Yuya Nishihara
1b300fefa2 templater: add type alias for Box<dyn TemplateProperty<..>>
It's verbose to type.
2025-05-01 00:33:59 +00:00
Yuya Nishihara
b96924d17f templater: convert property to trait object by caller
I'm trying to refactor property wrapping functions, and noticed that it's odd
that .wrap_<property>() does boxing internally whereas .wrap_template() doesn't.

Also, it sometimes makes sense to turn property into trait object earlier. For
example, we can deduplicate L::wrap_boolean() in build_binary_operation().
2025-05-01 00:33:59 +00:00
Yuya Nishihara
96b633a091 templater: add property.into_dyn() helper
I'm going to move Box<dyn _> conversion to callers, so there will be more places
to use this helper.
2025-05-01 00:33:59 +00:00
Yuya Nishihara
533fb5e4bb generic_templater: remove unneeded lifetime bounds
Perhaps, these bounds were needed because the context type were compiled into
the template object before.
2025-05-01 00:33:59 +00:00
Théo Daron
3ab9e098d7 cli config edit: Rollback to previous config when invalid TOML is saved 2025-04-29 16:26:11 +00:00
Jonas Greitemann
928984019f completion: fix completion of arguments for aliases/default-command in bash and zsh
This also adds a test case for the completion of arguments following
multi-argument aliases, to cover the bug reported in issue #5377.

The default command is like a special kind of alias, one which is
expanded from zero tokens. Consequently, it also triggers the bug
#5377 on bash/zsh, even if the `default-command` is just a single token.

The fix is along the lines sketched out by the "TODO" comment. Bash and
Zsh don't behave identical, so the padding ([""]) still needs to be
applied (and removed) conditionally in a disciplined manner.
2025-04-29 14:38:25 +00:00
Jonas Greitemann
eaaaf058a8 completion tests: parameterize test case over different shells
The completion mechanism works differently in different shells:

For example, when the command line `jj aaa bb ccc` is completed at the
end of the `bb` token, bash and zsh pass the completer the whole line
`-- jj aaa bb ccc` and an index of 2 which refers to the `bb` token;
they are then expected to complete `bb`. Meanwhile, fish and Powershell
only pass the command up to the completion point, so `-- jj aaa bb`;
the completer is always expected to complete the last token. In all
cases, the shell ultimately decides what to do with the completions,
e.g. to complete up to a common prefix (bash), to show an interactive
picker (zsh, fish), or to insert the completion if it is the only one
(all shells). Remaining tokens (`ccc`) are also always appended by the
shell and not part of the completion.

While this is mostly handled by the clap_complete crate, we do expand
aliases and present clap_complete with a fake view of the real command
line, thereby reaching into its internals by wrapping the interface
between the completion shell script that is provided by clap_complete
and its Rust code in `CommandEnv::try_complete()`. If we get this wrong,
completion might yield unexpected results, so it is worth testing
completion for both flavors of shells whenever aliases are potentially
in the mix.

To avoid redundancy, the shell-specific invocation of `jj` is factored
into a `complete_at()` function of the test fixture. The `test-case`
crate is then used to instantiate each test case for different values of
clap_complete's `Shell` enum.

filter

bash/zsh specific behavior

move impl
2025-04-29 14:38:25 +00:00
Gaëtan Lehmann
2c4a0328f9 templates: add self.trailers().contains_key(key)
as a simpler and more readable alternative to

    self.trailers().filter(|t| t.key() == "Change-Id")
2025-04-29 06:36:12 +00:00
Martin von Zweigbergk
b7489aac81 CliRunner: don't require hook functions to have static lifetime
I want to pass in a closure that captures some variables in the local
scope of my `main()` function.
2025-04-29 04:22:47 +00:00
Martin von Zweigbergk
4435fae3be CliRunner: replace start hook by dispatch hook
The `CliRunner` lets a custom binary add processing that should happen
before running a command. This patch replaces that by a hook that can
do processing before and/or after. I thought I would want to use this
for adding telemetry (such as timings) to our custom binary at
Google. I ended up adding that logging outside of `CliRunner::run()`
instead, so it gives a more accurate timing of the whole invocation. I
think this patch is still an improvement, as it's more generic than
the start hook.
2025-04-29 02:49:12 +00:00
dependabot[bot]
517292fd46 cargo: bump the cargo-dependencies group with 3 updates
Bumps the cargo-dependencies group with 3 updates: [insta](https://github.com/mitsuhiko/insta), [syn](https://github.com/dtolnay/syn) and [toml_edit](https://github.com/toml-rs/toml).


Updates `insta` from 1.42.2 to 1.43.0
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.42.2...1.43.0)

Updates `syn` from 2.0.100 to 2.0.101
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/2.0.100...2.0.101)

Updates `toml_edit` from 0.22.24 to 0.22.25
- [Commits](https://github.com/toml-rs/toml/compare/v0.22.24...v0.22.25)

---
updated-dependencies:
- dependency-name: insta
  dependency-version: 1.43.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cargo-dependencies
- dependency-name: syn
  dependency-version: 2.0.101
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
- dependency-name: toml_edit
  dependency-version: 0.22.25
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-28 19:24:18 +00:00
dependabot[bot]
b2636dd9fa github: bump the github-dependencies group with 5 updates
Bumps the github-dependencies group with 5 updates:

| Package | From | To |
| --- | --- | --- |
| [taiki-e/install-action](https://github.com/taiki-e/install-action) | `2.49.50` | `2.50.3` |
| [DeterminateSystems/nix-installer-action](https://github.com/determinatesystems/nix-installer-action) | `16` | `17` |
| [actions/setup-python](https://github.com/actions/setup-python) | `5.5.0` | `5.6.0` |
| [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv) | `5.4.2` | `6.0.0` |
| [github/codeql-action](https://github.com/github/codeql-action) | `3.28.15` | `3.28.16` |


Updates `taiki-e/install-action` from 2.49.50 to 2.50.3
- [Release notes](https://github.com/taiki-e/install-action/releases)
- [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md)
- [Commits](09dc018eee...ab3728c7ba)

Updates `DeterminateSystems/nix-installer-action` from 16 to 17
- [Release notes](https://github.com/determinatesystems/nix-installer-action/releases)
- [Commits](e50d5f73bf...21a544727d)

Updates `actions/setup-python` from 5.5.0 to 5.6.0
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](8d9ed9ac5c...a26af69be9)

Updates `astral-sh/setup-uv` from 5.4.2 to 6.0.0
- [Release notes](https://github.com/astral-sh/setup-uv/releases)
- [Commits](d4b2f3b6ec...c7f87aa956)

Updates `github/codeql-action` from 3.28.15 to 3.28.16
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](45775bd823...28deaeda66)

---
updated-dependencies:
- dependency-name: taiki-e/install-action
  dependency-version: 2.50.3
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-dependencies
- dependency-name: DeterminateSystems/nix-installer-action
  dependency-version: '17'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-dependencies
- dependency-name: actions/setup-python
  dependency-version: 5.6.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-dependencies
- dependency-name: astral-sh/setup-uv
  dependency-version: 6.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-dependencies
- dependency-name: github/codeql-action
  dependency-version: 3.28.16
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-28 19:24:08 +00:00
Yuya Nishihara
4f3e7e972d templater: don't attribute method table functions as pub
It's unlikely that these functions are used by external callers.
2025-04-28 01:37:49 +00:00
Yuya Nishihara
27a35a79b1 merge-tools: builtin: refactor mapping of binary files
We no longer need this, but I think this is easier to follow than destructuring
FileContents in larger match block.
2025-04-28 01:37:45 +00:00
Mateus Auler
968806bc64 templates: implement Commit.trailers() 2025-04-27 18:29:25 +00:00
Yuya Nishihara
6e67d79c10 merge-tools: builtin: parse conflict hunks back to merge value
Closes #4963
2025-04-27 01:33:48 +00:00
Yuya Nishihara
acb4e27bd9 merge-tools: builtin: split apply_diff_builtin() function
In builtin diff editor, we materializes conflicts, so we need to parse them
back to reproduce the original (or partially-resolved) contents. OTOH, the
merge editor should write the merged contents transparently.

This change also revealed that binary hunks wouldn't be processed correctly in
the merge editor.
2025-04-27 01:33:48 +00:00
Yuya Nishihara
105c892ce4 tests: do not shell out taplo to gather forgotten test files
It would be annoying if forgotten tests wouldn't be reported locally.
2025-04-27 01:33:23 +00:00
Ilya Grigoriev
5a735182ac docs conflicts.md: clarify the revert example a bit
Yuya's suggestion from
<https://github.com/jj-vcs/jj/pull/6415#discussion_r2061122640>.

Co-authored-by:  Yuya Nishihara <yuya@tcha.org>
2025-04-27 00:40:27 +00:00
Ilya Grigoriev
1f14f7a0ff docs conflicts.md: fix confusing typo
Fix #6414.
2025-04-27 00:40:27 +00:00
Martin von Zweigbergk
13477940af local_working_copy: avoid a block_on() in already async function 2025-04-26 02:22:23 +00:00
Yuya Nishihara
a3dcd8b659 merge-tools: builtin: leverage materialized_diff_stream() 2025-04-26 02:05:40 +00:00
Yuya Nishihara
be37209423 merge-tools: builtin: do not include unchanged entry in test diffs, sort paths
This matches the edit_diff_builtin() behavior. "unused" path is removed since
it's the same as "unchanged".
2025-04-26 02:05:40 +00:00
Yuya Nishihara
9c723a1c76 merge-tools: builtin: extract wrapper functions in tests
make_diff_files() will be async function that uses materialized_diff_stream()
internally. apply_diff_builtin() will take callbacks to handle binary/conflict
files.
2025-04-26 02:05:40 +00:00
Jacob Hayes
1cdd79071e git: tolerate unknown git.fetch remotes if others are available
If `git.fetch` contains remotes that are not available, we currently error even
if other remotes are available. For common fork workflows with separate
`upstream` and `origin` remotes (for example), this requires a user to either
set both remotes in their user config and override single-remote repos or set
only one in their user config and override all multi-remote repos to fetch from
`upstream` (or both).

This change updates fetching to only *warn* about unknown remotes **if** other
remotes are available. If none of the configured remotes are available, an error
is still raised as before.
2025-04-25 14:06:53 +00:00
Martin von Zweigbergk
92629ded4c docs: make technical conflicts doc better match our recent thinking
These days, we usually think of conflicts as one base state and series
of diffs between other states. The base state is normally the parent
when rebasing.

Also, we're deprecated `jj backout` in favor of `jj revert`, so let's
use that terminology.
2025-04-25 13:53:28 +00:00
Martin von Zweigbergk
146900a071 cli: put editor-*.jjdescription file in /tmp instead of .jj/repo/
When we ask the user to prodive a commit description, we currently
write a file to `.jj/repo/` with the draft description and then pass
that to the editor. If the editor exits with an error status, we leave
the file in place and tell the user about the path so they can recover
the description. I'm not sure I've ever used one of these files. I
have certainly never used a file that's not from the most recent
edit. I have, however, cleaned up old such files. This patch changes
the code so we write them to /tmp instead, so we get the cleanup for
free.
2025-04-25 02:08:30 +00:00
Martin von Zweigbergk
d41c83e96a merged_tree: make merge_trees() async
`merge_tree_values()` was already marked async, but it was calling the
blocking `merge_trees()`, so it could still block.
2025-04-24 16:29:24 +00:00
Jonas Greitemann
7bb8e17e88 tests: factor out utility function is_external_tool_installed
A pattern has emerged where a integration tests check for the
availability of an external tool (`git`, `taplo`, `gpg`, ...) and skip
the test (by simply passing it) when it is not available. To check this,
the program is run with the `--version` flag.

Some tests require that the program be available at least when running
in CI, by calling `ensure_running_outside_ci` conditionally on the
outcome. The decision is up to each test, though, the utility merely
returns a `bool`.
2025-04-24 15:48:08 +00:00
Jonas Greitemann
bf2c01e74b config-schema: allow "command-env"-style for editors and fix tools
The `CommandNameAndArgs` struct is used in multiple places to specify
external tools. Previously, the schema only allowed for this in
`ui.pager`.

This commit adds a few sample configs which define variables editors and
fix tools as commands with env vars.

The schema has also been updated to make these valid.
2025-04-24 15:48:08 +00:00
Jonas Greitemann
d35dd31c87 config-schema: require both "command" and "env" keys in structured tool config
Not sure if that is intentional or should rather be considered a bug,
but currently the "structured" option for specifying an external tool
requires that both the command "command" and the "env" keys are
specified. The "command" key makes sense; for the "env" key it came as
a surprise, but it can be argued that this form should only be used when
environment variables need to be specified and the plain string or array
form should be used otherwise.

Either way, the schema did not accurately reflect the current behavior;
now it does. Two sample configs have been added as schema test cases.
2025-04-24 15:48:08 +00:00
Jonas Greitemann
4a1754bc46 config-schema: deny empty arrays for command-like config options
Anytime an external tool is referenced in the config, the command can be
provided as a string or as a token array. In the latter case, the array
must not be empty; at least the command name must be provided.

The schema didn't previously object to an empty array, though; this has
now been rectified. I've added more sample configs to cover this case.
Those same configs can also be used to illustrate that this is indeed
jj's current behavior:

$ jj --config-file cli/tests/sample-configs/invalid/ui.pager_empty_array.toml show
Config error: Invalid type or value for ui.pager
Caused by: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/ui.pager.command_empty_array.toml show
Config error: Invalid type or value for ui.pager
Caused by: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/ui.editor_empty_array.toml config edit --user
Config error: Invalid type or value for ui.editor
Caused by: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/ui.diff-editor_empty_array.toml split
Error: Failed to load tool configuration
Caused by:
1: Invalid type or value for ui.diff-editor
2: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/ui.merge-editor_empty_array.toml resolve
Error: Failed to load tool configuration
Caused by:
1: Invalid type or value for ui.merge-editor
2: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/ui.diff.tool_empty_array.toml diff
Config error: Invalid type or value for ui.diff.tool
Caused by: data did not match any variant of untagged enum CommandNameAndArgs
                                                                                                                                                                                  
$ jj --config-file cli/tests/sample-configs/invalid/fix.tools.command_empty_array.toml fix
Config error: Invalid type or value for fix.tools.black
Caused by: data did not match any variant of untagged enum CommandNameAndArgs
in `command`

As a notable exception, `ui.default-command` *is* allowed to be an empty
array. In that case, `jj` will print a usage message. This is also
covered by a valid sample config.
2025-04-24 15:48:08 +00:00
Jonas Greitemann
5444067c37 config-schema: schema wrongly allowed ui.pager.command to be a string
While `ui.pager` can be a string which will be tokenized on whitespace,
and argument token array, or a command/env table, the `command` key
within that table currently must be an array. The schema previously
explicitly also allowed it to be a string but that does not actually
work, as exemplified by running:
```sh
$ jj --config-file cli/tests/sample-configs/invalid/ui.pager_command-env_string.toml config list
Config error: Invalid type or value for ui.pager
Caused by: data did not match any variant of untagged enum CommandNameAndArgs
```

`CommandNameAndArgs` should potentially be changed to allow strings.
For now, the schema has been updated to reflect the status quo. A new
sample toml has been added to the `invalid` directory to cover this;
prior to updating the schema, this new test case failed. Once the
behavior is changed to allow string, the file merely needs to be moved
to `valid`.
2025-04-24 15:48:08 +00:00
Jonas Greitemann
d4024e0d92 config-schema: fix 2 default values which weren't booleans, but strings
These are two more instances where the default values were wrong and in
fact not even consistent with the schema itself.

I've found these by running
```sh
jq -r 'paths(type == "object" and has("default")) as $p | getpath($p).default | tojson as $v | $p | map("\"\(select(. != "properties"))\"") | join(".") as $k | "\($k) = \($v)"' cli/src/config-schema.json | taplo check --schema=file://$PWD/cli/src/config-schema.json -
```
which uses `jq` to filter the default values from the schema definition
to create a rudimentary TOML file containing all the defaults according
to the schema and then uses `taplo` the validate this TOML against the
schema.

This approach could be developed further to also parse the intermediate
TOML file and compare the result with the default config (from parsing
an empty config). That would not only test for self-consistency of the
schema's proclaimed defaults but also for consistency with the actual
defaults as assumed by jj.
2025-04-24 15:48:08 +00:00