2133 Commits

Author SHA1 Message Date
Yuya Nishihara
658cd3e0fd git: resolve git2::Repository internally in GitFetch::new()
git2::Repository will be removed from the subprocess code path.
2025-02-01 11:04:38 +00:00
Yuya Nishihara
9bf29accc2 git: resolve git2::Repository internally in push_updates()
git2::Repository will be removed from the subprocess code path.
2025-02-01 11:04:38 +00:00
Yuya Nishihara
fd76b44d55 cli: transform GitFetch/PushError globally 2025-02-01 11:04:38 +00:00
Yuya Nishihara
27e7672a3b git: store bad pattern object in GitFetchError::InvalidBranchPattern
This helps add From<GitFetchError> impl.
2025-02-01 11:04:38 +00:00
Jakob Hellermann
d212becdba cli: complete: use null Ui to prevent writing warnings into completions
E.g. when the user doesn't have the default command set, you don't want
to get
```
Warning: Cannot define an alias that overrides the built-in command 'log'
```
printed on every completion.
2025-02-01 08:37:22 +00:00
Jakob Hellermann
d7c887c424 cli: add ability to construct null Ui without any output 2025-02-01 08:37:22 +00:00
Yuya Nishihara
994c6a457a cli: remove handling of null terminated string from git sideband writer
I think this is copy-paste error from C implementation.
2025-02-01 00:41:51 +00:00
Yuya Nishihara
fc82e99ae9 cli: move cursor to first column after printing git progress bar
This helps sideband writer overwrite the progress bar. Suppose progress
information is less important than sideband messages, it should be okay to
always overwrite the progress bar. The sideband writer will erase the trailing
characters and move the cursor back to the first column, and/or put "\n"
accordingly.
2025-02-01 00:41:51 +00:00
Antoine Martin
c2acc49be5 docs: document the ui.movement.edit config option
This option was introduced in #4283, but was not documented apart from
`prev` and `next`'s help text on the --edit/--no-edit flags.
2025-01-31 23:10:34 +00:00
Martin von Zweigbergk
0f1a6fc4ae rebase: clarify -d/-A/-B arguments with examples 2025-01-31 16:08:15 +00:00
Martin von Zweigbergk
0d00de72c6 cli: git: escape bookmark and remote names in trunk() config
Closes #5359.
2025-01-31 15:54:47 +00:00
Martin von Zweigbergk
b1827e16f1 cli: tests: fix a bad copy&paste 2025-01-31 15:54:47 +00:00
Yuya Nishihara
b637e98127 git: enable sideband message callback globally, disable on fetch without tty
With this and "git --progress" PR #5519, remote git progress will be displayed.

The sideband callback is disabled in git2 code path if progress is not enabled.
If this were enabled, most "git fetch" tests would fail with git2 due to remote
progress messages. Since there's no git2 API to turn the remote progress off,
and the git2 code path is supposed to be phased out, I just inserted ad-hoc
workaround.
2025-01-31 01:47:34 +00:00
Yuya Nishihara
4dd9c5f0a7 git: simplify cast of progress callback 2025-01-31 01:47:34 +00:00
Yuya Nishihara
cdbfd6bc51 git: reimplement get_all_remotes() by using gix API 2025-01-31 00:52:23 +00:00
Yuya Nishihara
7a1cd6a0f6 git: factor out common get_git_backend/repo() helper, simplify error handling 2025-01-31 00:52:23 +00:00
Jakob Hellermann
3293a1aa97 cli: completion: derive clap::ValueEnum for ColorChoice
This enables autocompletion for `jj --color <TAB>`
2025-01-29 22:51:24 +00:00
Matt Kulukundis
5b5a9e71c3 docs: improve cli docs for consistency and links 2025-01-29 18:01:16 +00:00
Baltasar Dinis
120b9cc766 git: forward remote messages to output 2025-01-28 21:56:04 +00:00
Baltasar Dinis
e8620c31ae git: describe codepaths that require git2 2025-01-28 18:29:01 +00:00
Baltasar Dinis
eb1d70317a cli: relocate git fetch code to cli/src/commands/git/fetch.rs
This code was living in cli/src/git_utils.rs but no one else was using
it
2025-01-28 18:29:01 +00:00
Baltasar Dinis
1be574c219 git: update jj git clone|fetch to use new GitFetch api directly.
* Make the new `GitFetch` api public.
* Move `git::fetch` to `lib/tests/test_git.rs` as `git_fetch`, to minimize
  churn in the tests. Update test call sites to use `git_fetch`
* Delete the `git::fetch` from `lib/src/git.rs`.
* Update `jj git clone` and `git_fetch` in `cli/src/git_utils.rs` to use
  the new api directly. Removing one redundant layer of indirection.
* This fixes #4920 as it first fetches from all remotes before `import_refs()`
  is called, so there is no race condition if the same commit is treated
  differently in different remotes specified in the same command.

Original commit by @essiene
2025-01-28 18:29:01 +00:00
Baltasar Dinis
2f8bbb111a tests: refactor cli tests for git 2025-01-28 18:29:01 +00:00
Yuya Nishihara
90e79348e3 diff: remove ad-hoc rename handling in show_diff_stat()
Renamed entries are omitted by iterator/stream since 352a4a0eea8e "copies:
filter rename source entries by CopiesTreeDiffStream."
2025-01-28 01:44:57 +00:00
Ilya Grigoriev
f4346f2e51 cli reference & jj log --help: render URLs in CLI refrerence
Fixes #5490 (we can catch other instances of this manually)

Note that it links to the `latest` even if you are looking at the
`prerelease` docs. This is not ideal, but seems annoying to fix.
2025-01-28 00:50:54 +00:00
Bryce Berger
1bcd55d077 cli: remove double ": : " on git password prompt
`ui.prompt_password()` already adds ": " to the end of the prompt.
Remove the extra at the (only) callsite, to keep similarity to the above
`terminal_get_pw()`.
2025-01-27 22:59:40 +00:00
Yuya Nishihara
93d98f11ba cli: git clone: reload workspace after configuring new remote
I originally thought we could just reinitialize RepoLoader, but it wasn't
enough. Since LocalWorkingCopy holds Arc<Store>, we need to reinstantiate both
working copy and repo loader.
2025-01-27 11:03:39 +00:00
Yuya Nishihara
94754b7f49 cli: add helper method to load workspace at arbitrary path
map_workspace_load_error() is slightly adjusted because we now have three
"user" wc path options: 1. cwd (default), 2. -R path, 3. internal API call.
2025-01-27 11:03:39 +00:00
Yuya Nishihara
dcca1811fe cli: apply log --limit before --reversed
As I said, I don't have strong feeling about the current behavior, and appears
that "log | head | reverse" is preferred over "log | reverse | head".
"jj evolog" already behaves differently, so I just updated the doc.

Note that the new behavior might be slightly different from git, but nobody
would care. (iirc, in git, topological sorting comes later.)

Closes #5403
2025-01-27 01:35:36 +00:00
Yuya Nishihara
9985dce0ab revset: inline reversed() iterator to caller
The implementation isn't specific to revset, and is short.
2025-01-27 01:35:36 +00:00
Scott Taylor
00069119d8 tests: keep user's $PATH while running jj commands
Currently, the Git subprocess tests only work on Linux due to a default
path being used for the `git` executable when `$PATH` is unset. This can
break if Git isn't installed at the expected path. Also, I believe it is
currently necessary to set the `$TEST_GIT_EXECUTABLE_PATH` environment
variable on Windows for tests to pass. Instead, we should use the user's
`$PATH` to locate the `git` executable, as well as any other executables
that are needed. This also makes `$TEST_GIT_EXECUTABLE_PATH` no longer
necessary, so it can be removed.
2025-01-26 17:16:59 +00:00
Ilya Grigoriev
332b8d774a config-schema.json: fixup to default-command
Before this commit, both VS Code's "Even better TOML" and `taplo`
reported an error saying `["status","--no-pager"] is not of type
"string"` for

```toml 
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
ui.default-command = ["status", "--no-pager"]
``` 

I believe the schema was either invalid or just ignored `oneOf` because
it was trivially satisfied whenever the `type` restriction was
satisfied.
2025-01-26 06:03:40 +00:00
Yuya Nishihara
fe54c6276e templater: add diff.files() method
This can be used in order to count the number of added files by
diff.files().filter(..).len(), for example. If we add more advanced fileset
predicates, it can also be expressed as diff("added()").files().len(). The
latter would be cheaper to compute.

For #4154, I'll probably add DiffStats template type. It might be doable by
extending diff.files() method, but I don't think it's good idea to write stats
calculation logic in template language.

Closes #5272
2025-01-26 01:54:33 +00:00
Yuya Nishihara
b22347e80b templater: add TreeDiffEntry types
Tests will be added later.
2025-01-26 01:54:33 +00:00
Yuya Nishihara
e21f8e62cb diff: extract function that maps diff entry to status label and char
I'm going to add diff_entry.status() template method.
2025-01-26 01:54:33 +00:00
Bryce Berger
cbb743cfb5 config: add --when.command to scope resolution
Closes #5217

Motivating use case:

    [[--scope]]
    --when.command = ["log"]
    [--scope.ui]
    pager = "less"

This adds a new (optional) field to `--when` config conditions, to
inspect the current command.

`--when.commands` is a list of space-separated values that matches a
space-separated command. To be specific:

    --when.command = ["file"]        # matches `jj file show`, `jj file list`, etc
    --when.command = ["file show"]   # matches `jj file show`, but *NOT* `jj file list`
    --when.command = ["file", "log"] # matches `jj file` *OR* `jj log` (or subcommand of either)

When both `--when.commands` and `--when.repositories` are set, the
intersection is used.
2025-01-24 05:30:07 +00:00
Yuya Nishihara
362be5914f templater: add list.filter(predicate) method
If we add generic diff template, we'll probably want to filter diff entries by
status, etc.

Closes #5291
2025-01-24 03:42:39 +00:00
Yuya Nishihara
af05534108 templater: extract helper that builds lambda expression body
I also made the helper function accept multiple parameters/arguments as doing
that was easy.
2025-01-24 03:42:39 +00:00
Yuya Nishihara
9683d81f03 templater: load diff parameters from config file
It didn't before just because UserSettings wasn't available to the templater.
2025-01-24 03:42:26 +00:00
Yuya Nishihara
3ed77c9bb3 cli: split diff options constructors to not require command args 2025-01-24 03:42:26 +00:00
Yuya Nishihara
fb25e8a4ad cli: add hint to config error occurred within templater 2025-01-24 03:42:26 +00:00
bsdinis
35440ce1bd git: spawn a separate git process for network operations
Reasoning:

`jj` fails to push/fetch over ssh depending on the system.
Issue #4979 lists over 20 related issues on this and proposes spawning
a `git` subprocess for tasks related to the network (in fact, just push/fetch
are enough).

This PR implements this.

Implementation Details:

This PR implements shelling out to `git` via `std::process::Command`.
There are 2 sharp edges with the patch:
 - it relies on having to parse out git errors to match the error codes
   (and parsing git2's errors in one particular instance to match the
   error behaviour). This seems mostly unavoidable

 - to ensure matching behaviour with git2, the tests are maintained across the
   two implementations. This is done using test_case, as with the rest
   of the codebase

Testing:

Run the rust tests:
```
$ cargo test
```

Build:
```
$ cargo build
```

Clone a private repo:
```
$ path/to/jj git clone --config='git.subprocess=true' <REPO_SSH_URL>
```

Create new commit and push
```
$ echo "TEST" > this_is_a_test_file.txt
$ path/to/jj describe -m 'test commit'
$ path/to/jj git push --config='git.subprocess=true' -b <branch>
```


Issues Closed

With a grain of salt, but most of these problems should be fixed (or at least checked if they are fixed). They are the ones listed in #4979 .

SSH:
- https://github.com/jj-vcs/jj/issues/63
- https://github.com/jj-vcs/jj/issues/440
- https://github.com/jj-vcs/jj/issues/1455
- https://github.com/jj-vcs/jj/issues/1507
- https://github.com/jj-vcs/jj/issues/2931
- https://github.com/jj-vcs/jj/issues/2958
- https://github.com/jj-vcs/jj/issues/3322
- https://github.com/jj-vcs/jj/issues/4101
- https://github.com/jj-vcs/jj/issues/4333
- https://github.com/jj-vcs/jj/issues/4386
- https://github.com/jj-vcs/jj/issues/4488
- https://github.com/jj-vcs/jj/issues/4591
- https://github.com/jj-vcs/jj/issues/4802
- https://github.com/jj-vcs/jj/issues/4870
- https://github.com/jj-vcs/jj/issues/4937
- https://github.com/jj-vcs/jj/issues/4978
- https://github.com/jj-vcs/jj/issues/5120
- https://github.com/jj-vcs/jj/issues/5166

Clone/fetch/push/pull:
- https://github.com/jj-vcs/jj/issues/360
- https://github.com/jj-vcs/jj/issues/1278
- https://github.com/jj-vcs/jj/issues/1957
- https://github.com/jj-vcs/jj/issues/2295
- https://github.com/jj-vcs/jj/issues/3851
- https://github.com/jj-vcs/jj/issues/4177
- https://github.com/jj-vcs/jj/issues/4682
- https://github.com/jj-vcs/jj/issues/4719
- https://github.com/jj-vcs/jj/issues/4889
- https://github.com/jj-vcs/jj/discussions/5147
- https://github.com/jj-vcs/jj/issues/5238

Notable Holdouts:
 - Interactive HTTP authentication (https://github.com/jj-vcs/jj/issues/401, https://github.com/jj-vcs/jj/issues/469)
 - libssh2-sys dependency on windows problem (can only be removed if/when we get rid of libgit2): https://github.com/jj-vcs/jj/issues/3984
2025-01-23 16:50:53 +00:00
bsdinis
c773c0296f git: test git fetch with more than two remotes and branches
In some cases, there are non trivial codepaths for fetching multiple
branches explicitly. In particular, it might be the case that fetching
works for n = 2 but not n = 3.

This commit changes a cli test to have 3 remotes and 3 branches, and a
lib test with 3 branches, only one of them succeds.
2025-01-23 16:50:53 +00:00
Jonathan Frere
55d1c17245 cli: describe: Mark conflicting message/stdin args 2025-01-23 16:11:32 +00:00
Jonathan Frere
e63d1d5114 cli: describe: Add a --edit flag
The --edit flag forces the editor to be shown, even if it would have
been hidden due to the --no-edit flag or another flag that implies it
(such as --message or --stdin).
2025-01-23 16:11:32 +00:00
Yuya Nishihara
8eebac54fc cli: port "file list" to template 2025-01-23 02:21:15 +00:00
Yuya Nishihara
7db343ec32 templater: add TreeEntry type
I'm going to add "file list" template, and I think it's better to provide a file
path as "path", not "self". This patch also adds some tree value properties
which seemed useful.

Tests will be added later.
2025-01-23 02:21:15 +00:00
Yuya Nishihara
5062ae83d3 templater: add RepoPath types
This will be used in "file list" template. Option<RepoPath> type isn't
needed for that, but I think it'll appear somewhere in custom diff template.
The path.parent() method is added mainly for testing Option<RepoPath>.

Tests will be added later.
2025-01-23 02:21:15 +00:00
Yuya Nishihara
ce3100a8cd cli: reformat config/templates.toml
.editorconfig is set to trim trailing whitespace. I also adjusted indent style
and trailing commas.
2025-01-23 02:21:15 +00:00
Yuya Nishihara
2129c8996f cli: migrate "git remote list" to gix
This one is easy, but porting other "jj git remote" sub commands would require
non-trivial work.

The empty [remote "<name>"] case is covered by existing tests.
2025-01-22 12:39:46 +00:00