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

628 commits

Author SHA1 Message Date
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
Yuya Nishihara
526953cd87 cli: print "workspace root" without loading repo 2024-02-02 01:28:23 +09:00
Yuya Nishihara
818a885658 cli: map bare BackendError to internal error
The error message suggests that BackendError isn't a user error.
2024-02-01 16:59:44 +09:00
Yuya Nishihara
ca322b761a cli: print source chain of internal error in a similar way to anyhow
Multi-line output should be easier to follow than lengthy line separated by
colon.
2024-02-01 16:59:44 +09:00
Yuya Nishihara
a278059c64 cli: preserve source object of internal error
I'm going to rewrite the error output to print source chain one by one.

The "{message}: {err}" pattern is wrapped in an error struct. InternalError
variant could be a { message, source } pair, but not all errors need an
additional message. This will also apply to UserError.
2024-02-01 16:59:44 +09:00
Yuya Nishihara
8f118074fe cli: map bare io::Error to user error
Suppose the error is emitted from Ui or external command, I don't think
io::Error in CLI is an internal error.
2024-02-01 16:59:44 +09:00
Daniel Ploch
5326571cbd cli_util: allow extensions to run custom code before all commands 2024-01-30 22:47:52 -08:00
Ilya Grigoriev
96d0e776ad docs: fixup to b318b200, mark code blocks in help as text
This prevents rust doctests from trying to compile the code blocks.

I don't think we use doctests much or at all, but I'd like
`cargo insta test --test-runner nextest --accept --workspace`
to pass.

Unfortunately, this affects the output of `jj help` as well, but I
can't think of a workaround for that.
2024-01-30 15:32:17 -08:00
Ilya Grigoriev
52c415eaf4 docs: store output of jj util markdown-help, render it on the website
I am using a very hacky approach, using `insta` to generate the markdown help.
This is based on a lucky coincidence that `insta` chose to use a header
format for snapshot files that MkDocs interprets as a Markdown header (and
ignores).

I considered several other approaches, but I couldn't resist the facts that:

- This doesn't require new developers to install any extra tools or run any
extra commands.
- There is no need for a new CI check.
- There is no need to compile `jj` in the "Make HTML docs" GitHub action,
  which is currently very fast and cheap.

Downside: I'm not sure how well MkDocs will work on Windows, unless the
developer explicitly enables symbolic links (which IIUC is not trivial).

### Possible alternatives 

My next favorite approaches (which we could switch to later) would be:

#### `xtask`

Set up a CI check and a  [Cargo `xtask`]  so that `cargo xtask cli-help-to-md`
essentially runs `cargo run -- util markdown-help > docs/cli-reference.md` from
the project root.

Every developer would have to know to run `cargo xtask cli-help-to-md` if
they change the help text.

Eventually, we could have `cargo xtask preflight` that runs `cargo +nightly
fmt; cargo xtask cli-help-to-md; cargo nextest run`, or `cargo insta`.

#### Only generate markdown for CLI help when building the website, don't track it in Git.

I think that having the file in the repo will be nice to preview changes to
docs, and it'll allow people to consult the file on GitHub or in their repo.

The (currently) very fast job of building the website would now require
installing Rust and building `jj`. 

#### Same as the `xtask`, but use a shell script instead of an `xtask`

An `xtask` might seem like overkill, since it's Rust instead of a shell script.
However, I don't want this to be a shell script so that new contributors on
Windows can still easily run it ( since this will be necessary for the CI to
pass) without us having to support a batch file.

#### Cargo Alias

My first attempt was to set up a [cargo alias] to run this, but that doesn't
support redirection (so I had to change the `jj util` command to output to a
file) and, worse, is incapable of executing the command *in the project root*
regardless of where in the project the current directory is. Again, this seems
to be too inconvenient for a command that every new PR author would have to run
to pass CI.

Overall, this just seems a bit ugly. I did file
https://github.com/rust-lang/cargo/issues/13348, I'm not really sure that was
worthwhile, though.

**Aside:** For reference, the alias was:
    
```toml
# .cargo/config.toml
alias.gen-cli-reference = "run -p jj-cli -- util markdown-help docs/cli-reference.md"
```

### Non-alternatives 

#### Clap's new feature

`clap` recently obtained a similarly-sounding feature in
https://github.com/clap-rs/clap/pull/5206. However, it only prints short help
for subcommands and can't be triggered by an option AFAICT, so it won't help us
too much.

[Cargo `xtask`]: https://github.com/matklad/cargo-xtask
[cargo alias]: https://doc.rust-lang.org/cargo/reference/config.html#alias
2024-01-30 14:58:32 -08:00
Ilya Grigoriev
b318b2009d cli help: add code blocks to make help render as markdown properly 2024-01-30 14:58:32 -08:00
Ilya Grigoriev
a197409b2b cli: new jj util markdown-help outputs jj help for all commands
This uses the [`clap-markdown`] library. It's not very flexible, but seems to
work. Its implementation is not difficult. If needed, we could later
reimplement the part that iterates over all subcommands and have a different
output (e.g., the boring version of each help text inside its own code block,
or a different file per subcommand, or some fancy template in handlebars or
another rust-supported templating language). I don't want to do it right now,
though.

The library does turn out to have some annoying bugs, e.g.
https://github.com/ConnorGray/clap-markdown/pull/18, but I think that's not a
deal-braker.  The fix seems to be 3 lines; if the fix doesn't get merged soon, we
could vendor the library maybe?

[`clap-markdown`]: https://docs.rs/clap-markdown/latest/clap_markdown/
2024-01-30 14:58:32 -08:00