Commit graph

189 commits

Author SHA1 Message Date
Martin von Zweigbergk
2dae5f58dd cli: print a message about new and resolved conflicts
When e.g. `jj rebase` results in new conflicts, it's useful for the
user to learn about that without having to run `jj log` right
after. This patch adds reporting of new conflicts created by an
operation. It also add reporting of conflicts that were resolved or
abandoned by the operation.

There was no measurable performance impact when rebasing a single
commit in the Linux kernel repo.
2023-12-10 12:44:57 -08:00
Yuya Nishihara
a110ec6d95 cli: print failed git export reason for each ref
Not all reasons are actionable, but we print hint in common cryptic cases.
2023-12-09 23:37:00 +09:00
Yuya Nishihara
25fcc3e403 workspace: consider .git symlink when generating relative git_target path
Before, an absolute path would be saved in the git_target file if .git is a
symlink. That's not wrong, but seemed a bit weird. Let's consolidate the
behavior across .git file types.
2023-12-05 14:23:59 -08:00
Yuya Nishihara
899c6375a0 git_backend: don't fully canonicalize .git symlink
Apparently, libgit2 doesn't deduce "core.bare" config from the directory name,
but gitoxide implements it correctly. So we shouldn't blindly canonicalize
the Git repository path. Fortunately, the saved git_target path isn't a fully-
canonicalized form (unless user explicitly sepcified "--git-repo ./.git"), so
we don't need a hack to remap git_target back to the symlink path.

is_colocated_git_workspace() is adjusted since the git_workdir is no longer
resolved from the fully-canonicalized repo path, at least in our code. Still we
have the ".git/.." fallback because test_init_git_colocated_symlink_gitlink()
would otherwise fail. I haven't figured out why, and the test might be actually
wrong compared to the git CLI behavior, but let's not change that for now.

Fixes #2668
2023-12-05 14:23:59 -08:00
Yuya Nishihara
32d3e24177 tests: add weirdly symlinked git repo to demonstrate "repo" tool issue
A git repo created by the "repo" tool doesn't have core.base set, which means
the "bare"-ness relies on the directory name. Gitoxide appears to parse it
correctly, whereas libgit2 doesn't. That's why the symlinked .git repo is no
longer processed as a colocated repo.

#2668
2023-12-05 14:23:59 -08:00
Yuya Nishihara
acac2cd1ee tests: extract helper function that reads "git_target" file 2023-12-05 14:23:59 -08:00
Ilya Grigoriev
48d586cba0 test_abandon_command: create another test for bug 2600
See comments inline for details. Cc #2600.

In particular, I wanted to make sure these behaviors are not affected by #2646.
They don't seem to be.

The tests ended up weirder than expected because of
https://github.com/martinvonz/jj/issues/2600#issuecomment-1835418824. Even
though, right now, the behavior of tests is unaffected by that issue, the
*expected* behavior is different.
2023-12-01 17:03:44 -08:00
Ilya Grigoriev
0634dc5674 test_abandon_command: show change ids in get_log_output
Branches move around a little confusigly with `abandon`. We do want to keep
them, to test their behavior, but we can show the change id to make things
clearer.
2023-12-01 17:03:44 -08:00
Ilya Grigoriev
bb72def464 cli rebase: tests for weird ancestry for -s and -b 2023-11-28 21:36:51 -08:00
Ilya Grigoriev
22abbbea9b cli rebase -r: add tests for weird ancestry, record a bug, fix a comment
Note that one of the new tests panics; this is a newly discovered bug.

In Git, a commit's direct parent is allowed to also be an indirect ancestor
at the same time. `jj` currently tries to prevent this situation, but does
allow it. The correctness of `rebase -r A -d descendant_of_A` currently depends
on this jj-specific behavior; we should change that.

Cc #2600
2023-11-28 21:36:51 -08:00
Chris Krycho
b4caef7fe0 cli: do not allow jj init --git in existing Git repo
Allowing `jj init --git` in an existing Git repo creates a second Git
store in `.jj/repo/store/git`, totally disconnected from the existing
Git store. This will only produce extremely confusing bugs for users,
since any operations they make in Git will *not* be reflected in the
jj repo.
2023-11-28 17:31:54 -06:00
Ilya Grigoriev
6aef4bb52e cli rebase: do not allow -r --skip-empty
This follows up on 3967f63 (see that commit's description for more
motivation) and e79c8b6.

In a discussion linked below, it was decided that forbidding `-r --skip-empty`
entirely is preferable to the mixed behavior introduced in 3967f63.

3967f637dc (commitcomment-133539911)
2023-11-27 10:16:36 -08:00
Ilya Grigoriev
95949e8011 test_abandon_command: rename test 2023-11-25 21:36:35 -08:00
Yuya Nishihara
4f2503cbce cli: show hint of non-tracking remote branches on "jj init --git-repo"
If the existing git repo contains local and remote branches of the same name,
one of the remote branches is probably a tracking remote branch. Let's show
a hint how to set up tracking branches. The tracking state could be derived
from .git/config, but doing that automatically might cause another issue like
#1862, which could have been mitigated by git.auto-local-branch = false.
2023-11-25 16:46:10 +09:00
Ilya Grigoriev
811ac5ff23 cli new: have --no-edit print description of the new commit 2023-11-23 11:15:38 -08:00
Ilya Grigoriev
e33f57a0f5 cli new: add --no-edit option
This allows, for example, creating a merge commit with `jj new a b --no-edit -m Merge`, without
affecting the working copy.
2023-11-23 11:15:38 -08:00
Ilya Grigoriev
aa08de30c7 cli new: Make -r, --before, and --after repeatable
Repeating these is a no-op. This allows:

```shell
jj new -r a -r b # Equivalent to jj new a b
jj new --before a --before b  # Equivalent to jj new a b --before
```

I keep typing the latter and getting an annoying error.
2023-11-23 11:15:38 -08:00
Ilya Grigoriev
22ad4d7599 test_abandon_command: test avoidance of simultaneous direct and indirect descendants
This is similar to the following test:

5186066cf5/cli/tests/test_rebase_command.rs (L264-L269) 

from https://github.com/martinvonz/jj/pull/538.
2023-11-19 16:37:49 -08:00
Ilya Grigoriev
e5cfada7e2 test_abandon_command: remove obsolete TODO
This was fixed in 7c8f66ab0, I believe.
2023-11-19 16:37:49 -08:00
Martin von Zweigbergk
c2d5e3d343 clippy: fix new issues spotted by nightly version 2023-11-16 10:20:07 -08:00
Yuya Nishihara
9533177422 cli: include branch name in non-fast-forwardable error
Just like the other errors.
2023-11-11 07:03:31 +09:00
Yuya Nishihara
27751b0142 tests: add test for moving conflicting branch to one of descendants 2023-11-11 07:03:31 +09:00
Yuya Nishihara
0d21578846 cli: disallow to create new branch by "jj branch set"
Per discussion in https://github.com/martinvonz/jj/discussions/2555. I'm
okay with either way, but it's confusing if we had "branch create" and
"branch set" and both of these could create a new branch.
2023-11-11 07:03:31 +09:00
Yuya Nishihara
aca2a3cf93 tests: don't create new branch by "jj branch set" 2023-11-11 07:03:31 +09:00
Łukasz Kurowski
57d7aeab5e cli: generate commit template after selecting changes
Renamed `description_template_for_commit` to
`description_template_for_describe` since it's only used in
`cmd_describe`.

Renamed `description_template_for_cmd_split` to
`description_template_for_commit` and modified to accomodate empty
`intro` argument.

Fixes #2439.
2023-11-09 15:10:25 +01:00
Yuya Nishihara
70479a712b cli: include branch names in bulk branch creation/update warning
This will probably help notice missing -r flag. Maybe we can also warn if
one of the branch names looks like a revset.

https://github.com/martinvonz/jj/discussions/2555
2023-11-09 15:38:22 +09:00
Yuya Nishihara
a6aa8aa4f4 tests: add test for moving branch forward and backward 2023-11-09 15:38:22 +09:00
Yuya Nishihara
2ac9865ce7 revset: exclude @git branches from remote_branches()
As discussed in Discord, it's less useful if remote_branches() included
Git-tracking branches. Users wouldn't consider the backing Git repo as
a remote.

We could allow explicit 'remote_branches(remote=exact:"git")' query by changing
the default remote pattern to something like 'remote=~exact:"git"'. I don't
know which will be better overall, but we don't have support for negative
patterns anyway.
2023-11-08 07:34:30 +09:00
Yuya Nishihara
f1898a31b5 merge: simply print interleaved conflict values in debug output
We could apply that for the resolved case, but Resolved/Conflicted label
seems more useful than just printing Merge([value]).
2023-11-06 07:21:06 +09:00
Yuya Nishihara
b07b370ed3 merge: simply generate content hash from interleaved values 2023-11-06 07:21:06 +09:00
Yuya Nishihara
d8a7822c38 merge_tools: do not follow or change permission of symlinks
Fixes #2525.
2023-11-06 07:20:52 +09:00
Austin Seipp
e1193db4cf cli: support multiple --revision arguments to workspace add
Summary: A natural extension of the existing support, as suggested by Scott
Olson. Closes #2496.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Change-Id: I91c9c8c377ad67ccde7945ed41af6c79
2023-11-04 10:26:08 -05:00
Yuya Nishihara
c88e69ad6f git_backend: replace git2::Repository with gix::Repository
My gut feeling is that gitoxide aims to be more transparent than libgit2. We'll
need to know more about the underlying Git data model.

Random comments on gix API:

 * gix::Repository provides API similar to git2::Repository, but has less
   "convenient" functions. For example, we need to use .find_object() +
   .try_to/into_<kind>() instead of .find_<kind>().
 * gix::Object, Blob, etc. own raw data as bytes. gix::object and gix::objs
   types provide high-level views on such data.
 * Tree building is pretty low-level compared to git2.
 * gix leverages bstr (i.e. bytes) extensively.

It's probably not difficult to migrate git::import/export_refs(). It might
help eliminate the startup overhead of libssl initialization. The gix-based
GitBackend appears to be a bit faster, but that wouldn't practically matter.

#2316
2023-11-02 19:33:06 +09:00
Yuya Nishihara
f89f2f9e7d cli: add "branch list [NAMES]..." filter
Like "jj log PATHS...", unmatched name isn't an error. I don't think
"jj branch list glob:'push-*'" should fail just because there are no in-flight
PR branches.
2023-11-01 08:38:55 -07:00
Isabella Basso
749d8bb15a git: preserve HEAD when possible
Closes: #2210
2023-11-01 08:23:52 -03:00
Ilya Grigoriev
8bc3f5fd67 cli rebase: Allow jj rebase -r to rebase a commit onto a descendant
#1188

There are some additional test changes because children and descendants are now
rebased before the commit itself.
2023-10-30 10:56:27 -07:00
Martin von Zweigbergk
23a0baba14 cli: make jj workspace add preserve all parents of current workspace 2023-10-29 21:53:29 -07:00
Ilya Grigoriev
b482898924 immutable commits: remove the hint if trying to edit the root commit
The hint is a bit misleading in this case. I also changed the message slightly.
2023-10-29 21:13:39 -07:00
Ilya Grigoriev
ebb6b942ac cli new: have --before/--after respect immutable commits
I wasn't very careful to make the function
pretty; I'm planning to refactor it anyway as
part of implementing `rebase --before` and
`rebase --after`.
2023-10-29 21:13:39 -07:00
Ilya Grigoriev
2571169251 clippy: run cargo clippy --fix --workspace with recent nightly 2023-10-29 20:19:44 -07:00
Yuya Nishihara
0e14a1f04d templater: add local/remote_branches keywords 2023-10-28 11:03:23 +09:00
Yuya Nishihara
01d474563e templater: make branches, tags, git_refs, and git_head return list type
I'm not going to change the default output, but this allows us to highlight
or dim only the @remote component.
2023-10-28 05:29:50 +09:00
Ilya Grigoriev
eeb93cc8be cli change id templates: make "hidden" override "divergent"
See the test changes in `test_undo.rs` for motivation. This matters rarely, but
seems to be better.
2023-10-26 17:58:13 -07:00
Ilya Grigoriev
1733ae22c7 cli templates: include info on divergent change ids in short commit template
Fixes #2411
2023-10-26 17:58:13 -07:00
Ilya Grigoriev
6a128f56ed cli: rebase descendants earlier for jj diffedit and jj restore
Makes sure that, at the point the commit summary for the new commit is written,
the original commit that is being rewritten is already abandoned. Otherwise,
once we show divergent change ids (in a subsequent commit) in the short commit
template, the commits would be shown as divergent.

This also has an effect on whether branches are displayed next to the commit;
the changes in test_resotre_command happen because, now, the branch is properly
propagated to the restored commit before its summary is displayed.
2023-10-26 17:58:13 -07:00
Yuya Nishihara
2874a69faf tests: migrate most tests from test_templater.rs
test_templater_alias(), test_templater_alias_override(), and
test_templater_bad_alias_decl() aren't moved since they also test config loading
and error formatting. The first test in test_templater_parse_error() is left for
the same reason. test_templater_upper_lower() depends on the commit templater.
2023-10-27 05:30:53 +09:00
Yuya Nishihara
957360dc83 tests: use color formatter in core template tests
test_templater_label_function() is migrated as example.
2023-10-27 05:30:53 +09:00
Yuya Nishihara
96f8ca5d54 tests: add minimal template language and test helpers
I don't think many of the tests in test_templater.rs should use "jj log" command
as they check very specific template syntax and function behaviors. Let's move
them to in-module tests. We could add a separate test file, but we would have
to export a couple of templater macros.

test_templater_timestamp_method() is migrated as example.
2023-10-27 05:30:53 +09:00
Yuya Nishihara
b455335983 tests: move test_templater_branches() to test_commit_template.rs
It's not testing the core templater functionality.
2023-10-27 05:30:53 +09:00
Yuya Nishihara
1bfe5b5b56 cli: add string pattern support to "git push --branch"
Since "jj git fetch --branch" supports glob patterns, users would expect that
"jj git push --branch glob:.." also works.

The error handling bits are copied from "branch" sub commands. We might want to
extract it to a common helper function, but I haven't figured out a reasonable
boundary point yet.
2023-10-26 04:51:17 +09:00