Commit graph

2177 commits

Author SHA1 Message Date
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
Jonas Greitemann
69cf7b38fc config-schema: add missing default for core.fsmonitor 2025-04-24 15:48:08 +00:00
Jonas Greitemann
b99361cbab config-schema: fix wrong "default" for ui.streampager.interface
The schema said that the default was "never" which is actually not one
of the allowed enum values.
2025-04-24 15:48:08 +00:00
Jonas Greitemann
47fba33dcd config-schema: fix a typo in the $comment field 2025-04-24 15:48:08 +00:00
Yuya Nishihara
757a08cd21 cli: rebase: consolidate call sites of move_commits() 2025-04-24 13:16:33 +00:00
Yuya Nishihara
fdaf8b9ca5 cli: rebase: remove redundant check for empty operation
move_commits() exits early if the target commits are empty.
2025-04-24 13:16:33 +00:00
Yuya Nishihara
bdedf4a958 cli: rebase: use slice pattern when constructing tx descriptions 2025-04-24 13:16:33 +00:00
Sam
001801a3b1 cli: add config option for built-in pager's ruler 2025-04-23 03:16:58 +00:00
Yuya Nishihara
6e5f0297e2 cli: evolog: rename variable to match the actual type
iter_nodes isn't an iterator.
2025-04-22 16:27:02 +00:00
Yuya Nishihara
853992facf cli: evolog: remove redundant Result wrapping 2025-04-22 16:27:02 +00:00
Yuya Nishihara
af9c608ca5 config: migrate ui.default-description to template alias
Since we now have the template alias, it's easy to migrate the config value
programatically. However, there are a couple of minor behavior changes:

 a. default description won't be used if user customized the
    draft_commit_description template.
 b. default description won't be inserted if trailer is added

For (a), I assumed user would inline the default description in the draft
template if they customized the template. (b) should be okay because the
trailers template is a new feature.
2025-04-21 14:39:47 +00:00
Yuya Nishihara
fc5f90c4ac annotate: reorganize functions as restartable process
I don't have any plan to implement incremental UI for file annotation, but I
think the new API is nicer in that they have fewer function arguments.

Note that this wouldn't help implement interactive UI to go ancestor annotation
by clicking annotated line. To achieve that cheaply, we'll need weave-like data.
2025-04-21 12:38:38 +00:00
Martin von Zweigbergk
ed99e21bc4 revset: rename StoreError variants to Backend
I haven't checked, but I think "store" is a holdover from a long time
ago.
2025-04-20 02:28:36 +00:00
Gaëtan Lehmann
7073811fe0 squash: don't add trailers to an empty description
ref: #6265
2025-04-19 16:25:03 +00:00
Martin von Zweigbergk
15351a2d92 templates: extract a template alias as hook for default commit description
This makes it easier to override just the default description without
having copy the whole default template (and having to keep it up to
date with new versions).
2025-04-19 05:42:52 +00:00
Yuya Nishihara
6cba6d7ec2 cli: git-push: do not move existing local bookmarks by --change
An existing "push-*" bookmark should usually be in position. If it wasn't
because of e.g split, I think the user should be aware of that and take an
explicit action.
2025-04-19 01:26:40 +00:00
Yuya Nishihara
03b37c6646 cli: git-push: extract helper function that checks bookmark name to create 2025-04-19 01:26:40 +00:00
Gaëtan Lehmann
fae66ace9b split: add trailer support 2025-04-18 16:48:01 +00:00
Gaëtan Lehmann
6d240be777 squash: add trailer support 2025-04-18 16:35:16 +00:00
Gaëtan Lehmann
2a7b0211eb new: add trailer support 2025-04-17 13:29:49 +00:00
Winter
af60f3d674 cli: deprecate ui.default-description
Closes https://github.com/jj-vcs/jj/issues/6298.
2025-04-17 02:03:48 +00:00
Gaëtan Lehmann
5f7159d4b1 commit: add trailer support 2025-04-16 14:21:35 +00:00
Martin von Zweigbergk
f0545ee25c test: introduce test helpers for creating repo path types
I'm about to make the constructors return a `Result`. The helpers will
hide the unwrapping.
2025-04-15 14:42:23 +00:00
Gaëtan Lehmann
f6e3f38b94 templates: add commonly used trailers
namely Signed-off-by and Change-Id

`format_signed_off_by_trailer` will be formatted properly if the author
name is not set, but will contain the email placeholder if the author
email is not set, as I haven't found a way to make the template
generation fail.

`format_gerrit_change_id_trailer` is based on jj's change id, but it
needed to be padded to reach 40 characters. Zero-padding is kind of
boring so I've used `6a6a6964`, the hexadecimal representation of `jjid`
in ascii.

Because the trailer value runs up to the end of the line, they are
all terminated with a new line. This way it's also convenient to
define these trailers in the `commit_trailers` template:

  [templates]
  commit_trailers = '''
    format_signed_off_by_trailer(self)
    ++ format_gerrit_change_id_trailer(self)
  '''
2025-04-15 05:16:16 +00:00
Winter
f3c4cc2155 cli: duplicate: add setting for templating the new commit descriptions
This allows the customization of the duplicated commit descriptions.

An ideal use case for this is emulating `git cherry-pick -x`, as
illustrated in the tests.
2025-04-13 21:49:47 +00:00
Gaëtan Lehmann
71a0194ad1 describe: add trailer support
Add a new `template.commit_trailer` configuration option. This template
is used to add some trailers to the commit description.

A new trailer paragraph is created if no trailer paragraph is found in
the commit description.
The trailer is not added to the trailer paragraph when the trailer is
already present, or if the commit description is empty.
2025-04-13 20:36:11 +00:00
Gaëtan Lehmann
3c233c0f45 lib: add trailer module for commit trailers
To be used for parsing `Change-Id`, `Signed-off-by` and other
`Co-authored-by` trailers from commits

Co-authored-by: Austin Seipp <aseipp@pobox.com>
2025-04-13 20:36:11 +00:00
Yuya Nishihara
81b2f1a1fb merge-tools: fix builtin merge editor to not ignore executable bit
Exec-bit conflicts are resolved separately, but we still need to copy them to
UI to get back the original state.
2025-04-13 05:18:11 +00:00
Yuya Nishihara
fa00775f94 cli: resolve: do not use .with_new_file_ids() to construct resolved file value
This reverts a01d0bf773 "cli: resolve: leave executable bit unchanged when
using external tool", and updates handling of resolved content.

Fixes #6250
2025-04-13 02:02:58 +00:00
Yuya Nishihara
ace0a52eb1 cli: resolve: error out early if conflict in exec bit couldn't be resolved
As Martin suggested, "we should instead make it an error to try to resolve the
content-level conflict before resolving the executable-bit-level conflict. I
think we should do the same when merging copy records."

https://github.com/jj-vcs/jj/pull/6288#pullrequestreview-2751367755
2025-04-13 02:02:58 +00:00
Yuya Nishihara
b28bc420ab merge: do not map absent tree entry to non-executable
We're going to make "jj resolve" error out on exec bit conflict. This behavior
should be more consistent with tree::try_resolve_file_conflict(), which exits
early if the tree value had absent entries.

Since unchanged exec bit shouldn't be lost when resolving change-delete content
conflict, the resolution function falls back to the original state if the
exec-bit conflict is resolved to None.
2025-04-13 02:02:58 +00:00
Yuya Nishihara
1e94ee263b cli: resolve: update "not normal files" error message and formatting
try_materialize_file_conflict_value() and to_file_merge() shouldn't fail because
of exec bit changes. And error.to_string() shouldn't include trailing newline.
2025-04-12 08:58:05 +00:00
Yuya Nishihara
d2caf6f1d9 cli: resolve: use try_materialize_file_conflict_value()
The executable bit handling will be a bit more involved in order to get around
#6250.
2025-04-12 08:58:05 +00:00
Yuya Nishihara
f047addfe0 conflicts: pack MaterializedTreeValue::FileConflict fields into struct
I'll add a function that returns Option<MaterializedFileConflictValue> instead
of MaterializedTreeValue.
2025-04-12 08:58:05 +00:00
Yuya Nishihara
5c6ab172b8 transaction: propagate error from tx.write()
#6287
2025-04-12 06:56:13 +00:00
Yuya Nishihara
f587374d37 transaction: wrap tx.commit() error in enum
This helps propagate error from tx.write(). I made the error variants
non-transparent because it's easier than manually implementing From<> that maps
each inner error to the other inner error.
2025-04-12 06:56:13 +00:00
Yuya Nishihara
60b96122f2 cleanup: use new array methods instead of .collect_tuple()/.next_tuple()
It's more obvious that the element types are the same.
2025-04-12 00:58:14 +00:00
Winter
601548061d config-schema: add templates 2025-04-12 00:20:46 +00:00
Caleb White
3efb59426f abandon: convert deleted bookmark warning to hint
Bookmarks are no longer deleted on the next `jj git push` command, so
this updates the language and downgrades the warning to a hint.
2025-04-11 01:35:07 +00:00
Emily
8c506006b2 docs: add diagrams for jj new --after and --before 2025-04-10 19:00:34 +00:00
Benjamin Brittain
0b6d0a7a75 git_backend: derive the change ID from the git change-id header
When read/writing commits from the git-backend, populate the git commit
header with a backwards hash of the `change-id`. This should enable
preserving change identity across various git remotes assuming a
cooperative git server that doesn't strip the git header.

This feature is behind a `git.write-change-id-header` configuration flag
at least to start.
2025-04-09 16:42:56 +00:00
Emily
333d47f5e5 git: add deprecation warnings for git.subprocess 2025-04-08 10:36:46 +00:00
Yuya Nishihara
b63ab33b10 diff: add option to render color-words diffs without materializing conflicts
The original idea was to flatten left/right conflict trees and pair up adjacent
negative/positive terms. For example, diff(A, B-C+D) could be rendered as
diff(A, B) and diff(C, D). The problem of this formalization is that one of the
diff pairs is often empty (because e.g. A=B), so the context is fully omitted.
The resulting diff(C, D) doesn't provide any notion why the hunk is conflicted,
and how it is different from A.

Instead, this patch implements diffs in which each left/right pair is compared.
In the example above, the left terms are padded, and the diffs are rendered as
diff(A, B), diff(-A, -C), diff(A, D). This appears to be working reasonably well
so long as either side is resolved or both sides have the same numbers of terms.

Closes #4062
2025-04-08 09:12:39 +00:00
Yuya Nishihara
b24efa8a8d diff: parameterize "removed"/"added" labels in color-words diffs 2025-04-08 09:12:39 +00:00
Yuya Nishihara
8af238f68a diff: test identical contents early when rendering color-words diffs
This helps extract hunk rendering function for non-materialized color-words
diffs. In conflict hunk, an identical diff pair will be omitted with "..."
marker.

This patch introduces a subtle behavior change when "ignore whitespace" options
are used. Before, "..."  wouldn't be printed if contents differ only in
whitespace. I don't think the new behavior is bad because the file header says
"Modified regular file" in that case.
2025-04-08 09:12:39 +00:00
Yuya Nishihara
6d009b3453 diff: make FileContent generic
I'll make color-words diffs optionally compare Merge<BString> without
materializing conflicts.
2025-04-08 09:12:39 +00:00
Aleksey Kuznetsov
3eaff83bca cli: Add config setting for bookmark list sort order
This is a conclusion of #5849.
Config setting to list bookmarks in specified order.

Closes #3831
2025-04-08 08:06:29 +00:00
Yuya Nishihara
af4f7a7811 cli: describe: reuse author field set to temporary builders
I originally thought we could remove args.reset_author tests in later pass, but
we can't because author timestamp may be updated if a commit is discardable.
Still it's nice that we can deduplicate some logic.
2025-04-08 02:11:53 +00:00