Commit graph

176 commits

Author SHA1 Message Date
Martin von Zweigbergk
20eb9ecec1 git: don't abandon HEAD commit when it loses a branch
I was trying to create a reproduction script for #412, but the script
ran into another bug first. The script removed all the local and
remote branches from the backing Git repo. I noticed that we would
then try to abandon all commits. We should still count Git HEAD's
target as visible and not try to abandon it. This patch fixes that.
2022-10-29 03:02:26 -07:00
Martin von Zweigbergk
efce1e54e6 tests: extract setup of libgit2 config to lib crate
We have some problems with non-hermetic tests in the lib crate, so
we'll want to reuse the setup code there.
2022-10-23 11:08:22 -07:00
Yuya Nishihara
cb2fcde560 revset: implement file(pattern[, candidates]) predicate
The name "file()" is just copied from hg. I'm not sure if it's good in
jj's context, but I couldn't find a better name.
2022-10-24 01:48:00 +09:00
Benjamin Saunders
037eaaf36c repo: forbid checking out the root commit
Prevents `jj edit root` from succeeding, which would otherwise place
the repo in a state where every operation panics.
2022-10-21 10:10:07 -07:00
Benjamin Saunders
305cb3a7ee cli: search @- for branches to push when @ has none 2022-10-20 22:18:48 -07:00
Benjamin Saunders
b009019d8d cli: add git remote rename subcommand 2022-10-20 11:04:16 -07:00
Benjamin Saunders
646fc338ab Include @ in the default revset
Yields a less confusing behavior of `jj log` after pushing a commit.
2022-10-19 13:30:16 -07:00
Martin von Zweigbergk
94501131ac cli: when merging concurrent operations, snapshot afterwards
It seems simpler to do the snapshotting after merging any concurrent
operations instead of snapshotting on top of one of the operations,
especially since the attempt to snapshot may end up noticing that the
working copy is stale.

More importantly, snapshotting before resolving operations resulted in
a crash if the working copy was modified. That happened because we
held a lock on the operation heads (`locked_op_heads`) while we tried
to record the operation committing the working copy. I noticed this
only after adding the test.
2022-10-12 06:22:38 -07:00
Martin von Zweigbergk
5fa21b612c cli: remind the user to configure their name and email
This commit adds a reminder in `finish_transaction()` if the user
hasn't configured their name and email. That means they'll get a
reminder after most mutating commits, except for commands that only
snapshot the working copy, and a few more cases.

Closes #530.
2022-10-09 21:24:05 -07:00
Martin von Zweigbergk
af4d183c7e cleanup: automated fixes by new Clippy version 2022-10-09 12:20:15 -07:00
Martin von Zweigbergk
043d118f1f cli: disallow initializing repo with native backend by default
The native backend is just a proof of concept and there's no real
reason to use it other than for testing, so let's reduce the risk of
accidentally creating repos using it.
2022-10-09 01:00:03 -07:00
Tal Pressman
621caa4dcb add default log revset configuration setting 2022-10-02 16:56:18 +09:00
Martin von Zweigbergk
b561a05d25 cargo: upgrade to clap 4.0.4
I changed the "GLOGAL OPTIONS" help heading to use title case, to
match clap's new help style.

I also removed our override of the help text for `-h, --help` because
the default text now includes "(use `-h` for a summary)" (and it's
harder override now).

Perhaps the most obvious difference to users will be the changed help
output
(https://epage.github.io/blog/2022/09/clap4/#polishing-help-output). It
no longer has color, and long lines are not wrapped. I suppose we
should wrap the text ourselves instead..
2022-09-29 17:53:36 -07:00
Martin von Zweigbergk
d1565fb6eb cli: on push, indicate which branches we're going to force-push 2022-09-27 02:23:05 -07:00
Martin von Zweigbergk
2d2ed53a34 tests: use different commit per branch in jj git push tests
I think I meant for this test to use different commits but because
they have the same content and metadata, they ended up with the same
hash.
2022-09-27 02:23:05 -07:00
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