ok/jj
1
0
Fork 0
forked from mirrors/jj
Commit graph

638 commits

Author SHA1 Message Date
Jonathan Tan
33f3a420a1 workspace: recover from missing operation
If the operation corresponding to a workspace is missing for some reason
(the specific situation in the test in this commit is that an operation
was abandoned and garbage-collected from another workspace), currently,
jj fails with a 255 error code. Teach jj a way to recover from this
situation.

When jj detects such a situation, it prints a message and stops
operation, similar to when a workspace is stale. The message tells the
user what command to run.

When that command is run, jj loads the repo at the @ operation (instead
of the operation of the workspace), creates a new commit on the @
commit with an empty tree, and then proceeds as usual - in particular,
including the auto-snapshotting of the working tree, which creates
another commit that obsoletes the newly created commit.

There are several design points I considered.

1) Whether the recovery should be automatic, or (as in this commit)
manual in that the user should be prompted to run a command. The user
might prefer to recover in another way (e.g. by simply deleting the
workspace) and this situation is (hopefully) rare enough that I think
it's better to prompt the user.

2) Which command the user should be prompted to run (and thus, which
command should be taught to perform the recovery). I chose "workspace
update-stale" because the circumstances are very similar to it: it's
symptom is that the regular jj operation is blocked somewhere at the
beginning, and "workspace update-stale" already does some special work
before the blockage (this commit adds more of such special work). But it
might be better for something more explicitly named, or even a sequence
of commands (e.g. "create a new operation that becomes @ that no
workspace points to", "low-level command that makes a workspace point to
the operation @") but I can see how this can be unnecessarily confusing
for the user.

3) How we recover. I can think of several ways:
a) Always create a commit, and allow the automatic snapshotting to
create another commit that obsoletes this commit.
b) Create a commit but somehow teach the automatic snapshotting to
replace the created commit in-place (so it has no predecessor, as viewed
in "obslog").
c) Do either a) or b), with the added improvement that if there is no
diff between the newly created commit and the former @, to behave as if
no new commit was created (@ remains as the former @).
I chose a) since it was the simplest and most easily reasoned about,
which I think is the best way to go when recovering from a rare
situation.
2024-02-09 00:38:47 -08:00
Jonathan Tan
61a026ff7b workspace: inline is_stale()
A subsequent commit will need to handle the return value of
check_stale_working_copy() in 3 different ways, so a boolean will soon
not be sufficient. In preparation for that, inline is_stale() into its
caller, converting it into a "match".
2024-02-09 00:38:47 -08:00
Jonathan Tan
4d0f1b9746 workspace: refactor for_stale_working_copy
Move this function from cli_util.rs, since workspace.rs is the only
caller. This function will be enlarged in a subsequent commit.
2024-02-09 00:38:47 -08:00
Yuya Nishihara
406f2b6147 templater: retain "++" in parsed tree to provide better error indication 2024-02-09 07:42:54 +09:00
Yuya Nishihara
fd4c5a601c templater: translate symbol rules in error message
This is simplified version of the revset change c4769e0b7c.
2024-02-09 07:42:54 +09:00
Yuya Nishihara
948129e88f templater: evaluate logical operator expressions (||, &&, and !)
#2924
2024-02-09 07:42:54 +09:00
Yuya Nishihara
88a1729f8b templater: parse logical operators (||, &&, and !)
These operator symbols are different from the ones in the revset language. I
have no idea if we need bitwise operators, but we'll probably add comparison
operators. It would look weird if 'x == y & z' were parsed as '(x == y) & z'.
2024-02-09 07:42:54 +09:00
Yuya Nishihara
3c4d90483d templater: sort catch-all arms of ExpressionKind in declaration order
Perhaps this was copy-paste error.
2024-02-09 07:42:54 +09:00
Ilya Grigoriev
12c3be70f4 lib refs.rs: rename TrackingRefPair to LocalAndRemoteRef
As discussed in
https://github.com/martinvonz/jj/pull/2962#discussion_r1479384841, the
previous name is confusing since the struct is used for pairs where the
remote branch is not tracked by the local branch.
2024-02-07 17:06:28 -08:00
Evan Mesterhazy
4c4db67f85 Add comments to cmd_split() and rename some variables
This commit is intended to improve readability and makes no functional changes.
2024-02-07 19:53:05 -05:00
Yuya Nishihara
1296d20126 templates: use surround() function in default "show" template
This isn't a great example of surround(), but works.
2024-02-08 02:16:47 +09:00
Yuya Nishihara
4f0db3607a cli: fix doc about colocated repo created by "jj git init --git-repo=."
Ref changes are imported and exported automatically so long as jj and git
share the same workspace directory.
2024-02-07 09:12:24 -08:00
Yuya Nishihara
b13cfef095 cli: rename --colocated flag of "jj git init" to --colocate (verb)
"jj git clone" has --colocate flag, so let's stick to it.

#2747
2024-02-07 09:12:24 -08:00
Yuya Nishihara
3e72c43970 cli: suggest "jj git init" if workspace looks like a plain git repo 2024-02-08 00:34:55 +09:00
jyn
d66fcf2ca0 compile integration tests as a single binary
this greatly speeds up the time to run all tests, at the cost of slightly larger recompile times for individual tests.

this unfortunately adds the requirement that all tests are listed in `runner.rs` for the crate.
to avoid forgetting, i've added a new test that ensures the directory is in sync with the file.

 ## benchmarks

before this change, recompiling all tests took 32-50 seconds and running a single test took 3.5 seconds:

```
; hyperfine 'touch lib/src/lib.rs && cargo t --test test_working_copy'
  Time (mean ± σ):      3.543 s ±  0.168 s    [User: 2.597 s, System: 1.262 s]
  Range (min … max):    3.400 s …  3.847 s    10 runs
```

after this change, recompiling all tests take 4 seconds:
```
;  hyperfine 'touch lib/src/lib.rs ; cargo t --test runner --no-run'
  Time (mean ± σ):      4.055 s ±  0.123 s    [User: 3.591 s, System: 1.593 s]
  Range (min … max):    3.804 s …  4.159 s    10 runs
```
and running a single test takes about the same:
```
; hyperfine 'touch lib/src/lib.rs && cargo t --test runner -- test_working_copy'
  Time (mean ± σ):      4.129 s ±  0.120 s    [User: 3.636 s, System: 1.593 s]
  Range (min … max):    3.933 s …  4.346 s    10 runs
```

about 1.4 seconds of that is the time for the runner, of which .4 is the time for the linker. so
there may be room for further improving the times.
2024-02-06 18:19:41 -08:00
Ilya Grigoriev
291ce0c379 docs: minor updates to jj git push --help 2024-02-06 15:51:39 -08:00
Ilya Grigoriev
b20e7ee095 docs: document that git push --deleted only pushes tracked branches
It tries to push all deleted branches, but can only succeed for tracked
branches.

Closes #2946, as there's probably no need to have `--deleted --tracked`
that would only be different in that the warnings wouldn't be printed.
Thanks to @yuja for pointing this out.
2024-02-06 15:51:39 -08:00
Ilya Grigoriev
8fb790118f cli branch rename: change warning when renaming a branch with remotes 2024-02-06 15:41:01 -08:00
Martin von Zweigbergk
b343289238 working_copy: make reset() take a commit instead of a tree
Our virtual file system at Google (CitC) would like to know the commit
so it can scan backwards and find the closest mainline tree based on
it. Since we always record an operation id (which resolves to a
working-copy commit) when we write the working-copy state, it doesn't
seem like a restriction to require a commit.
2024-02-06 12:41:09 -08:00
Martin von Zweigbergk
9feffa54c8 cli: include command to set config in hint about default command
When the user doesn't have a configured default command, we show a
hint saying to set `ui.default-command`. I think the user is very
likely to want to set that in the user-wide config, so let's include
the command in the hint.
2024-02-06 11:06:52 -08:00
Yuya Nishihara
026a72dfe7 templater: add surround(prefix, suffix, content) function
I'll probably add infix logical operators later, but the surround() function
is still useful because we don't have to repeat the condition:

    if(x || y, "<" ++ separate(" ", x, y) ++ ">")
    surround("<", ">", separate(" ", x, y))

It can't be used if we want to add placeholder text, though:

    if(x || y, "<" ++ separate(" ", x, y) ++ ">", "(none)")

Closes #2924
2024-02-06 23:39:34 +09:00
Yuya Nishihara
1adf6b5d6e cli: do initial import of Git refs without touching HEAD
This reimplements the change 9faa4670d5 "cli: on init, import git refs prior
to importing HEAD." Initialization is special because the HEAD ref isn't
available to jj yet, and there is an empty working-copy commit.

The initialization function could be refactored to go through the common code
path, but I think doing that would make future improvement harder. We might
want to initialize tracking branches based on .git/config for example.

Fixes #2942
2024-02-06 17:19:37 +09:00
Yuya Nishihara
5118d01385 cli: move is_colocated_git_workspace() to git_util, make it public 2024-02-06 17:19:37 +09:00
Ilya Grigoriev
d16a3fcda8 cli git push: new --tracked option 2024-02-05 20:26:14 -08:00
Ilya Grigoriev
cdbbde164b test_git_push: clarify the initial setup 2024-02-05 20:26:14 -08:00
Ilya Grigoriev
5037176a27 git push --help: update link to point to docs website 2024-02-05 20:26:14 -08:00
Essien Ita Essien
2607512815 cli: add a jj git init command.
This initializes a git backed repo.

* It does the same thing as `jj init --git` except that it
  has a --colocated flag to explicitly specify that we want
  the .git repo to be side-by-side the .jj repo in the working
  directory.
* `jj init --git` will keep the current behaviour and will not
  be able to create colocated git backed repos.
* Update test snapshots.
2024-02-05 00:40:58 +00:00
Ilya Grigoriev
65e702aded cli: minor updates to jj util completion
A few minor updates after 0f27152 AKA #2945

Specifically, I tried to change the help text so that it looks better as
Markdown. I also reworded the deprecation warning and added a hint.
2024-02-04 15:55:00 -08:00
jyn
0f2715203f cli: use a positional argument for jj util completion
this has two main advantages:
- it makes it clear that the shells are mutually exclusive
- it allows us to extend the command with shell-specific options in the future if necessary
as a happy accident, it also adds support for `elvish` and `powershell`.

for backwards compatibility, this also keeps the existing options as hidden flags.

i am not super happy with how the new help looks; the instructions for setting up the shell are
squished together and IMO a little harder to read. i'm open to suggestions.
2024-02-04 13:36:55 -08:00
jyn
3d1ce5b6fd document that jj util completion defaults to bash
it's somewhat confusing to me that the `--bash` flag exists at all, since it does nothing - maybe it makes sense to give a hard error? or just remove the flag?
but in any case, it seems good to document the existing behavior.
2024-02-04 12:58:17 -08:00
jyn
52f4fb1b27 don't try to diff binary files
previously, `jj diff` would show the full contents of binary files such as images.
after this change, it instead shows "(binary)". it still shows the filename and metadata so that
users can open the file in the viewer of their choce.

future work could involve showing binary files as Sixel or similar; finding a way to compare large
non-binary files without filling up the screen; or extending the data backends to avoid having to
read the whole file contents into memory.
2024-02-04 11:49:52 -08:00
Ilya Grigoriev
d7bbbd1c29 cli git push: change warning if default revset contains no branches
Previously, `jj git push; jj git push` would tell the user that "No
branches point to the specified revisions.". I found this confusing,
even though strictly speaking it is correct (as the default revset only
considers revisions that haven't been pushed to the remote).

Closes #2241
2024-02-04 10:15:27 -08:00
Ilya Grigoriev
64fa84746a docs CLI reference: add a warning that it is experimental
There are many minor bugs that are difficult to fix in the short-term.

See also the commit message for a197409b2b
2024-02-04 10:05:47 -08:00
Yuya Nishihara
99f0e7f844 cli: remove workaround for ": {source}" embedded in error message 2024-02-04 09:13:21 +09:00
Yuya Nishihara
77ceadbfd0 cleanup: remove remaining ": {source}" from error message templates 2024-02-04 09:13:21 +09:00
Yuya Nishihara
1efadd96c8 git: remove ": {source}" from FailedRefExportReason, walk chain by caller
The error output gets more verbose because all gix error sources are printed.
Maybe we'll need a better formatting, but changing to multi-line output doesn't
look nice either.
2024-02-04 09:13:21 +09:00
Yuya Nishihara
a0cefb8b7b revset, template: remove ": {source}" from parse error message template
These error types are special because the message is embedded in ASCII art. I
think it would be a source of bugs if some error types had ": {source}" but
others don't. So I'm going to remove all ": {source}"s, and let the callers
concatenate them when needed.
2024-02-04 09:13:21 +09:00
Austin Seipp
7a7f76cbfb cli: deprecate jj merge
Summary: As discussed in Discord, on GitHub, and elsewhere, this change
deprecates the use of `jj merge` and suggests users use `jj new` exclusively
instead. `merge` isn't completely unfit as a name; but we think it obscures
the generality of `new` and we want people to use it instead.

To further drive the bit home, by default, `jj merge` is now hidden. This will
hopefully stop new users from running into it.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Change-Id: I94938aca9d3e2aa12d1394a5fbc58acce3185b56
2024-02-03 17:21:56 -06:00
Austin Seipp
3f13ea39e2 cli: deprecate jj checkout
Summary: As discussed in Discord, on GitHub, and elsewhere, this change
deprecates the use of `jj checkout` and suggests users use `jj new` exclusively
instead. The verb `checkout` is a relic of a bygone era the — days of RCS
file locking, before 3-way merge — and is not a good, fitting name for the
functionality it provides.

To further drive the bit home, by default, `jj checkout` (and `jj co`) is now
hidden. This will hopefully stop new users from running into it.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Change-Id: I7a1adfc9168fce1f25cf5d4c4c313304769e41a1
2024-02-03 17:21:56 -06:00
Austin Seipp
2a9e6fc610 cli: move tests from test_checkout -> test_new_command
These didn't really need to use `jj checkout`, and it will be deprecated in a
future change anyway. Move them out of there and into `new`.

Ideally this would go into `test_conflicts.rs`, but that exists in `jj-lib`, so
it doesn't have `TestEnvironment` available to it.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Change-Id: If0173b27ab4d1f6036a4ec632ec77b6824f310c3
2024-02-03 17:21:56 -06:00
Essien Ita Essien
bcdb9beb6c cli: Move git_init() from init.rs to git.rs
* Move git_init() to cli/src/commands/git.rs and call it from there.
* Move print_trackable_remote_branches into cli_util since it's not git specific,
  but would apply to any backend that supports remote branches.
* A no-op change. A follow up PR will make use of this.
2024-02-03 15:06:09 +00:00
Essien Ita Essien
31e4061bab cli: Refactor out git_init() to encapsulate all git related work.
* Create a git_init() function in cli/src/commands/init.rs where all git related work is done.
  This function will be moved to cli/src/commands/git.rs in a subsequent PR.
2024-02-03 14:27:12 +00:00
Essien Ita Essien
8423c63a04 cli: Refactor workspace root directory creation
* Add file_util::create_or_reuse_dir() which is needed by all init
  functionality regardless of the backend.
2024-02-03 14:15:05 +00:00
Ilya Grigoriev
e9c482c017 docs: mention in jj help config edit that the command can create a file 2024-02-02 23:29:58 -08:00
Ilya Grigoriev
98948554f7 cli jj config: add jj config path command 2024-02-02 23:29:58 -08:00
Ilya Grigoriev
8a4b3966a6 test_global_opts: make test_version just a bit nicer when it fails 2024-02-02 23:19:25 -08:00
Ilya Grigoriev
42e6132771 test_global_opts: extract --version to its own test 2024-02-02 23:19:25 -08:00
Yuya Nishihara
28dd0180ad cli: propagate WorkspaceLoadError::Path error transparently
The inner error message is now printed by default.
2024-02-02 08:22:24 +09:00
Yuya Nishihara
9adf6e1303 cli: remove "I/O error" prefix from the error message
It doesn't add much context, and looks worse with the new error formatting.
2024-02-02 08:22:24 +09:00
Yuya Nishihara
30666dfbcf cli: preserve source of user error, print source chain one by one
"Caused by" lines are inserted before the hint because they are more strongly
related to the error.
2024-02-02 08:22:24 +09:00