Commit graph

552 commits

Author SHA1 Message Date
Ilya Grigoriev
335e86d8e7 test_branch_command: use bare repositories
Otherwise, those tests cannot use `jj git push`. This is an issue with a test
in the next commit, and I don't want people to copy these tests and be surprised.
2023-06-30 21:29:24 -07:00
Ilya Grigoriev
333c348fb9 branch forget & delete: report if forgot/deleted multiple branches 2023-06-30 21:29:24 -07:00
Ilya Grigoriev
f6ddd775b9 branch delete: allow deleting globs of branches 2023-06-30 21:29:24 -07:00
Ilya Grigoriev
144a44914a branch forget: error message if no globs match 2023-06-30 21:29:24 -07:00
Yuya Nishihara
e601a30b15 cli: make log accept multiple -rREVISION expressions
For scripting scenario, multiple -r options are easier to construct than
concatenating expressions with ")|(".
2023-06-29 19:33:32 +09:00
Glen Choo
777b786c53 git: add a hidden submodule subcommand
Add the `submodule` subcommand, which will remain hidden while we are
polishing up the submodules feature. Also, add a debugging-only
sub-subcommand `print-gitmodules` that tests our .gitmodules parser with
the .gitmodules in the working copy.
2023-06-27 10:07:00 -07:00
Grégoire Geis
fee7eb5813 add --edit option to jj sparse set 2023-06-27 22:56:46 +09:00
Yuya Nishihara
3c2657c393 cli: add hint for git-exporting forgotten branches
Inspired by d01ecc5c46 "more detailed message describing deleted branches."

And yes, "jj git export" does propagate "jj branch forget" to the underlying
Git repository, which strengthen my feeling that git::export_refs() should
also remove "forgotten" remote tracking refs.
2023-06-26 13:56:32 +09:00
Yuya Nishihara
72792a8dbe cli: say "(forgotten)" if branch is listed just because it's in git_refs
I thought we would need additional bookkeeping to detect forgotten branches,
but I was wrong. If a branch exists only in git_refs, it is forgotten (but not
yet exported.)
2023-06-26 13:56:32 +09:00
Ilya Grigoriev
bdb6db88e1 cli: new jj chmod command to set executable bit 2023-06-24 13:28:01 -07:00
Ilya Grigoriev
d01ecc5c46 branch list: more detailed message describing deleted branches
Fixes #1537
2023-06-24 09:23:14 -07:00
Ilya Grigoriev
e41d672cc0 branch forget: allow forgetting deleted branches
Partially fixes #1537
2023-06-24 09:23:14 -07:00
Ilya Grigoriev
89a3f8db76 test_branch_command: demo inability to forget deleted branch 2023-06-24 09:23:14 -07:00
Ilya Grigoriev
d217fe069b test_branch_command: test fetching a forgotten branch 2023-06-24 09:23:14 -07:00
Ilya Grigoriev
ee4f8f2876 test_git_fetch: move a fetch test from test_git_import_export 2023-06-24 09:23:14 -07:00
Ilya Grigoriev
08d147be32 test_git_import_export.rs: rename test and modernize terminology 2023-06-24 09:23:14 -07:00
Waleed Khan
24ea8478cb feat(config): add jj config get for scripting
The motivating use-case was this `jj signoff` script: https://gist.github.com/thoughtpolice/8f2fd36ae17cd11b8e7bd93a70e31ad6

Which includes lines like this:

```sh
NAME=$(jj config list user.name | awk '{split($0, a, "="); print a[2];}' | tr -d '"')
MAIL=$(jj config list user.email | awk '{split($0, a, "="); print a[2];}' | tr -d '"')
```

There is no reason that we should have to clumsily parse out the config values. This `jj config get` command supports scripting use-cases like this.
2023-06-23 12:07:39 -07:00
Kevin Liao
86b6a11e63 Fix jj init --git-repo fails and leaves broken .jj folder
This commit fixes #1305

Before this commit, running `jj init --git-repo=./` in a folder that
does not have a .git would cause jj to panick and leave an unfinished corrupted jj repo.

This commit fixes that by changing the call chain to return an error
instead of calling .unwrap() and panicking. This commit also adds logic to delete the unfinished jj
repository when the git backend initialization failed.

Before this commit, running the above command would result in the following
```
Running `jj/target/debug/jj init --git-repo=./`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { code: -3, klass: 2, message: "failed to resolve path '/Users/kevincliao/github/jj/test-repo/.jj/repo/store/../../../.git': No such file or directory" }', lib/src/git_backend.rs:83:75
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

After this commit, the result is the following and the jj repo is deleted:
```
Running `jj/target/debug/jj init --git-repo=./`
Error: Failed to access the repository: Error: Failed to open git repository: failed to resolve path '/Users/kevincliao/github/jj/test-repo/.jj/repo/store/../../../.git': No such file or directory; class=Os (2); code=NotFound (-3)
```
2023-06-20 11:02:06 -07:00
Ilya Grigoriev
096538ba18 revsets: stop jj parsing br as a git_ref refs/heads/br
Use `br@git` instead.

Before, if there is not a local branch `br`, jj tried to resolve
it as a git ref `refs/heads/br`. Unchanged from before, `br` can
still be resolved as a tag `refs/tag/br`.
2023-06-12 14:31:44 -07:00
Ilya Grigoriev
a483252cf2 revset: allow checking out git-tracking (@git) branches 2023-06-12 14:31:44 -07:00
Ilya Grigoriev
d5e8896d1b tests: demo jj branch forget behavior in colocated repos 2023-06-12 14:31:44 -07:00
Ilya Grigoriev
8df945b71d cmd: have jj branch list report git-tracking (@git) branches
This doesn't change the way @git branches are stored in `git_refs` as opposed
to inside `BranchTarget` like normal remote-tracking branches. There are
subtle differences in behavior with e.g. `jj branch forget` and I'm not sure
how easy it is to rewrite `jj git import/export` to support a different
way of storage.

I've decided to call these "local-git tracking branches" since they track
branches in the local git repository. "local git-tracking" branches sounds a
bit more natural, but these could be confused with there are no remote
git-tracking branches. If one had the idea these might exist, they would be
confused with remote-tracking branches in the local git repo.

This addresses a portion of #1666
2023-06-12 14:31:44 -07:00
Martin von Zweigbergk
ddb07e639c merge_tools: simplify error message for complex conflicts
Since e48ace56d1, the number of adds in the hunk is always exactly
one more than enumber of removes, so we can simplify the condition and
the error message accordingly.
2023-06-07 13:45:16 -07:00
Ilya Grigoriev
337544cf96 No-op clarification of import_export tests 2023-06-07 13:42:48 -07:00
Ilya Grigoriev
fa1e961f53 jj debug operation --display id option to show current operation id for tests
I also considered `jj operation id`, but I'm not sure this is useful outside tests
2023-06-07 13:42:48 -07:00
Waleed Khan
0fff404fb2 cleanup: fix clippy issues 2023-06-05 11:11:17 -05:00
Martin von Zweigbergk
7f3d07e35f cli: add jj git push -r for pushing branches pointing to revset
I think I will find this useful in at least two cases:

1. When you already have a branch pointing to some commit, it's easier
   to do `jj git push -r xyz` than `jj git push --branch
   push-xyzxyzyxzxyz`.

2. When you have a stack of changes, it's useful to be able to push
   all of them at once.

I think we should also update the default behavior of `jj git push` to
be `jj git push -r 'remote_branches()..@'` or something like
that. That removes the ugliness of having a default behavior that the
user can't reproduce using flags. I'll leave that change for a
separate PR.
2023-06-04 20:50:11 -07:00
Martin von Zweigbergk
abcfebf1e2 cli: allow jj git push --change xyz --branch foo
This was pretty simple. I simplified a bit by making the transaction
description mention only branches, not changes. It still mentions the
branches created for the changes, however. Also, since the operation
"tags" contain the full command line, I think it'll still be
relatively easy for the user to understand what the operation was
about.
2023-06-04 20:50:11 -07:00
Martin von Zweigbergk
35b19b1e28 cargo: upgrade clap from to 4.1.11 to 4.3.0
I changed `test_early_args` because the first line no longer has a
redundant color reset, so now we test the `Commands:` line instead,
which has actual color (well, bold+underline anyway).
2023-05-31 12:32:26 -07:00
Martin von Zweigbergk
5653827101 cli: add pointer from error message to docs about stale working copy 2023-05-31 06:32:40 -07:00
Martin von Zweigbergk
fb17e6a50e revset: use different errors for ambiguous commit/change IDs
I made a typo and got something like this:

```
Error: Commit or change id prefix "wl" is ambiguous
```

Since we can tell commit ids from change ids these days, let's make
the error message say which kind of id it is. Changing that also kind
of forced me to make a special error for empty strings. Otherwise we
would have to arbitrarily say that an empty string is a commit id or
change id. A specific error message for empty strings seems helpful,
so that's probably for the better anyway.
2023-05-31 06:28:32 -07:00
Yuya Nishihara
d6f1ab697a cli: load revset/template aliases in order of config layers
Since we abuse TOML table syntax to define function aliases, an identical
function alias can be found more than once in the merged config. The merged
config doesn't preserve the definition order, so we need to load aliases
table per layer.
2023-05-23 14:20:55 +09:00
Martin von Zweigbergk
b6691a1d23 cli: make jj sparse --list a subcommand
`jj sparse` is a bit different from other commands in that its `jj
sparse --list` is practically a separate command. Let's make it an
actual subcommand for consistency, and so we can more cleanly add
additional flags for `jj sparse list` in the future. I moved all the
other arguments to `jj sparse set`. I'm not sure if `jj sparse set
--reset` would have been better as `jj sparse reset`, but it is
technically just updating the sparse patterns just like the other
arguments (`--clear`, `--add` , `--remove`).
2023-05-22 09:49:38 -07:00
Martin von Zweigbergk
6a9b527987 tests: test lookup of prefixes from the log output just about
It's easier to follow the test if we try to resolve commits from the
`jj log` output just above. That's what we did until I changed it away
from that without thinking in fcda05c69b.
2023-05-22 07:02:32 -07:00
Martin von Zweigbergk
5d2872d76f tests: restore effectiveness of prefix among hidden commits
When I added `revsets.short-prefixes` in 20ef171d7a, I didn't notice
that I made the test of commit prefixes among hidden commits
ineffective because. This restores that by disabling short prefixes in
the test.
2023-05-22 07:02:32 -07:00
Martin von Zweigbergk
a72898000f tests: avoid hardcoding commit/operation ids when possible
Hardcoded ids cannot be updated with `insta`.
2023-05-22 07:02:32 -07:00
Martin von Zweigbergk
0e18757610 tests: include description in test_git_colocated log template
I think this makes the tests a little clearer.
2023-05-22 07:02:32 -07:00
Yuya Nishihara
c23f1e4161 cli: reload both repo and wc commit if working copy was updated
Otherwise, working-copy snapshot would be taken against wrong parent, which
would cause divergence if the history was previously rewritten.

Fixes #1608
2023-05-22 08:36:38 +09:00
Ilya Grigoriev
714aff63e6 git.rs: properly abandon commits from moved/deleted branches on remote (#864)
This bug concerns the way `import_refs` that gets called by `fetch` computes
the heads that should be visible after the import.

Previously, the list of such heads was computed *before* local branches were
updated based on changes to the remote branches. So, commits that should have
been abandoned based on this update of the local branches weren't properly
abandoned.

Now, `import_refs` tracks the heads that need to be visible because of some ref
in a mapping keyed by the ref. If the ref moves or is deleted, the
corresponding heads are updated.

Fixes #864
2023-05-17 17:57:58 -07:00
Ilya Grigoriev
cf4a603eb4 Tests demonstrating a similar bug with moved rather than deleted branch 2023-05-17 17:57:58 -07:00
Ilya Grigoriev
d654a9e163 TestEnvironment: make it easier to run integration tests with printf debugging
Before this, it was difficult to run an integration test after adding any
directives from printf-style debugging to jj (e.g. `err!`, `eprintln!`,
`println!`), since `jj_cmd_success` fails if `jj` to output anything to stderr
while `jj_cmd_failure` fails if stdout is not empty.

This adds a `TestEnvironment::debug_allow_stderr` variable that lifts this
restriction for `jj_cmd_success` and makes it output anything `jj` output to
stderr instead. You can set it directly or by running the test with the
`DEBUG_ALLOW_STDERR` environment variable set. You can then add `err!`
anywhere.

You do need to run the test in a somewhat special way, as described in the
docstring.
2023-05-14 19:59:50 -07:00
Martin von Zweigbergk
eab5218fe5 cli: allow resolving shorter ids within a configured revset
This adds a config called `revsets.short-prefixes`, which lets the
user specify a revset in which to disambiguate otherwise ambiguous
change/commit ids. It defaults to the value of `revsets.log`.


I made it so you can disable the feature by setting
`revsets.short-prefixes = ""`. I don't like that the default value
(using `revsets.log`) cannot be configured explicitly by the
user. That will be addressed if we decide to merge the `[revsets]` and
`[revset-aliases]` sections some day.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
ac31c83e13 cli: rename ui.default-revset to revsets.log
I plan to add `revsets.short-prefixes` and `revsets.immutable` soon,
and I think `[revsets]` seems like reasonable place to put them. It
seems consistent with our `[templates]` section. However, it also
suffers from the same problem as that section, which is that the
difference between `[templates]` and `[template-aliases]` is not
clear. We can decide about about templates and revsets later.
2023-05-11 23:41:24 -07:00
Ilya Grigoriev
0a51c5fc2e test_git_colocated_fetch_deleted_branch: Fix the test
Before, HEAD@git was at change `e1f4` mentioned in the test. So, as long as we
consider the behavior added in 20eb9ec to be correct, that change should NOT
have been abandoned after the fetch, in spite of what the comment in the test
says. In other words, the test did NOT demonstrate a bug before this commit.

Now, the test properly demonstrates the bug.

Cc #864
2023-05-11 16:35:11 -07:00
Ilya Grigoriev
46422c6502 test_git_colocated: show git head in colocated tests 2023-05-11 16:35:11 -07:00
Yuya Nishihara
92cfffd843 git: on external HEAD move, do not abandon old branch
The current behavior was introduced by 20eb9ecec1 "git: don't abandon
HEAD commit when it loses a branch." While the change made HEAD mutation
behavior more consistent with a plain ref operation, HEAD can also move on
checkout, and checkout shouldn't be considered a history rewriting operation.

I'm not saying the new behavior is always correct, but I think it's safer
than losing old HEAD branch. I also think this change will help if we want
to extract HEAD management function from git::import_refs().

Fixes #1042.
2023-05-11 10:15:31 +09:00
Yuya Nishihara
66d405fa5f git: add tests that simulate external checkout/amend in colocated repo
I'm going to change the behavior of _without_ref() case to mitigate #1042.
2023-05-11 10:15:31 +09:00
Martin von Zweigbergk
9c91f8190d tracing: bump a few trace events from DEBUG to INFO
Now that we don't print INFO-level events by default, we can start
using that level.
2023-05-03 11:40:23 -07:00
Yuya Nishihara
f8d56e816d cli: print parent commit summary on checkout
On "jj checkout", description of the working-copy commit is empty, and the
working-copy parent provides more information. It might be a bit verbose to
print parent summary on every history rewriting, but I think that's okay.
2023-05-02 15:04:13 +09:00
Grégoire Geis
fe653f430e Make tests run on windows-gnu 2023-05-01 13:48:40 +09:00