Commit graph

5182 commits

Author SHA1 Message Date
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
Austin Seipp
6be5cf3dfc github: use macos-14, add new aarch64-apple-darwin release binary
GitHub announced these new Apple Silicon based runners today. Let's take them
for a spin.

Let's also add an entry in the release matrix to build and publish `aarch64-
apple-darwin` binaries, too. This doesn't migrate the old release matrix entry;
it still uses a `macos-11` runner. This means the x86 binaries should work on a
few older macOS versions if users need it.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-01-30 16:41:38 -06:00
Stephen Jennings
b2800f7f44 docs: add notes for Windows users 2024-01-29 12:16:15 -08:00
Philip Metzger
068f511b3f FAQ: Make a question clearer.
It seems that "amended" is not clear enough for users. So use simpler terms.

Suggestion from ilyagr in [Discord](https://discord.com/channels/968932220549103686/1201196831653236756/1201268055678931147).
2024-01-29 20:42:26 +01:00
dependabot[bot]
969db1b58d cargo: bump the cargo-dependencies group with 3 updates
Bumps the cargo-dependencies group with 3 updates: [indexmap](https://github.com/indexmap-rs/indexmap), [serde](https://github.com/serde-rs/serde) and [serde_json](https://github.com/serde-rs/json).


Updates `indexmap` from 2.1.0 to 2.2.1
- [Changelog](https://github.com/indexmap-rs/indexmap/blob/master/RELEASES.md)
- [Commits](https://github.com/indexmap-rs/indexmap/compare/2.1.0...2.2.1)

Updates `serde` from 1.0.195 to 1.0.196
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.195...v1.0.196)

Updates `serde_json` from 1.0.111 to 1.0.113
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.111...v1.0.113)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cargo-dependencies
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-29 12:56:11 -06:00
Yuya Nishihara
3d0b3d57d8 git_backend: on gc(), remove unreachable no-gc refs and compact them
With my jj repo, the number of jj/keep refs went down from 87887 to 27733.
The .git directory size is halved, but we'll need to clean up extra and index
files to save disk space. "git gc --prune=now && jj debug reindex" passed, so
the repo wouldn't be corrupted.

#12
2024-01-27 10:18:11 +09:00
Yuya Nishihara
351487b9f5 backend: pass Index and keep_newer timestamp parameters to gc()
GitBackend::gc() will need to check if a commit is reachable from any
historical operations. This could be calculated from the view and commit
objects, but the Index will do a better job.
2024-01-27 10:18:11 +09:00
Yuya Nishihara
845eb4ce01 git_backend: when running "git gc", chdir instead of specifying it by GIT_DIR
Hopefully this will be more reliable on Windows where path/environment stuff
is messy.
2024-01-27 10:18:11 +09:00
Yuya Nishihara
4e54021930 backend: have gc() return BackendError instead of opaque error type
The gc() implementation is likely to call other backend functions, which
return BackendError.
2024-01-27 10:18:11 +09:00
Yuya Nishihara
84949dd551 backend: mark BackendError::Other as transparent
The inner error should be the source, and I don't think the "Error:" prefix
gives additional context.
2024-01-27 10:18:11 +09:00
Ilya Grigoriev
bef2ecadac cli: change R to D for "deleted" in diff summary
@joyously ponted out that `R` could be interpreted as "renamed" instead of
"removed".  "Deleted" is unambiguous.
2024-01-26 10:01:40 -08:00
Yuya Nishihara
1330381fc6 cli: add inline comment about racy Git HEAD updates
This is the source of the problem I noticed when debugging #924 and #1608. I
don't think this can be easily fixed, so let's document it.
2024-01-27 00:01:59 +09:00
Yuya Nishihara
3207009e73 cli: reorder import of git head/refs and snapshot
Since import_git_refs() may check out new working-copy commit, it shouldn't be
triggered before the snapshot.

Fixes #2876
2024-01-27 00:01:59 +09:00
Yuya Nishihara
9faa4670d5 cli: on init, import git refs prior to importing HEAD
The "::HEAD" set is usually smaller than "::git_refs". If these sets were
imported in that order, "HEAD..git_refs" commits would be indexed on top of
the "::HEAD" commits. It's not a problem, but undesirable.
2024-01-27 00:01:59 +09:00
Yuya Nishihara
23a1ddb6ad cli: split WorkspaceCommandHelper::import_git_refs_and_head()
Also added status message to import_git_head() as I think it's an unusual
event.
2024-01-27 00:01:59 +09:00
Yuya Nishihara
8a67191d25 git: simplify import_head() as it doesn't have to process multiple head commits 2024-01-27 00:01:59 +09:00
Yuya Nishihara
fc114ef217 git: extract Git HEAD handling bits from import_some_refs()
I'm going to make WorkspaceCommandHelper::maybe_snapshot() snapshot the working
copy before importing refs. git::import_some_refs() can rebase the working copy
branch and therefore @ can be moved. git::import_head() doesn't, and it should
be invoked before snapshotting.

git::import_head() is inserted to some of the git:import_refs() callers where
HEAD seems to matter. I feel it's a bit odd that the HEAD ref is imported to
non-colocated repo, but "jj init --git-repo" relies on that, and I think the
existence of HEAD@git is harmless. It's merely a ref to the revision checked
out somewhere else.
2024-01-27 00:01:59 +09:00
Yuya Nishihara
5a88180720 git_backend: fix import_head_commits() to not issue duplicated ref edits
This was broken at afa72ff496 "git_backend: inline prevent_gc() to bulk-update
refs." Since no-gc refs are created within a transaction, duplicated edits are
no longer allowed.
2024-01-27 00:00:57 +09:00
Ilya Grigoriev
dff440c4a8 clippy: Fix nightly warnings about "useless use of vec!" 2024-01-25 22:00:26 -08:00
Valentin Gatien-Baron
3b7678d9c5 cli: move jj workspace root to `jj root, for discoverability
This is a convenient command, for scripting things like `cd $(jj root)
&& do something`, and it seems better to allow people to find it
before they learn about workspaces.
2024-01-25 16:31:44 -05:00
Ilya Grigoriev
95b752dfe8 cli branch: add alias t for track
This goes with `c`, `s`, `f`. I feel like it's a relatively
common command now that `auto-local-branch` defaults to
`false`.

I didn't add `u` for `untrack` because it seems a little
ambiguous (un-what?); there may be other `branch` commands that undo
something in the future.
2024-01-25 12:59:18 -08:00
Daniel Ploch
20cbe77bf5 workspace: support creating shares of custom workspaces 2024-01-25 11:46:07 -08:00
Daniel Ploch
cb889f0b45 workspace: combine working copy functions into a trait 2024-01-25 11:46:07 -08:00
dependabot[bot]
c2da98471b cargo: bump the cargo-dependencies group with 1 update
Bumps the cargo-dependencies group with 1 update: [chrono](https://github.com/chronotope/chrono).


Updates `chrono` from 0.4.32 to 0.4.33
- [Release notes](https://github.com/chronotope/chrono/releases)
- [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chronotope/chrono/compare/v0.4.32...v0.4.33)

---
updated-dependencies:
- dependency-name: chrono
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-25 15:57:04 +00:00
dependabot[bot]
d1dad19000 github: bump the github-dependencies group with 1 update
Bumps the github-dependencies group with 1 update: [EmbarkStudios/cargo-deny-action](https://github.com/embarkstudios/cargo-deny-action).


Updates `EmbarkStudios/cargo-deny-action` from 1.5.11 to 1.5.12
- [Release notes](https://github.com/embarkstudios/cargo-deny-action/releases)
- [Commits](2b35f42b96...748857f070)

---
updated-dependencies:
- dependency-name: EmbarkStudios/cargo-deny-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-25 07:52:43 -08:00
Ilya Grigoriev
69bc1f2b0f docs branches.md: insert definitions for related terms 2024-01-24 18:47:17 -08:00
Ilya Grigoriev
5eb55b035e docs branches.md: updates to jj branch (un)track docs 2024-01-24 18:47:17 -08:00
Ilya Grigoriev
ef23c35550 docs branches.md: explain the new defaults and reorganize
This follows up on #2625 and updates all sections of `branches.md` to represent
the new default of `git.auto-local-branch=false`.

I realized that the paragraph we discussed for so long with @PhilipMetzger
actually repeats information that was already present a bit earlier in the file.
So, I removed most of it and moved the rest. Sorry I didn't notice this earler.

## The callout

Unfortunately, GitHub and MkDocs use different syntax for admonitions.

The callout looks like this in MkDocs:
https://github.com/martinvonz/jj/assets/4123047/45d79e7a-35db-492e-a227-004b7e3383c1

Use `poetry run -- mkdocs serve` to double-check.
2024-01-24 18:47:17 -08:00
dependabot[bot]
9e15fba494 github: bump the github-dependencies group with 2 updates
Bumps the github-dependencies group with 2 updates: [EmbarkStudios/cargo-deny-action](https://github.com/embarkstudios/cargo-deny-action) and [actions/upload-artifact](https://github.com/actions/upload-artifact).


Updates `EmbarkStudios/cargo-deny-action` from 1.5.10 to 1.5.11
- [Release notes](https://github.com/embarkstudios/cargo-deny-action/releases)
- [Commits](1350841d09...2b35f42b96)

Updates `actions/upload-artifact` from 4.2.0 to 4.3.0
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](694cdabd8b...26f96dfa69)

---
updated-dependencies:
- dependency-name: EmbarkStudios/cargo-deny-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-dependencies
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-24 12:33:06 -06:00
Jonathan Tan
6fa5d456f8 util gc: allow specifying prune time
This only affects pruning of the operation log for now, and only
supports the string "now" for now.
2024-01-24 09:29:40 -08:00
Daniel Ploch
4024fb4880 cli_util: improve API for editing text in a tempfile
Consolidates bulky tempfile code in sparse.rs and description_util.rs into cli_util.rs
2024-01-23 23:49:35 -08:00
Yuya Nishihara
5a7d8ac596 working_copy: don't follow symlinks when visiting files in gitignored directory
Fixes #2878
2024-01-24 16:38:48 +09:00
Yuya Nishihara
d0d4496258 tests: add executable files and symlinks to gitignored directory test 2024-01-24 16:38:48 +09:00
Stephen Jennings
57d5abab0c cli: display which file's conflicts are being resolved 2024-01-23 08:59:43 -08:00
dependabot[bot]
e403bd1547 cargo: bump the cargo-dependencies group with 2 updates
Bumps the cargo-dependencies group with 2 updates: [clap_complete](https://github.com/clap-rs/clap) and [chrono](https://github.com/chronotope/chrono).


Updates `clap_complete` from 4.4.8 to 4.4.9
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.4.8...clap_complete-v4.4.9)

Updates `chrono` from 0.4.31 to 0.4.32
- [Release notes](https://github.com/chronotope/chrono/releases)
- [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chronotope/chrono/compare/v0.4.31...v0.4.32)

---
updated-dependencies:
- dependency-name: clap_complete
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
- dependency-name: chrono
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-23 15:34:43 +00:00
dependabot[bot]
6f222e466b github: bump the github-dependencies group with 1 update
Bumps the github-dependencies group with 1 update: [EmbarkStudios/cargo-deny-action](https://github.com/embarkstudios/cargo-deny-action).


Updates `EmbarkStudios/cargo-deny-action` from 1.5.9 to 1.5.10
- [Release notes](https://github.com/embarkstudios/cargo-deny-action/releases)
- [Commits](c9a2a63163...1350841d09)

---
updated-dependencies:
- dependency-name: EmbarkStudios/cargo-deny-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-23 15:29:11 +00:00
Martin von Zweigbergk
502150b2f4 conflicts: test materialization with with negative snapshots
We didn't have any tests with negative snapshots (after a `-------`
line). I initially thought we couldn't produce such conflict markers
anymore. I'm not sure we want to render conflicts like the one in the
test like this. I don't think I intended for `add_index` in the code
to be able to be two steps ahead of the remove. Maybe we should
rewrite the algorithm to not do that and thus never produce negative
snapshots.
2024-01-23 07:18:54 -08:00
Yuya Nishihara
566713bf6b cli: colorize choices of prev/next commits 2024-01-23 15:01:25 +09:00
Ilya Grigoriev
d168fd2b09 test_rebase_abandoning_empty: add children of an empty @ to the test case
This demonstrates the minor bug discussed in
https://github.com/martinvonz/jj/pull/2766#discussion_r1442365389
AKA https://github.com/martinvonz/jj/issues/2869.

It's also interesting whether changing the definition of "discardable" commit
would affect this test, see
https://github.com/martinvonz/jj/issues/2859#issuecomment-1903275884

(I think it won't, but still)
2024-01-22 18:36:49 -08:00
Yuya Nishihara
2839922e57 ui: remove redundant .to_lowercase() from prompt_yes_no() 2024-01-23 08:48:58 +09:00
Martin von Zweigbergk
63c4de3cf7 docs: try to clarify that jj doesn't need a staging area
Wol on lwn.net pointed out that our current description in the Git
Comparison doc for why there is no staging area can be interpreted as
saying that it's because it simplifies the CLI. It took me a while to
see that interpretation, but it makes sense to me now. This patch
tries to clarify that we have better tools than the staging area for
manipulating commits.
2024-01-22 15:47:24 -08:00
Jonathan Tan
0bc1341fd0 revset: add count_estimate() to Revset trait
The count() function in this trait is used by "jj branch" to determine
(and then report) how many commits a certain branch is ahead/behind
another branch. This is currently implemented by walking all commits
in the revset, counting how many were encountered. But this could be
improved: if the number is large, it is probably sufficient to report
"at least N" (instead of walking all the way), and this does not scale
well to jj backends that may not have all commits present locally (which
may prefer to return an estimate, rather than access the network).

Therefore, add a function that is explicitly documented to be O(1)
and that can return a range of values if the backend so chooses.

Also remove count(), as it is not immediately obvious that it is an
expensive call, and callers that are willing to pay the cost can obtain
the exact same functionality through iter().count() anyway. (In this
commit, all users of count() are migrated to iter().count() to preserve
all existing functionality; they will be migrated to count_estimate() in
a subsequent commit.)

"branch" needed to be updated due to this change. Although jj
is currently only available in English, I have attempted to keep
user-visible text from being assembled piece by piece, so that if we
later decide to translate jj into other languages, things will be easier
for translators.
2024-01-22 15:07:00 -08:00
Jonathan Tan
08da40bc82 branch: refactor ahead/behind message
A subsequent commit will teach more variants of ahead/behind messages,
so refactor the existing code to avoid code duplication and a future
combinatorial explosion.
2024-01-22 15:07:00 -08:00
Daniel Ploch
22117171bd changelog: update changelog for next/prev changes 2024-01-22 13:58:45 -08:00
Daniel Ploch
32b982e507 next: support prompting for ambiguous commit targets
Resolves part of issue #2126
2024-01-22 13:58:45 -08:00
Daniel Ploch
deaea0732a testing: allow testing of commands that expect stdin 2024-01-22 13:58:45 -08:00
Daniel Ploch
b4b1a21e70 next: fix branching tests to actually test ambiguous targets 2024-01-22 13:58:45 -08:00
Daniel Ploch
f3edc75c81 ui: add helpers for prompting from a set of values
Prompts are barely used in the CLI currently but they are very useful in extensions with more complex workflows.
2024-01-22 13:58:45 -08:00