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

161 commits

Author SHA1 Message Date
Yuya Nishihara
16f2b82feb conflicts: change diff line marker to %%%%%%%
I feel the original -------/+++++++ pair is slightly confusing because
each half can be a separator by itself. I don't know what character other
than '-'/'+' is preferred, but let's pick '%' (for "mod") per @martinvonz
suggestion.
2022-09-20 15:26:29 +09:00
Martin von Zweigbergk
6812bd9584 cleanup: rename checkout to wc_commit
`wc_commit` seems clearer than `checkout` and not too much longer. I
considered `working_copy` but it was less clear (could be the path to
the working copy, or an instance of `WorkingCopy`). I also considered
`working_copy_commit`, but that seems a bit too long.
2022-09-18 16:19:58 -07:00
Yuya Nishihara
c9c3735faf cli: add basic support for 'jj log PATH'
In the current implementation, tree is diffed twice if both PATH and -p
are specified. If this adds significant cost, we'll need to reimplement
it without using a revset abstraction (or maybe adjust revset/graph API.)
2022-09-16 13:02:58 +09:00
Ilya Grigoriev
3244398e89 Fix rebase -r of a parent of a merge commit
Previously, using `rebase -r` on the parent of a merge commit
turned it into a non-merge commit. In other words, starting
with

```
    o   d
    |\
    o | c
    o | b
    | o a
    |/  
    o 
```

and doing `rebase -r c -d a` resulted in

```
    o d
    o b
    | o c
    | o a
    |/  
    o 
```

where `d` is no longer a merge commit.

For reference, here's a complete test that passed before this commit (but should NOT pass; see the diff for a test that should pass):

```
#[test]
fn test_rebase_single_revision_merge_parent() {
    let test_env = TestEnvironment::default();
    test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
    let repo_path = test_env.env_root().join("repo");

    create_commit(&test_env, &repo_path, "a", &[]);
    create_commit(&test_env, &repo_path, "b", &[]);
    create_commit(&test_env, &repo_path, "c", &["b"]);
    create_commit(&test_env, &repo_path, "d", &["a", "c"]);
    // Test the setup
    insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
    @
    o   d
    |\
    o | c
    o | b
    | o a
    |/
    o
    "###);

    let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "a"]);
    insta::assert_snapshot!(stdout, @r###"
    Also rebased 2 descendant commits onto parent of rebased commit
    Working copy now at: 3e176b54d680 (no description set)
    Added 0 files, modified 0 files, removed 2 files
    "###);
    insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
    @
    o d
    | o c
    o | b
    | o a
    |/
    o
    "###);
}
```
2022-09-12 12:23:21 -07:00
Yuya Nishihara
b21a123bc8 cli: ensure rebase destinations are unique and not form a merge with root 2022-09-12 23:46:15 +09:00
Josh Soref
fd3f8afe1a spelling: nonexistent
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-09-09 11:58:37 -07:00
Yuya Nishihara
872081c867 tests: use testutils::new_temp_dir() thoroughly 2022-09-07 23:49:46 +09:00
Glen Choo
468418f1ce cli: add interdiff command
Add the `jj interdiff` command for comparing only the diffs of commits.
Its args are identical to that of `jj diff`, minus `--revision` (because
interdiff always requires two commits).

Like `jj obslog -p`, Changes introduced by intervening commits are
ignored by rebasing `--from` onto `--to` 's parents.
2022-09-02 02:59:37 +08:00
Yuya Nishihara
c5aab9fe29 cli: fix crash on "jj merge whatever root" 2022-09-01 13:36:17 +09:00
Yuya Nishihara
1cc7fc4cd9 cli: error out if "new" parent revisions aren't unique
If more than one parents are specified, the user would expect a merge
commit.
2022-09-01 13:36:17 +09:00
Martin von Zweigbergk
3a46623446 cli: make jj merge delegate to jj new 2022-08-31 07:51:32 -07:00
Martin von Zweigbergk
d3286c2847 tests: use jj new instead of jj merge in tests
Because `jj new` updates to the new commit, this makes them a little
simpler.
2022-08-31 07:51:32 -07:00
Martin von Zweigbergk
a1a980d395 cli: make jj new create a merge commit if more than one arg given
`jj merge` just creates an empty change, which is practically the same
as `jj new`. The main difference is that the former requires more than
one argument and the latter requires at most one argument. It seems
cleaner to generalize them and make them aliases. This patch starts
doing that by making `jj new` accept more than one argument.

Instead of having `jj merge` be exactly an alias for `jj new`, we may
want to make it a thin wrapper that just checks that more than one
argument was given. That would probably be less confusing to users who
run `jj merge` without arguments to see what it does.

We should probably make `jj checkout` also be an alias for `jj new`,
but that will have to wait until we have removed support for open
commits (since `jj checkout` still has logic for dealing with open
commits).
2022-08-31 07:51:32 -07:00
Martin von Zweigbergk
b5378caa81 cli: make jj move/squash/unsquash ask for combined description
In 8ae9540f2c, I made `jj move/squash/unsquash` not abandon the
working copy if it became empty because that would lose any
description associated with it. It turned out that the new behavior
was also confusing because it made it unclear if the working-copy
commit was actually abandoned. Let's roll back that change and instead
ask the user for a combined description when both the source and
destination commits have non-empty descriptions. Not discarding a
non-empty description seems like a good improvement regardless of the
behavior related to working-copy commits. It's also how `hg fold`
behaves (though hg doesn't allow the description to be empty).
2022-08-30 21:41:26 -07:00
Martin von Zweigbergk
478dfd74fc tests: teach fake editor to check that initial text is as expected 2022-08-30 21:41:26 -07:00
Jonathan Tan
a9606a8269 tests: stop libgit2 from accessing config files
libgit2 by default will respect config files present on a user's
machine---in particular, when creating a new repo, it will read
`init.defaultBranch` to determine what the name of the default branch
should be. This makes the tests non-hermetic, so disable that feature.

On my machine, `init.defaultBranch` is set in system config. Without
this patch, `test_git_colocated` and
`test_git_colocated_rebase_on_import` fail, but with this patch, they
pass.
2022-08-30 14:45:02 -07:00
Martin von Zweigbergk
0d1bf7cb3b cli: disable open commits by default 2022-08-26 23:34:52 -07:00
Martin von Zweigbergk
36b98f25fa tests: replace a jj open X; jj co X by jj edit X
We now allow editing a closed commit, so let's do that. That makes the
impact on tests a bit smaller when we disable open commits by default
next.
2022-08-26 23:34:52 -07:00
Martin von Zweigbergk
cd458ec96b cli: teach jj checkout a -m flag, to match jj new
The two commands are very similar and we should probably make one an
alias of the other (or just delete one), but for now let's at least
make them more similar by supporting `-m` for both.

I currently think `jj new` is more natural when starting a new change
on top of the current one and `jj checkout` is more natural when
starting a new change on top of another one, as well as when you just
want to look around or run tests. `jj checkout` doesn't currently
default to the working copy like `jj new` does. Perhaps we should make
it do that. Will people eventually feel that it's natural to run `jj
checkout` to create a new change on top of the working copy, or will
they feel that it's natural to run `jj new` on an unrelated commit
even to just look around, or will we want them as synonyms forever?
2022-08-26 23:34:52 -07:00
Yuya Nishihara
7eed4068e9 cli: do not discard working copy changes recovered from stale state
Otherwise the subsequent command would rerun the checkout, which would fail
if the diff contained added files.
2022-08-19 00:11:23 +09:00
Martin von Zweigbergk
3e79eacaf7 cli: snapshot working copy even on e.g. jj diff -r <some hash>
I was initially worried about the cost of always snapshotting the
working copy, so that's why e.g. `jj diff -r <some hash>` doesn't do
it. However, there's been a few caused by missing snapshotting, and
there are still a few (I just noticed it in `jj undo` while writing
this patch). Let's always do the snapshotting and if the user really
doesn't want it, they can pass `--no-commit-working-copy` (which we
should probably rename to `--no-snapshot-working-copy` or maybe just
`--no-snapshot`). That should reduce bugs and make the CLI more
predictable.

Two test cases were affected becasue `jj merge` also didn't snapshot
the working copy.

Before this patch, e.g. `jj co --no-commit-working-copy` would error
out, but now it will succeed (without touching the working copy,
leaving the working copy stale). That may be confusing, but it should
be easy to recover from (e.g. by `jj undo`). We can consider adding a
check for it later if it seems too confusing (it's probably rarely
something the user wanted).
2022-07-29 22:06:53 +02:00
Martin von Zweigbergk
8bc4574ee5 cli: push only branches pointing to @ by default
Since we now allow pushing open commits, we can implement support for
pushing the "current" branch by defining a "current" branch as any
branch pointing to `@`. That definition of a current/active seems to
have been the consensus in discussion #411.

Closes #246.
2022-07-13 16:23:13 -07:00
Yuya Nishihara
c2ce1eedca diff: make sure word diff print final newline
Since whitespace change is barely visible in color-words diff, I think it
would be too verbose to add "\ No newline at end of file" marker. Let's just
append missing newline to make the command output readable.
2022-07-07 23:29:18 +09:00
Martin von Zweigbergk
c2c32ba0dc cli: don't use stale index to look up snapshotted working copy 2022-07-05 00:42:40 -07:00
Martin von Zweigbergk
7a99257040 cli: add a --dry-run for jj git push 2022-07-04 22:50:40 -07:00
Martin von Zweigbergk
c10c510e01 cli: make jj git push print what it's going to push
It's convenient to push all changed branches every time with `jj git
push`, but sometimes I want to know which branches were actually
pushed. This make the command print what it's going to do.

I'll add a `--dry-run` mode and tests next.
2022-07-04 22:50:40 -07:00
Martin von Zweigbergk
3aaeca9e1c tests: add test for successful push
I think I had not added tests for successful push before because I
thought there was some issue with testing it with libgit2. There *is*
an issue, which is that libgit2 requires the remote to be bare when
it's on local disk, but we can very easily make the git repo bare in
this test.

I also updated the error handling in the `git` module to not let
follow-on errors hide the real error and to not fail if two branches
moved to the same commit.
2022-07-04 22:50:40 -07:00
Martin von Zweigbergk
a2b4bd239f cli: check that clone target is an empty dir if it exists
We used to check only if the destination already had a `.jj/`
directory. This patch changes that to check that the destination is an
empty directory.

Closes #399.
2022-07-01 09:03:24 +08:00
Martin von Zweigbergk
5d871810a1 tests: add test for jj git clone
We didn't seem to have any. I included a test for #399.

The tests also showed how the debug formatting (`{:?}`) results in
escaped (e.g.) backslashes on Windows, which is not what we want, so I
also fixed that.
2022-07-01 09:03:24 +08:00
Martin von Zweigbergk
418ab22be0 cli: add config for using only new UX for open commits
By adding `ui.open-commits=false` in your config, you can now make `jj
checkout` always create a new working-copy commit on top of the
specified commit. If the config is set, open commits will also appear
in the same color as closed commits in `jj log` etc. This will let
some of us experiment with the new UX before we decide if it's a good
idea or not. I left `jj close` in place because it's useful for
setting a description and creating a new commit in one step.

I didn't mention the new config in the release notes because I hope we
can reach a decision and remove the config before the next release.
2022-07-01 08:58:08 +08:00
Martin von Zweigbergk
42b2937d5e cli: add jj edit for editing a commit in the wokring copy 2022-07-01 08:58:08 +08:00
Martin von Zweigbergk
54285a9c56 tests: add test of jj checkout
I'm about to change how `jj checkout` works w.r.t. open/closed commits
(and in particular by moving some logic from the library crate to the
CLI), so let's make sure we have some test coverage.
2022-07-01 08:58:08 +08:00
Martin von Zweigbergk
9c55d98842 cli: rename jj edit to jj touchup 2022-07-01 08:58:08 +08:00
Martin von Zweigbergk
fc4b109e5b cli: allow pushing open commits
Since we're thinking of removing the concept of open and closed
commits, we can't use that open/closed distinction to decide to not
push some commits.
2022-07-01 08:58:08 +08:00
Martin von Zweigbergk
051c01491c cli: teach obslog an option to show diff
This patch adds `jj obslog -p` for including the diff compared to the
predecessor (the first predecessor if there are several). If the
predecessor's parents are different, then we create a temporary tree
by rebasing the predecessor to have the same parents and we use the
result as base for the diff. That way, we avoid polluting the diff
with the changes caused by the rebase. (I don't think we currently
have any commands that can change both parents and content, so the
diff should always be empty for rewrites caused by a rebase.)

Working on this also reminded me that it'll be really nice when we
replace `jj obslog` by something based on the operation log - I really
miss seeing information about the operation in the output (like `hg
obslog` gets from its obsmarkers).
2022-06-14 04:39:49 -07:00
Martin von Zweigbergk
a4a148104c cli: don't say "Creating branch push-*" if it already exists
I was a bit surprised to see the message when I used `jj git push
--change @-` on a commit that already had a branch because I had
pushed it earlier.

The fix means that we instead print the message even if we later
abandon the transaction (so the branch-creation is not persisted)
because the commit is open, for example. That's already what happens
if the commit is missing a description, and since we're planning to
remove the open/closed concept, I don't think this patch makes it much
worse. We probably should improve it later by printing the message
only once the push has succeeded.
2022-06-10 09:30:55 -07:00
Yuya Nishihara
4dea1f9e16 cli: parse --color option and reconfigure ui
I often redirect the jj output to pager, so I set ui.color = "always" in
config file. This patch allows me to remove such config, and instead specify
--color=always only when needed.
2022-06-10 12:47:06 +09:00
Yuya Nishihara
3d41db1659 config: move NO_COLOR handling from ui, don't override user setting
According to the NO_COLOR FAQ, "user-level configuration files [...] should
override $NO_COLOR." https://no-color.org/

Unfortunately this makes it harder to test the $NO_COLOR behavior since the
test environment isn't attached to a tty. We could allocate a pty or
LD_PRELOAD shim to intercept isatty(), but I feel it would be too much to do.

https://github.com/assert-rs/assert_cmd/issues/138
2022-06-10 12:47:06 +09:00
Martin von Zweigbergk
6667b3efec cli: prevent pushing commits without description, author, or committer
This patch prevents perhaps pushing commits with an empty description
or the placeholder "(no user/email configured)" values for
author/committer.

Closes #322.
2022-06-06 17:31:01 -07:00
Waleed Khan
de1c8f0f37 cli: make jj branch take subcommands, not flags
As per https://github.com/martinvonz/jj/issues/330.
2022-06-06 09:02:56 -07:00
Martin von Zweigbergk
8ae9540f2c cli: make move/squash/unsquash keep empty working-copy commit
If the source commit becomes empty as a result of
`move/squash/unsquash`, we abandon it. However, perhaps we shouldn't
do that if the source commit is a working-copy commit because
working-copy commits are often work-in-progress commits.

The background for this change is that @arxanas had just started a new
change and had set a description on it, and then decided to make some
changes in the working copy that should be in the parent
commit. Running `jj squash` then abandoned the working-copy commit,
resuling in the description getting lost.
2022-05-30 07:52:24 -07:00
Martin von Zweigbergk
3b47b00ed0 tests: add e2e test for jj unsquash
We had tests for `jj move` and `jj squash`, but not for `jj
unsquash`. I'm about to add a `--keep` option, so let's add tests for
the current behavior first.
2022-05-30 07:52:24 -07:00
Martin von Zweigbergk
80f1a6f97d tests: extract a methods for log output in a few more tests 2022-05-30 07:52:24 -07:00
Martin von Zweigbergk
6c6e6cb423 checkout: don't abandon old commit if it has non-empty description
If the user entered a description, we shouldn't abandon it even if it
has no changes to the content.
2022-05-21 22:12:15 -07:00
Martin von Zweigbergk
eedc315821 cli: make jj new always check out the new commit
Before this change, `jj new` would check out the new commit only if it
was created on top of the current commit. I never liked that
special-casing, and after thinking more about how the open/closed
should work (see discussion #321), I think we want `jj new` to behave
similar to how `git/hg checkout` works, so it can effectively replace
the current `jj checkout` command for the use case of starting new
work on top of an existing commit.
2022-05-21 22:12:15 -07:00
Martin von Zweigbergk
0865b1ccff cli: show placeholder text for empty commit message
It can be confusing that some commits (typically the working copy)
don't have a description. Let's show a placeholder text in such cases.

I chose the format to match the "(no email configured)" message we
already have.
2022-05-18 09:16:04 -07:00
Martin von Zweigbergk
f5f3091997 cli: make aliases (for commands and arguments) visible in help
This should help make e.g. `squash` discoverable for users who search
the help output for "amend". It should also help users discover the
builtin abbreviations like `st` (for `status`).
2022-05-17 11:02:03 -07:00
Martin von Zweigbergk
6c83eb6ae3 cli: teach log flag to show commits in reverse order
This adds a `--reversed` flag to `jj log` to show commits with later
commits further down. It works both with and without the graph.

Since the graph-drawing code is already independent of the
relationship between commits, it doesn't need any updating.
2022-05-15 05:17:54 -07:00
Martin von Zweigbergk
87ba11592b cli: make log -s/--git imply -p
`log -s/--summary` and `log --git` without `-p` don't do anything. I
also don't think it's very useful to pass these flags in an alias,
where you would then sometimes also pass `-p` to see the diff summary
in the output. We already have the `diff.format` config for that use
case. So let's make both of these flags imply `-p`.

I implemented it by making the `diff_format` variable an
`Option<DiffFormat>`, which is set iff we should show a patch. That
way we have the condition in one place, and the places we use it
cannot forget to check it.
2022-05-13 03:19:10 -07:00
Martin von Zweigbergk
788831fed3 cli: allow alias after global args, and recursive aliases
Our support for aliases is very naively implemented; it assumes the
alias is the first argument in argv. It therefore fails to resolve
aliases after global arguments such as `--at-op`.

This patch fixes that by modifying the command defintion to have an
"external subcommand" in the list of available commands. That makes
`clap` give us the remainder of the arguments when it runs into an
unknown command. The first in the list will then be an alias or simply
an unknown command. Thanks to @epage for the suggestion on in
clap-rs/clap#3672.

With the new structure, it was easy to handle recursive alias
definitions, so I added support for that too.

Closes #292.
2022-05-12 06:30:27 -07:00