Commit graph

2762 commits

Author SHA1 Message Date
Scott Taylor
4eabf9a511 rebase: abandon commits while rebasing
This fixes a bug where the rebase wouldn't work properly if a root of
the target commit set was abandoned before being rebased.
2025-05-21 11:58:13 +00:00
Scott Taylor
e75afec82c rewrite: allow abandoning while moving commits
Instead of calling `move_commits`, callers now have the option to call
`compute_move_commits` and then customize the rebase before calling
`ComputedMoveCommits::apply`. `ComputedMoveCommits::record_to_abandon`
can be used to abandon commits while rebasing.
2025-05-21 11:58:13 +00:00
Scott Taylor
6b9e944cd0 rebase: demo bug with skipping divergent commits
If the root of the target commit set is abandoned, it prevents the
commits from being rebased properly.
2025-05-21 11:58:13 +00:00
Martin von Zweigbergk
d2cf2cb768 async: bubble up async-ness from Backend::read_file 2025-05-20 22:07:03 +00:00
Winter
2d1f50a8ea cli: resolve: show a hint towards editing the conflict markers manually if the conflict has >2 sides
As suggested in Discord: https://discord.com/channels/968932220549103686/1370632916169920523
2025-05-20 18:11:43 +00:00
Martin von Zweigbergk
b970939804 backend: make read_file() return a AsyncRead
The `Backend::read_file()` method is async but it returns a `Box<dyn
Read>` and reading from that trait is blocking. That's fine with the
local Git backend but it can be slow for remote backends. For example,
our backend at Google reads file chunks 1 MiB at a time from the
server. What that means is that reading lots of small files
concurrently works fine since the whole file contents are returned by
the first `Read::read()` call (it was fetched when
`Backend::read_file()` was issued). However, when reading files that
are larger than one chunk, we end up blocking on the next
`Read::read()` call. I haven't verified that this actually is a
problem at Google, but fixing this blocking is something we should do
eventually anyway.

This patch makes `Backend::read_file()` return a `Pin<Box<dyn
AsyncRead>>` instead, so implementations can be async in the read part
too.

Since `AsyncRead` is not yet standardized, we have to choose between
the one from `futures` and the one from `tokio`. I went with the one
from `tokio`. I picked that because an earlier version of this patch
used `tokio::fs` for some reads. Then I realized that doing that means
that we have to use a tokio runtime, meaning that we can't safely keep
our existing `pollster::FutureExt::block_on()` calls. If we start
depending on tokio's specific runtime, I think we would first want to
remove all the `block_on()` calls. I'll leave that for later. I think
at this point, we could equally well use `futures::io::AsyncRead`, but
I also don't know if there's a reason to prefer that.
2025-05-20 13:23:36 +00:00
Scott Taylor
c406b3a929 rebase: skip duplicate divergent commits by default
This serves a similar purpose to Git's patch ID mechanism, however it is
slightly different in that it only compares commits which have the same
change ID as each other (divergent changes), and it does a full
comparison of the commits to see if they would have identical trees if
rebased onto the same parents. Since most changes aren't divergent, I
believe this should have a negligible performance cost in most cases.

I think skipping these commits by default makes sense for `jj rebase`,
since usually this will be a helpful behavior for the user. With this
behavior, a safe first step when encountering divergent changes would be
to rebase one branch on top of the other, since that will abandon any
divergent changes that have identical contents to existing commits,
leaving behind any non-trivial divergent changes for the user to resolve
manually.
2025-05-19 22:23:32 +00:00
Vincent Ging Ho Yim
21c541afb7 cli: remove jj branch and associated subcommands
`jj branch` has been deprecated since v0.22.0.

`renamed_cmd()` has no more callers now and has been removed. It can be added back in if
needed in the future.

The `jj branch` mentions in docs/design/tracking-branches.md have been left as they are
as a historical record since that document hasn't been updated since June 2024.
2025-05-19 13:20:20 +00:00
Vincent Ging Ho Yim
855fe12faf test: migrate remaining jj branch uses to jj bookmark 2025-05-19 13:20:20 +00:00
Vincent Ging Ho Yim
db37450ef2 cli: sort top-level commands lexicographically
The Markdown docs have been regenerated as well.
2025-05-19 12:11:57 +00:00
Yuya Nishihara
8cd32b20a3 cli: config edit: show file path to edit
I think the file path is generally useful, and isn't verbose. Just print it
unconditionally.

Closes #6566
2025-05-19 10:47:01 +00:00
Yuya Nishihara
6df3e240ed cli: add top-level context label to commit templates
Since operation templates have "operation" label, commit templates should have
"commit" for consistency.

The [colors] table is not updated to use the "commit" prefix. There are some
non-template outputs which use unqualified "bookmark"/"tag"/"git_ref" labels.
That's also a reason why "bookmark_list" template doesn't have a "bookmark"
context label yet. (We'll need to qualify the color definition as "commit
bookmark" so the whole bookmark list wouldn't be colorized as "bookmark".)
2025-05-19 01:41:15 +00:00
Yuya Nishihara
28cb16e83e cli: add top-level command-name label to op diff/show templates 2025-05-19 01:41:15 +00:00
Yuya Nishihara
d43d8c4e23 cli: add top-level command-name/context labels to graph "node" templates
It's inconsistent that the content templates have e.g. "op_log operation", but
the graph node templates don't.
2025-05-19 01:41:15 +00:00
Yuya Nishihara
f8a0fcfc47 templater: make .labeled() accept list of labels
I'm going to add top-level "<command> <context>" labels to templates, and many
of .labeled() callers will have to set at least two labels.
2025-05-19 01:41:15 +00:00
Yuya Nishihara
9e5205daee cli: git: fix "tag" labeling in import stats 2025-05-18 07:30:46 +00:00
Yuya Nishihara
86d4f4b90f cli: git: do not attempt to align bookmark and tag changes in stats
It was broken when we renamed "branch" to "bookmark", and there were no
complaints since then. Let's simply align changes per ref type.
2025-05-18 07:30:46 +00:00
Martin von Zweigbergk
23de072c14 store: drop "_async" suffix from read_file()/read_symlink()
There's no sync version anymore.
2025-05-18 02:45:43 +00:00
Martin von Zweigbergk
12bcd04459 store: delete read_file(), update callers to use async version 2025-05-18 02:45:43 +00:00
Yuya Nishihara
a1abe46c45 cli: define "operation tags" color properly
It's unrelated to (commit) "tags", and the color of "current_operation" seemed
wrong.
2025-05-18 01:42:14 +00:00
Yuya Nishihara
183a7b6eba cli: label "working_copy" by commit_summary template, not by code
I'm thinking of adding a top-level context label consistently. If we added
"commit" to the summary template (in code), the status output would be labeled
as "working_copy commit ..", whereas log entries would be labeled as "commit
working_copy ..". The latter should be more correct since the "commit" label
is global.

Now the working-copy entry is highlighted in op log and bookmark list, which
I think is good.
2025-05-18 01:42:14 +00:00
Yuya Nishihara
f7f85383bc tests: snapshot a few more colored outputs 2025-05-18 01:42:14 +00:00
Vincent Ging Ho Yim
53619359e2 cli describe: refactor to use pattern matching
This is both more idiomatic and explicit.
2025-05-17 15:44:57 +00:00
Vincent Ging Ho Yim
9d5c146c9b cli describe: remove redundant assertion of conflicting flags
This assertion is redundant given both the `conflicts_with = "edit"` declaration on the
`no_edit` flag and the passing `test_edit_cannot_be_used_with_no_edit` test.
2025-05-17 14:19:16 +00:00
Vincent Ging Ho Yim
459ed85f62 cli describe: move use_editor variable closer to use sites 2025-05-17 14:19:16 +00:00
Vincent Ging Ho Yim
e18eb8e05e test: clean up op log output to show short op ids 2025-05-17 12:20:38 +00:00
Vincent Ging Ho Yim
9d995c7f43 test: use --at-op and templates instead of manually parsing op ids from op log
There is an additional run of `jj op log`, so a commit id has changed here.
2025-05-17 12:20:38 +00:00
Vincent Ging Ho Yim
1398f1c174 test: rename op id variables and reword comment
The `previous_op_id` doesn't belong to the operation immediately before the
`current_op_id`. There is one operation in between, namely the latest snapshot taken.
2025-05-17 12:20:38 +00:00
Vincent Ging Ho Yim
2a596f7516 test: remove redundant --at-op argument 2025-05-17 12:20:38 +00:00
Vincent Ging Ho Yim
3dcf2e4d75 test: refactor to use get_log_output() helper function 2025-05-17 12:20:38 +00:00
Vincent Ging Ho Yim
1636202413 test: omit commit ids from log template
We are not interested in the commit ids here.
2025-05-17 12:20:38 +00:00
Vincent Ging Ho Yim
1447ff8f25 test: fix grammar in comment 2025-05-17 12:20:38 +00:00
Isaac Corbrey
85d54eb3d8 docs: Don't include unnecessary shebangs
It isn't necessary to include shebangs in scripts passed into
`util exec` since you're already explicitly calling out the shell you'd
like to use. This change removes shebangs from examples for `util exec`
and adds a note below calling this out.
2025-05-17 11:51:07 +00:00
Martin von Zweigbergk
275504235b cli: replace ExitCode by u8
I'd like to make the internal `jj` binary at Google log the exit code,
but `ExitCode` doesn't seem to provide any way of getting the numeric
code out of it. This patch therefore replaces `ExitCode` by `u8` and
lets the `main()` function convert it to `ExitCode`. It's a bit
unfortunate but I don't see a better solution. It doesn't seem worth
it to create our own newtype for it.
2025-05-17 05:45:59 +00:00
Yuya Nishihara
88d79c135b cli: accept --tool=:<format> argument as builtin diff format
This is just for completeness. I don't think this is practically useful, but the
:<format> syntax should work in both config files and command arguments.
2025-05-17 00:11:00 +00:00
Nicole Patricia Mazzuca
f9d59a36c0 config: clarify warning
Instead of saying to move configuration files from
`~/Library/Application Support` to `~/.config`, jj now tells you to move
configuration files from `~/Library/Application Support/jj` to
`~/.config/jj`.
2025-05-16 13:46:22 +00:00
T6
13c6257aac templater: add arithmetic operators 2025-05-16 12:45:09 +00:00
Yuya Nishihara
a9bae8bc91 templater: deprecate CommitId::normal_hex()
If CommitId and ChangeId were separate types in templates, we wouldn't add
CommitId::normal_hex().
2025-05-16 11:12:33 +00:00
Yuya Nishihara
e9600ccfdb templater: split ChangeId/CommitId types
This isn't complex compared to the enum version, and provides a better error
message.
2025-05-16 11:12:33 +00:00
Yuya Nishihara
0140aa59a9 templater: inline CommitOrChangeId::short/shortest() helpers
I'll replace the enum with distinct ChangeId/CommitId template types.
2025-05-16 11:12:33 +00:00
Gaëtan Lehmann
0b0d313583 split: use "selected/remaining changes" instead of "first/second commits"
With the new -A/-B/-d flags, the new commit may be created anywhere in
the tree, making the denomination first/second commit inaccurate.
2025-05-16 07:55:12 +00:00
Vincent Ging Ho Yim
20fd0b7daf cli bookmark move: move names argument before --from argument
The usage line originally showed `--from <REVSETS>|NAMES`, which was confusing as it
could be parsed as `--from (<REVSETS> or NAMES)`, rather than the correct `(--from
<REVSETS>) or NAMES`.

The order of the two arguments are now swapped, so that Clap displays it as
`NAMES|--from <REVSETS>` instead. Using bookmark names as the move targets should be
more common anyway. This is also consistent with the order in which the two arguments
are described in the command's doc comment.
2025-05-16 05:06:15 +00:00
Yuya Nishihara
851d25cd68 cli: unify diff format/tool config variables
This allows users to override the external tool set in ~/.jjconfig.toml. The
config variable is renamed to ui.diff-formatter to be consistent with the other
diff/merge editor settings.

--tool=:<format> support will be added separately.

Closes #3327
2025-05-16 00:33:49 +00:00
Yuya Nishihara
f0386e2fae cli: add CommandNameAndArgs::as_str() helper
This is convenient as Option type provides monadic methods.
2025-05-16 00:33:49 +00:00
Yuya Nishihara
79cb3d231a cli: keep short/long diff formats specified by args separately 2025-05-16 00:33:49 +00:00
Yuya Nishihara
e4656ce359 cli: split builtin diff format resolution into two parts
If we add --tool=:<builtin-format> syntax, name resolution failure shouldn't be
translated to a ConfigGetError. This change prepares for that.
2025-05-16 00:33:49 +00:00
Vincent Ging Ho Yim
b99116fc23 cli: improve hint to abandon commits when divergent change appears
A divergent change could point to more than two commits, so the hint now suggests
abandoning unneeded commits rather than just one of them.

The `-r` flag is unnecessary for `jj abandon` as it is implied.

Also changed `<REVISION>` to `<commit_id>` to be clear that using the change id here
will not work.
2025-05-16 00:21:38 +00:00
Vincent Ging Ho Yim
cfce146f8f commit: show a hint if --message is not provided and the description is empty
This addresses part of #4414 and implements something akin to what's described in
@arxanas's [suggestion], with the exception that the editor contents don’t need to be
completely cleared, since whether cleared or not it is not obvious whether the user
intended to add an empty description or abort entirely.

[suggestion]: https://github.com/jj-vcs/jj/issues/4414#issuecomment-2359123535

The hint is not shown if an empty description is provided via `--message ""`, since the
user is explicitly bypassing the editor and wants to commit the change directly.

Otherwise, if a user exits the editor with an empty description (notwithstanding any
`JJ:` lines), it could be one of the following cases:

1. The user wants to commit the changes but no longer wants to add a description. The
hint can simply be ignored.

2. The user wants to commit the changes and add a description but accidentally exits the
editor. The second hint shows how to add a description to the parent commit.

3. The user no longer wants to commit the changes. However, a new commit is still
created to maintain consistent behaviour as when an empty description is provided via
the CLI. The first hint shows how to undo the commit.
2025-05-15 13:02:53 +00:00
Vincent Ging Ho Yim
c683756533 commit: add tests for committing with empty description from CLI and from editor 2025-05-15 13:02:53 +00:00
Vincent Ging Ho Yim
9a39bf6c41 commit: remove trailing whitespace 2025-05-15 13:02:53 +00:00