Commit graph

123 commits

Author SHA1 Message Date
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
Martin von Zweigbergk
d0ecbaf1a4 graphlog: don't de-indent multi-line text at end of chain 2022-05-11 04:42:44 -07:00
Martin von Zweigbergk
6483aeefea cli: respect $VISUAL, overriding $EDITOR
With this patch, the order is this:

`$JJ_EDITOR` environement variable
`ui.editor` config
`$VISUAL` environement variable
`$EDITOR` environement variable
`pico`

That matches git, except that git falls back to an editor determined
at compile time (usually `vi`) instead of using `pico`.
2022-05-10 10:39:59 -07:00
Martin von Zweigbergk
0f5e360d96 cli: allow config in ~/.jjconfig.toml
As I said in 095fb9fef4, removing support for `~/.jjconfig` was an
experiment. I've heard from a few people (including in #233) that they
would prefer to have configs in the home directory. This patch
therefore restores that functionality, except I added a `.toml`
extension to the file to clarify the expected format to users and
editors.

After this patch, we still allow configs in `$XDG_CONFIG_HOME` (and
the other paths used by `dirs::config_dir()`), but we error out there
are config files in both that location and `~/.jjconfig.toml`.
2022-05-10 10:21:22 -07:00
Martin von Zweigbergk
f5f363f079 cli: make invalid alias definition an error 2022-05-10 04:02:24 -07:00
Martin von Zweigbergk
9df1512b7d cli: use exit code 2 for invalid utf-8 2022-05-10 04:02:24 -07:00
Martin von Zweigbergk
1faffbb5aa tests: check exit code on failure, and fix a bug in argument parsing
We didn't have any testing of exit codes on failure, other than
checking that they were not 0. This patch changes that so we always
check. Since we have the special exit code 2 (set by `clap`) for
incorrect command line, I've replaced some testing of error messages
by testing of just the exit code.

As part of this, I also fixed `jj branch --allow-backwards` to
actually require `-r` (it didn't before because having a default value
means the argument is considered always provided).
2022-05-10 04:02:24 -07:00
Waleed Khan
7a551e584f cli: jj branch can accept any number of branches 2022-05-02 21:33:58 -07:00
Martin von Zweigbergk
305adf05cc cli: when auto-importing from git, rebase descendants 2022-05-02 17:01:38 -07:00
Martin von Zweigbergk
726b29978d tests: show failure in git-shared working copy after deleting commit in git
Since 57ba9a9409, if the automatic import from git results in some
abandoned commit, that information gets recorded in the `MutableRepo`,
but I forgot to add a call to rebase the descendants. That causes a
failed assertion at
81a8cfefcb/lib/src/transaction.rs (L86). This
patch add a test showing that failure.
2022-05-02 17:01:38 -07:00
Waleed Khan
7a99a17304 cli: make jj branch --revision/--delete/--forget mutually-exclusive 2022-05-02 13:44:17 -07:00
Martin von Zweigbergk
81a8cfefcb cli: add a mode of pushing with branch taken from change ID
This adds `jj git push --change <revision>` which creates a branch
with a name based on the revision's change ID, and then pushes that
like with `--branch`. That can be useful so you don't have to manually
add the branch (and come up with a name for it). The created branch
behaves like any other branch, so it's possible to make it point to a
commit with a different change ID.
2022-04-29 15:55:03 -07:00
Martin von Zweigbergk
0719dae975 cli: add a command for listing git remotes and their URLs
As requested by @talpr. I added this is a separate new command `jj git
remote list`. One could also imagine showing the listing when there is
no sub-command specified to `jj git remote`, but we don't have other
commands that behave that way yet.

Closes #243
2022-04-29 14:08:24 -07:00
Martin von Zweigbergk
8ef00a3498 tests: re-run with insta crate version b9d99e87065b 2022-04-28 16:55:10 -07:00
Martin von Zweigbergk
885c780642 cli: add commands for working with sparse patterns (#52)
This adds a `jj sparse` command with options to list and manage the
set of paths to include in the working copy. It only supports includes
(postive matches) for now.

I'm not sure "sparse" is the best name for the feature. Perhaps it
would make sense as a subcommand under `jj workspace` - maybe `jj
workspace track`? However, there's also `jj untrack` for removing a
file from the working copy and leaving it in the working copy. I'm
happy to hear suggestions, or we can get back to the naming later.
2022-04-26 14:52:17 -07:00
Martin von Zweigbergk
6ec3afc75d cli: error out if jj untrack is run at non-head operation 2022-04-26 10:42:29 -07:00
Martin von Zweigbergk
f71047c823 cli: add hard-coded support for specifying previous operation
It's useful for testing to be able to specify some operation that's
not the latest one.

I didn't update the changelog because this feature is mostly for
testing.
2022-04-26 10:42:29 -07:00
Martin von Zweigbergk
f8512226fc cli: return specialized message on non-hex operation ID 2022-04-26 10:42:29 -07:00
Martin von Zweigbergk
6619a18056 tests: add test for jj op log and --at-op
We can't easily test much of the output of `jj op log` because it's
unstable, but here are at least a few tests.
2022-04-26 10:42:29 -07:00
Martin von Zweigbergk
8744015f33 cli: make operation to undo or restore to a positional argument
I originally made the operation argument a named argument
(`--operation`) to allow for a change ID to be passed as a positional
argument, matching e.g. `hg revert -r <rev> <path>`. However, even if
we add support for undoing changes only to certain change IDs, it's
going to be done much less frequently than full undo/restore. We can
therefore make that a named argument if we ever add it.
2022-04-25 17:29:48 -07:00
Martin von Zweigbergk
0058236a43 cli: make jj restore --to <rev> restore from the working copy 2022-04-25 17:29:48 -07:00
Martin von Zweigbergk
9f9af78c45 cli: provide better error message for no-arg jj move 2022-04-25 17:29:48 -07:00
Martin von Zweigbergk
04f11c0dc3 rebase: update bookkeeping for branches as we rebase descendants
The `DescendantRebaser` keeps a map of branches from the source
commit, so it gets efficient lookup of branches to update when a
commit has been rebased. This map was not kept up to date as we
rebased. That could lead to branches getting left on hidden
intermediate commits. Specifically, if a commit with a branch was
rewritten by some command, and an ancestor of it was also rewritten,
then we'd only update the branch only the first step and not update it
again when rebasing onto the rewritten ancestor.
2022-04-25 14:05:27 -07:00
Martin von Zweigbergk
cc7e20859c tests: add tests of jj move to ancestor, showing lost branch
I noticed earlier today that branches get lost (stuck on a hidden
commit) when you move part of a change to an ancestor. This patch adds
tests for both of those cases, showing the bug. There's no special
logic for this case in the CLI crate, so we should be able to test it
in the library crate instead, but since I have already written the
tests, maybe we can keep them.
2022-04-25 14:05:27 -07:00
Martin von Zweigbergk
9d440ca835 tests: remove a duplicate log output in jj move test 2022-04-25 14:05:27 -07:00
Martin von Zweigbergk
cf7bef88fe tests: extract a function for getting log output in jj move test 2022-04-25 14:05:27 -07:00
Martin von Zweigbergk
2e0d80919d cli: some fixes and touch-ups for jj workspace, plus tests 2022-04-22 15:45:35 -07:00
Martin von Zweigbergk
90edd670d9 tests: move tests of Ui from tests/ into ui module
The tests only test the `Ui` type and don't need anything from
`testutils`, so it seems they should be treated as unit tests.
2022-04-22 15:45:35 -07:00
Martin von Zweigbergk
8745ee7030 cli: use . in output for current directory instead of empty string 2022-04-20 13:52:25 -07:00
Martin von Zweigbergk
bd035004b9 tests: use jj_cmd_success() in one more place 2022-04-14 23:46:28 -07:00
Martin von Zweigbergk
3c71ae3c76 cli: make jj rebase default to -b @ (#168)
Closes #168.
2022-04-14 23:46:28 -07:00
Martin von Zweigbergk
30f5471fc3 cli: add mode for rebasing branch onto destination (#168) 2022-04-14 23:46:28 -07:00
Martin von Zweigbergk
7ec93ddb32 tests: also check output from jj rebase
I'd like to have tests showing the number of commits rebased. I just
missed it when adding the tests.
2022-04-14 23:46:28 -07:00
Martin von Zweigbergk
7aac95ac80 test: add tests for jj rebase 2022-04-13 21:27:30 -07:00
Martin von Zweigbergk
109a9422f0 cli: teach jj split to include all specified paths in first commit 2022-04-10 09:13:51 -07:00
Martin von Zweigbergk
d6d2b8b5bc cli: allow overriding ui.editor config by $JJ_EDITOR variable 2022-04-10 09:13:51 -07:00
Martin von Zweigbergk
96d559a4b4 cli: allow overriding $EDITOR variable by ui.editor config 2022-04-10 09:13:51 -07:00
Martin von Zweigbergk
2958f5791c cli: don't crash if $EDITOR fails 2022-04-10 09:13:51 -07:00
Martin von Zweigbergk
f8724ee5a9 tests: add tests for jj describe 2022-04-10 09:13:51 -07:00