Robin Stocker
2d9c72ffb1
cli/tests: Prevent git.subprocess from reading outside git config
...
A subset of cli tests could fail if the system /etc/gitconfig had
configuration interfering with the tests. The cause seems to be running
of `jj` commands that would in turn use a `git` subprocess.
Fix this by setting `GIT_CONFIG_SYSTEM` and `GIT_CONFIG_GLOBAL`, like
in `hermetic_git`.
Fixes #6159
2025-03-31 10:46:57 +00:00
Yuya Nishihara
b000c94a7a
tests: add work_dir.dir(path), make create_dir*() return helper for sub dir
...
I found this pattern is common.
2025-03-18 01:25:08 +00:00
Yuya Nishihara
c7811bb956
tests: move strip_last_line() to command_output module
...
The primary caller of this function is CommandOutputString. We can reexport it
if needed.
2025-03-18 01:25:08 +00:00
Yuya Nishihara
7ab62ab865
tests: extract CommandOutput types to sub module
...
These types don't depend on TestEnvironment.
2025-03-18 01:25:08 +00:00
Emily
a56b78bdb6
git: make git2
support optional
...
This helps us prepare for removing the functionality down the line and
makes things easier for people building or packaging their own Jujutsu.
2025-03-16 06:07:28 +00:00
Caleb White
7e944f0d11
cli: config {edit,set,unset}: prompt when multiple files exist
...
This allows the user to select a particular file when using multiple
configs. In the event that a prompt cannot be displayed, the first
file will be automatically selected.
2025-03-13 03:51:52 +00:00
Yuya Nishihara
d5d4c7fe79
tests: port test_absorb_command.rs to TestWorkDir API, add read_file() helper
...
read_file() returns BString as it implements Display.
2025-03-12 02:18:56 +00:00
Yuya Nishihara
e802c4b8fe
tests: move current_operation_id() to TestWorkDir
2025-03-11 01:23:13 +00:00
Yuya Nishihara
61a449554b
tests: pass &TestWorkDir to create_commit*() helper
...
Callers will be ported to TestWorkDir API separately.
2025-03-11 01:23:13 +00:00
Emily
eeb34146ca
tests: remove libgit2
test performance hack
...
I think we should only initialize the library for the fetch/push
tests now, so it should be okay to drop this.
2025-03-10 15:08:08 +00:00
Yuya Nishihara
16028245d6
tests: add workspace test helper, use it in test_global_opts.rs
...
It's super common to pair test_env with repo_path.
Some of the tests still use absolute paths because it seemed rather confusing
to mix paths relative to the repo_root and to the env_root.
2025-03-10 07:50:18 +00:00
Martin von Zweigbergk
0055cd4e0b
cli tests: move create_commit()
tests helpers to common/
2025-03-09 00:44:25 +00:00
Yuya Nishihara
7fa8420908
tests: resolve directory path to run_jj_in() relative to env_root
...
Suppose we'll add test_env.init_workspace(path) or something, this will probably
make sense.
2025-02-25 15:40:14 +00:00
Yuya Nishihara
3634ff298c
tests: simplify jj_cmd() interface, rename to new_jj_cmd()
2025-02-25 15:40:14 +00:00
Yuya Nishihara
28803eef94
tests: rewrite remaining callers of jj_cmd() to use run_jj_in/with()
2025-02-25 15:40:14 +00:00
Yuya Nishihara
ad6985fd9c
tests: migrate unusual patterns of jj_cmd_ok() to run_jj_in()
...
These callers are manually ported to run_jj_in().
2025-02-24 15:39:11 +00:00
Yuya Nishihara
c9926eae4c
tests: implement Debug and Eq for CommandOutput
...
This helps assert that two command invocations generate exactly the same
results.
2025-02-24 00:57:24 +00:00
Yuya Nishihara
a1270f0149
tests: remove stale comment about CommandOutput wrapper
2025-02-24 00:57:24 +00:00
Yuya Nishihara
c83abc9dec
tests: migrate non-snapshot users of jj_cmd_success() to run_jj_in().success()
2025-02-23 13:34:17 +00:00
Yuya Nishihara
317993894b
tests: migrate unusual users of jj_cmd_success() to run_jj_in/with()
...
These callers are manually ported to run_jj_in(). assert_eq!() is changed to
insta::assert_snapshot!() where possible.
2025-02-23 13:34:17 +00:00
Yuya Nishihara
2543329c78
tests: remove unused jj_cmd_panic()
2025-02-23 03:06:59 +00:00
Yuya Nishihara
79a0867050
tests: migrate callers of jj_cmd_internal_error() to run_jj_in()
2025-02-23 03:06:59 +00:00
Yuya Nishihara
b79b29c288
tests: migrate callers of jj_cmd_cli_error() to run_jj_in()
2025-02-23 03:06:59 +00:00
Yuya Nishihara
d19e58f591
tests: migrate callers of jj_cmd_failure() to run_jj_in()
2025-02-23 03:06:59 +00:00
Yuya Nishihara
696cfee55f
tests: stop using assert_eq!() in cli tests where possible
...
Normalize the output instead.
2025-02-23 03:06:59 +00:00
Yuya Nishihara
18ea718113
tests: migrate some helper functions that uses jj_cmd_*() to run_jj_in()
...
Snapshotted operation IDs are changed because this patch reorders "jj new"
command arguments.
2025-02-22 01:23:04 +00:00
Yuya Nishihara
2581cd82be
tests: migrate users of normalize_with() to run_jj_in() function
2025-02-21 01:49:41 +00:00
Yuya Nishihara
cf7f1dfc88
tests: migrate users of normalize_exit_status() to run_jj_in() function
2025-02-21 01:49:41 +00:00
Yuya Nishihara
53664ce2a4
tests: migrate jj_cmd_stdin*() to run_jj*() functions
2025-02-21 01:49:41 +00:00
Baltasar Dinis
683ee9287e
tests: move gitoxide test helpers to testutils
...
These helpers are going to be needed to port the git2 code in the lib
tests to gitoxide. Since the cli tests already depend on testutils, this
helps with avoiding duplicating the code
2025-02-20 06:13:20 +00:00
Yuya Nishihara
de462a6268
tests: add helper to snapshot command output and exit status all at once
...
It's easier to review insta snapshot diffs than scanning panic log containing
lengthy output. I think this will also help printf debugging.
test_global_opts.rs is migrated to new API as an example.
2025-02-20 05:22:32 +00:00
Yuya Nishihara
740d8a2b1b
tests: add #[must_use] to helper functions that return value to be tested
2025-02-20 05:22:32 +00:00
Yuya Nishihara
630036eeb0
tests: add [EOF] marker to command output when displaying
...
It's important to test that command output is (usually) terminated with newline,
but insta::assert_snapshot!() is lax about that.
2025-02-19 02:31:59 +00:00
Yuya Nishihara
a54165230a
tests: add CommandOutputString wrapper
...
I'm going to add "[EOF]" marker to test that command output is terminated by
newline char. This patch ensures that callers who expect a raw output string
would never be affected by any normalization passes.
Some common normalization functions are extracted as CommandOutputString
methods.
2025-02-19 02:31:59 +00:00
Yuya Nishihara
0eddf5f3d6
tests: extract helper function that substitutes $TEST_ENV
...
I'm going to add wrapper type for normalized output, and this change makes
porting a bit easier.
2025-02-19 02:31:59 +00:00
Yuya Nishihara
381bb8a869
tests: create parent directory of .git link file by caller
...
It seems a bit safer to set up the working directory by caller who knows the
test environment directory exists.
2025-02-14 01:14:39 +00:00
Baltasar Dinis
18cd4d3010
cli/tests: add more gitoxide helpers
...
These are helpers for:
- gitlinks
- removing config values
- symbolic references
- status
- index management
2025-02-12 17:06:59 +00:00
Baltasar Dinis
39fe9aad3a
cli/tests: remove allow(unused) from git helpers
2025-02-11 13:46:25 +00:00
Baltasar Dinis
cd6141693b
cli/tests: add gitoxide helpers
2025-02-11 13:46:25 +00:00
Baltasar Dinis
769dbd8f5f
cli/tests: move test environment to its own file
...
The `mod.rs` was becoming crowded and this makes way for unrelated
additions to the test utilities module
2025-02-11 13:46:25 +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
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
Yuya Nishihara
d91e355674
cli: git clone: convert local Git remote path to slash-separated path
...
Since source.contains(':') can't be used for non-local path detection on
Windows, we now use gix::url for parsing. It might be stricter, but I assume it
would be more reliable.
Closes #4188
2024-12-23 09:40:52 +09:00
Yuya Nishihara
78b5766993
repo, workspace: use dunce::canonicalize() to normalize paths
...
These paths may be printed, compared with user inputs, or passed to external
programs. It's probably better to avoid unusual "\\?\C:\" paths on Windows.
Fixes #5143
2024-12-22 09:45:37 +09:00
Yuya Nishihara
d7e0ab6119
tests: use toml_edit to escape editor path, set ui.editor instead of $EDITOR
...
Most callers don't need the $EDITOR variable.
2024-12-20 19:28:01 +09:00
Yuya Nishihara
7ab5b6852b
tests: accept convertible type by set_config_path(), add_config(), add_env_var()
...
It's convenient. We occasionally pass format!()-ed value to these functions.
2024-12-20 19:28:01 +09:00
Yuya Nishihara
ac52e43435
cli: let "config set"/"unset" continue if file to edit can be disambiguated
...
If the user config path was an empty directory, these commands would fail with
EISDIR instead of "can't set config in path (dirs not supported)". I think this
can be changed later to create new "$dir/config.toml" file. Maybe we can also
change the default path to ~/.config/jj directory, and load all *.toml files
from there?
2024-12-15 16:36:29 +09:00
Martin von Zweigbergk
ce04e61dd4
tests: set $COLUMNS
when running CLI tests
...
As reported in #4394 , at least `test_show_command::test_show_basic`
can fail when run with a narrow terminal. This patch sets
`COLUMNS=100` in the environment when running tests so the CLI uses
that value instead of using the width of the user's terminal.
2024-09-05 08:56:04 -07:00
Matt Kulukundis
8ead72e99f
formatting only: switch to Item level import ganularity
2024-08-22 14:52:54 -04:00
Benjamin Tan
fb7c91ffa8
rebase: rewrite rebase_revision
to use transform_descendants
2024-04-22 21:05:49 +08:00