Commit graph

726 commits

Author SHA1 Message Date
Martin von Zweigbergk
689d9a836a cli: remove incorrect help for jj new
The help text said you can `jj abandon; jj co @-` to go to the parent
commit (it it's an open commit), but `jj abandon` already takes you to
the parent.
2022-05-21 22:12:15 -07:00
Martin von Zweigbergk
db27dd118f cleanup: remove some unused lifetimes 2022-05-21 10:41:45 -07:00
Martin von Zweigbergk
587d8521c5 cli: make op restore require an operation ID
It doesn't make much sense to default to restoring to the current
operation.
2022-05-20 16:19:33 -07:00
Martin von Zweigbergk
b46317596b cli: add update and up as aliases for checkout
Mercurial has these aliases, so it will be familiar for Mercurial
users. My only hesitation about adding these aliases is that we might
want the these names for something else in the future. You could
imagine `up` and `down` commands, for example. We still have a long
time before 1.0, so we have plenty of opportunity to make breaking
changes if we think of some other use for the names :)
2022-05-18 23:47:01 -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
71c789f50b cli: make log show only local commits by default
The default log output of showing all commits is not very useful when
contributing to an existing repo. Let's have it default to showing
commits not on any remote branch instead. I think that's the best we
can do since we don't have a configurable main branch yet, and we
don't even have per-repo configuration..

Closes #250.
2022-05-14 11:50:05 -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
9f6f4b4a55 graphlog: show bug in indentation after chain ends
If a chain ends, we don't count the chain itself when calculating the
padding to use before text. This patch updates a few tests to use
multi-line descriptions so this is seen.

We actually already have a case of this bug `test_operations.rs`. I
noticed that when I added that test, but it didn't bother me enough to
fix it until now.
2022-05-11 04:42:44 -07:00
Martin von Zweigbergk
866539f977 graphlog: use insta for tests
It's much easier to update the tests with `insta`.

It also presents you with the bad output including real newlines (a
diff, actually), so we can remove the `println!()` calls we had in
order to get readable output without escaped newlines.
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
8b54ac58bd config: wrap config errors in our own type 2022-05-10 10:21:22 -07:00
Martin von Zweigbergk
8289e87423 cli: move config-reading to new config module 2022-05-10 10:21:22 -07:00
Martin von Zweigbergk
0bbf360432 cli: move definition of global arguments to separate struct
By having the global arguments on a separate struct, I think it will
be easier to improve how we resolve aliases (#292).
2022-05-10 09:20:45 -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
15070bce5f cli: use exit code 3 for broken pipe
Since `clap` uses exit code 2 for bad CLI arguments, we should use a
different code for broken pipes.
2022-05-10 04:02:24 -07:00
Martin von Zweigbergk
c10247d5df cli: move all process::exit() calls to main.rs
It's cleaner to have all the calls in one place, and this structure
will also make it easier to return other errors from the `dispatch()`
function.

Note that there's still a call to `process::exit()` inside `clap` when
it fails to parse arguments.
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
Martin von Zweigbergk
a4f58ae918 cli: pass Ui as mutable reference to dispatch()
The function only needs a mutable reference (it doesn't store an owned
value anywhere), and this will enable the caller (i.e. `main()`) to
use the `Ui` instance after control returns from `dispatch()`.
2022-05-10 04:02:24 -07:00
Martin von Zweigbergk
cba89886e5 cleanup: replace some for x in xs.iter() by for x in &xs 2022-05-04 17:02:11 -07:00
Martin von Zweigbergk
e4f83e353e errors: use custom error for failed tree merge
Tree merges can currently fail because of a failure to look up an
object, or because of a failure to read its contents. Both results in
`BackendError` because of a `impl From<std::io::Error> for
BackendError`. That's kind of correct in this case, but it wasn't
intentional (that impl was from `local_backend`), and we need to
making errors more specific for better error handling.
2022-05-03 06:52:00 -07:00
Waleed Khan
67be21d9cb cleanup: fix some cargo clippy warnings 2022-05-02 21:49:01 -07:00
Waleed Khan
7a551e584f cli: jj branch can accept any number of branches 2022-05-02 21:33:58 -07:00
Yuya Nishihara
f6acee41df diff_edit: load command arguments from merge-tools.<name> config
Apparently, I need to pass `--merge` option to use kdiff3 as a diff editor.

We could add `diff-editor-args` or extend `diff-editor` to a list of command
arguments, but we'll eventually add stock merge tools and the configuration
would look like:

    [merge-tools.<name>]
    program = ...
    diff-args = [...]
    edit-args = [...]
    merge-args = [...]
2022-05-03 12:24:05 +09:00
Martin von Zweigbergk
1f2753fd3f cli: fix incompatibility between #271 and #273
The two PRs were incompatible, but it seems they were allowed to
"merge" (rebase) because the merge was conflict free?
2022-05-02 17:46:06 -07:00
Martin von Zweigbergk
305adf05cc cli: when auto-importing from git, rebase descendants 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
7268e5608e working_copy: propagate errors when snapshotting
Closes #258
2022-05-02 11:23:38 -07:00
Waleed Khan
4e026c6c93 diff_edit: add hint when using default editor 2022-05-02 08:19:23 -07:00
Martin von Zweigbergk
543a95c653 rewrite: propagate backend errors in DescendantRebase::rebase_next() 2022-05-02 08:05:24 -07:00
Martin von Zweigbergk
96b3e05bc5 working_copy: rename write_tree() to snapshot()
I think I copied the name `write_tree()` from Git, but I find it quite
confusing, since it's not clear if it write a tree to the working copy
or reads the working copy and writes a tree to the store (it's the
former).
2022-05-02 08:00:15 -07:00
Martin von Zweigbergk
b97fd381e5 diff_edit: delete unused error variant (since 9e9727af4e) 2022-05-01 22:58:18 -07:00
Martin von Zweigbergk
5893b52fd1 cleanup: use while let Some(...) instead of checking before popping 2022-05-01 13:45:00 -07:00
Waleed Khan
00a8abcdbb diff_edit: improve error handling
Used to produce a message like this:

```
thread 'main' panicked at 'failed to run diff editor: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/diff_edit.rs:136:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

Now produces a message like this:

```
Error: Failed to edit diff: Error executing editor 'meld': No such file or directory (os error 2)
```
2022-04-30 13:28:38 -07:00
Waleed Khan
2b843d418b cli: don't show bench/debug subcommands by default 2022-04-30 12:56:23 -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
bc75b08f4b cli: extract a function for finding single-branch push update
This will be reused in the next commit.
2022-04-29 15:55:03 -07:00
Martin von Zweigbergk
d42c71f48d errors: fix some easy error propagation in commands.rs
This is actually enough to fix #248, but I'll continue to work on
error handling for a while. I'd like to at least include the bad
object ID in this type of error messages.

Closes #248.
2022-04-29 14:10:16 -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
491d0e3b06 cli: add a debug command for showing information about an operation
This adds `jj debug operation <operation ID>`, which will print the
operation object and its associated view object.
2022-04-29 13:50:22 -07:00
Martin von Zweigbergk
9e9727af4e diff_edit: use sparse checkouts instead of emulating it (#52)
I think we can simply use sparse checkouts for the diff-editing
functionality now that we have it. I'm really happy with how simple it
got :)
2022-04-26 14:52:17 -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
b2f6725a04 cli: extract helper for making changes to the working copy (#52)
Most commands that are going to make changes to the working copy want
to share some logic for detecting concurrent changes, so let's extract
that to a function.
2022-04-26 14:52:17 -07:00
Martin von Zweigbergk
d4732574f4 cli: let caller of select_diff() create matcher
The function becomes more flexible by getting a matcher instead of
paths.
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
01407f261d cli: make resolve_single_op() reusable for loaded repos
When loading a repo, `@` means the latest operation, possibly even
merging any concurrent operations. After loading a repo, `@` means the
operation the repo was loaded at. For example, when running `jj
--at-op=abc123 undo -o @`, `@` will undo operation `abc123`. This
patch therefore makes `resolve_single_op()` more generic by letting
the caller pass in what `@` should resolve to. I also added version of
the function on `WorkspaceCommandHelper` for convenience.
2022-04-26 10:42:29 -07:00
Martin von Zweigbergk
76751edb81 cli: extract a function for resolving the --at-op operation 2022-04-26 10:42:29 -07:00
Martin von Zweigbergk
456a6b3108 cli: inline RepoLoader::load_at_head() in CommandHelper
The function doesn't make anything simpler for us, and I think it will
be easier to implement simple "opsets" (like "revsets" for operations)
if we work directly with the operation objects (instead of repo
objects).
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
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
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
21d8c501e3 cleanup: replace .tree().id() by tree_id() to avoid looking up trees 2022-04-21 21:54:52 -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
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
a6d0f5fe21 cli: extract functions for rebase flavor (#168) 2022-04-14 23:46:28 -07:00
Martin von Zweigbergk
c1e5f88780 cli: don't allow multiple values for jj rebase and jj untrack
Somehow I had thought that setting `clap(required = true)` on a
list-type argument was not enough to convince clap to require at least
one occurrence, but it seems that it does. The `min_values = 1` I had
added to get it to work actually means that we accept multiple values
passed to a single argument (e.g. `jj rebase -d x y z`), which is not
what I had intended.
2022-04-13 21:27:30 -07:00
Martin von Zweigbergk
677dea1682 cli: require at least one destination for rebase
Rebasing onto no commits (i.e. onto the root commit) is almost
definitely not what you meant to do if you run `jj rebase` (without
any arguments).
2022-04-11 15:35:21 -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
90ca03b244 cli: make configs from environment a separate source instead of overrides
This addresses a TODO I had left in the code. In addition to the
reasons I mentioned in the TODO, config sources are also better
because they can be layered. I'm planning on using that for editor
configs, letting `$EDITOR` be a layer under the configs and
`$JJ_EDITOR` be a layer over (matching how `git` does it).
2022-04-10 09:13:51 -07:00
Martin von Zweigbergk
486f49435b cli: if $JJ_CONFIG points to a directory, read all files in it
It's annoying especially for tests to not be able to append to a
config file without knowing the contents (as you have to do with
TOML). Let's read all files in a directory if `$JJ_CONFIG` points to a
directory. Mercurial does that for its `$HGRCPATH` variable.
2022-04-10 09:13:51 -07:00
Martin von Zweigbergk
4be0da3607 cli: teach jj squash to move only changes to specified paths 2022-04-09 16:13:01 -07:00
Martin von Zweigbergk
082ec5ae3b cli: teach jj move to move only changes to specified paths
I quite often want to move the changes to a particular file from one
commit to another. We already support that using `jj move -i`, but
that can be annoying to run because we don't have a TUI for it
(#48). Let's make it possible to do `jj move --from X --to Y <path>`.
2022-04-09 16:13:01 -07:00
Martin von Zweigbergk
385559260c cli: add documentation for remaining few CLI arguments 2022-04-09 16:13:01 -07:00
Martin von Zweigbergk
9a15e32351 cli: require at least one path for jj untrack
It seems very unlikely that the user would want to untrack all paths
(that's still possible with `jj untrack .`, if they really want to,
and have added all their current paths to the `.gitignore`).
2022-04-09 16:13:01 -07:00
Martin von Zweigbergk
88e34d703e cli: let clap error out for us on jj restore -i <file> 2022-04-09 16:13:01 -07:00
Martin von Zweigbergk
3d81d21ff5 tests: fix test checking clap arguments to actually check 2022-04-09 16:13:01 -07:00
Martin von Zweigbergk
bc3c2db828 cli: print errors to stderr 2022-04-09 16:13:01 -07:00
Martin von Zweigbergk
971ca0511b cli: fix formatting of jj help rebase
I think I lost the formatting in the upgrade to clap 3.0.
2022-04-08 18:52:00 -07:00
Martin von Zweigbergk
7a013a59ae cli: add a command for printing the contents of a file in a revision
I'm adding this mostly because it's useful for testing. That's also
the reason it supports displaying conflicts. I didn't call it `cat`
like `hg cat` because I haven't found `hg cat` on multiple files
useful.
2022-04-06 23:31:28 -07:00
Yuya Nishihara
46d96c5a9e cli: extract function that maps settings and command options to diff format
This removes the ui dependency from show_diff(), and clarifies that the
formatter argument is the output stream.

We might eventually trun DiffFormat into a struct, but it's an enum for
now.
2022-04-06 09:46:14 -07:00
Yuya Nishihara
0003c36dfc cli: rename DiffFormat struct to DiffFormatArgs
This avoids future name conflicts. I want to extract the Format enum from
show_diff().
2022-04-06 09:46:14 -07:00
Yuya Nishihara
cff611b481 cli: move Ui::format_file_path() to WorkspaceCommandHelper
With this change, we can eliminate (some of) the ui argument from diff
functions.

parse_file_path() can also be moved to WorkspaceCommandHelper, but I'm
yet to be sure how to reorganize it and matcher builder.
2022-04-06 09:46:14 -07:00
Yuya Nishihara
6c3ec03b72 cli: pass &WorkspaceCommandHelper around diff functions
This prepares for the removal of the ui argument from diff functions. I
think it's a bit confusing that these functions take (ui, formatter)
parameters since both ui/formatter can be output stream.

Ui::format_file_path() will be moved to WorkspaceCommandHelper.

show_git_diff() doesn't need WorkspaceCommandHelper as of now, but I've
also changed its signature for consistency. If we add an option to specify
path formatting of git diff for example, we'll probably need the command
helper.
2022-04-06 09:46:14 -07:00
Martin von Zweigbergk
28916ceb19 cli: in help output, list global options under separate heading
I've found it hard to read the `jj help` output because command
options are mixed with global options. This patch fixes that by
putting global options under a separate heading.
2022-04-02 14:57:48 -07:00
Martin von Zweigbergk
710d51c45b tests: move testutils from src/ to tests/ 2022-04-02 14:22:58 -07:00
Martin von Zweigbergk
f16d2a237b backend: pass in path when reading/writing conflicts as well
We do it for all the other kinds of objects already. It's useful to
have the path for backends that store objects by path (we don't have
any such backends yet). I think the reason I didn't do it from the
beginning was because we had separate `RepoPath` types for files and
directories back then.
2022-03-31 10:23:33 -07:00
Martin von Zweigbergk
034fbb47e3 cli: fix crash when initializing workspace colocated with Git repo
When initializing a workspace that shares its working copy with a Git
repo (i.e. `jj init --git-repo=.`), we import refs and HEAD when
creating the `WorkspaceCommandHelper` (as we do for all commands when
the working copy is shared). That makes the explicit import we do in
`cmd_init()` unnecessary. It also makes the checkout of HEAD I added
for the fix of #102 unnecessary. More importantly, as @yuja reported
in #177, it makes the command crash (at least if the repo is small
enough that the two checkouts happen within a second). I think the
problem is that the second checkout tries to create the same commit
except that the Change ID is different (the problem is not the
predecessors as I speculated in the issue tracker). The fix is to
simply avoid doing the redundant work. We still need a proper fix for
#27 eventually.

Closes #177.
2022-03-30 22:09:55 -07:00
Martin von Zweigbergk
197f669976 cli: fix git-colocated working copy on Windows
This patch adds a very simple e2e test of having a working copy shared
with Git. The test initially failed on Windows. The symptom was that
the "master" branch did not get updated when we create a commit using
`jj`. That suggested that we didn't correctly detect that the working
copy was shared. After a lot of troubleshooting, I think I mostly
understand what we going on here (thanks to @arxanas for suggesting
https://github.com/mxschmitt/action-tmate). The path we get from
`git2::Repository::workdir()` seems to not be canonicalized in the
same way as `std::fs::canonicalize()` canonicalizes. Specifically, it
does not have the "\\?\" prefix we get from that function. I suppose
that's because libgit2 is a C library and canonicalizes the path using
some other system call.
2022-03-30 22:09:55 -07:00
Martin von Zweigbergk
6cd4e03c25 cleanup: use canonicalize() method instead of free function
I had somehow not noticed that `Path` and `PathBuf` have
`canonicalize()` methods. Using them saves a few characters of code.
2022-03-30 22:09:55 -07:00
Martin von Zweigbergk
2c0b296f35 cli: remove TODO addressed in f6ba34f3c3 2022-03-30 22:09:55 -07:00
Yuya Nishihara
a7e3269ed8 log: add -p/--patch option to show diff along with commit meta data
"log -p | less" is the option I often use with hg/git to find interesting
bits from the changelog, and I think it's also valid with jj. Unlike
"hg log -p --stat", "jj log -p --summary" does not show both diff summary
and patch to reflect the internal structure. This behavoir is arguable and
may be changed later.

The logic of show_patch() is extracted from cmd_show().
2022-03-30 16:24:34 -07:00
Yuya Nishihara
9923bab3ba diff: pass formatter to show_diff() as argument
We might want to split show_diff() into config/option handling part and
diff displayer function, but I'm not sure. Since some of the show_diff
functions depends on ui, we can't isolate show_diff() from the ui object
anyway.

  let opts = parse_diff_option(ui, args);  // map config/option to diff opts
  show_diff(ui, formatter, opts, ...);  // would be nice if ui could be removed
2022-03-30 16:24:34 -07:00
Yuya Nishihara
c2fe008817 diff: pass formatter to show_diff child functions as argument
This decouples the output stream from the ui.
2022-03-30 16:24:34 -07:00
Yuya Nishihara
71e29792f6 diff: make show_diff_summary() reuse locked stdout formatter
This parepares for "log --patch" option, where the formatter will be passed
as a function argument. Unlike diff/show, graphlog needs a temporary output
buffer per commit.
2022-03-30 16:24:34 -07:00
Martin von Zweigbergk
d68eee296e tests: check that stderr is empty after successful commands
Successful commands should probably not write to stderr. If we later
add commands that e.g. print warnings to stderr, we'll want to cover
that explicitly in test.
2022-03-27 21:11:55 -07:00
Martin von Zweigbergk
12bce70bed cli: display how many commits were rebased when merging operations (#111)
This involved copying `UnresolvedHeadRepo::resolve()` into the CLI
crate (and modifying it a bit to print number of rebased commit),
which is unfortunate.
2022-03-26 22:31:49 -07:00
Martin von Zweigbergk
04ad9a3628 repo: when merging in removed head, rebase descendants (#111) 2022-03-26 22:31:49 -07:00
Martin von Zweigbergk
749ea62c08 cli: let the user know if there's been a concurrent modification (#111) 2022-03-26 22:31:49 -07:00
Martin von Zweigbergk
a38dd9d693 repo: make resolution of concurrent operations a separate step (#111)
This is yet another refactoring step to allow the UI layer to inspect
and control how concurrent operations are resolved.
2022-03-26 22:31:49 -07:00
Martin von Zweigbergk
eb333dc07d cli: move optimization for no-op rebases into MutableRepo (#111)
Certain commands should never rewrite commits, or they take care of
rebasing descendants themselves. We have an optimization in
`commands.rs` for those commands, so they skip the usual automatic
rebasing before committing the transaction. That's risky to have to
remember and `MutableRepo` already knows if any commits have been
rewritten (that wasn't the case before, in the Evolution-based
code). So let's just have `MutableRepo` do the check instead.
2022-03-26 22:31:49 -07:00
Martin von Zweigbergk
0ceb4f0dce cli: teach jj new to set initial description with -m
I rarely use `jj new`, so this feature is mostly for use in tests.
2022-03-26 21:11:42 -07:00
Martin von Zweigbergk
23c7581ce1 tests: add a convenience function for running jj successfully
We very often expect success, and we sometimes want to get the stdout,
too. Let's add a convenience function for that. It saves a lot of
lines of code.
2022-03-26 21:11:42 -07:00
Martin von Zweigbergk
03aad3ac2e cli: don't explicitly indicate positional argument's index
I had accidentally given the two positional arguments for `jj git
remote add` the same index. While fixing that, I realized that maybe
`clap` can infer the index based on the declaration order in the
struct. That does indeed seem to work, so I just removed all the
explicit `index` arguments instead.
2022-03-23 22:22:53 -07:00
Martin von Zweigbergk
9e6e5f3d54 cli: make functions delegating to subcommand a single expression 2022-03-23 15:17:21 -07:00
Martin von Zweigbergk
66fe23b4e9 cli: switch from clap's Builder API to its Derive API
The Derive API is easier to work with, less error-prone, and less
verbose, so it seems like a good improvement.

It was quite a bit of work to make the switch, and I'll be surprised
if I didn't make any mistakes in the translation. We unfortunately
don't have enough e2e tests to be very confident, so we'll have to fix
any problems as we discover them.

I've at least verified that the output of `jj debug completion --fish`
is unchanged, except for a few help texts I changed for different
reasons (consistency, clarity, avoiding redundancy).
2022-03-23 15:17:21 -07:00
Martin von Zweigbergk
11afbc70f9 cli: delete unimplemented jj debug writeworkingcopy command
I deleted the implementtion a long time ago, but I forgot to remove it
from the `clap::Command`.
2022-03-23 15:17:21 -07:00
Martin von Zweigbergk
2f59e8b68a cli: respect $NO_COLOR environment variable 2022-03-23 09:57:42 -07:00
Martin von Zweigbergk
7ba1c6bdb6 config: add support for a $JJ_CONFIG environment variable
It's useful for tests, scripts, and debugging to be able to use
specific config instead of the user's config. That's especially true
for our automated tests because they didn't have a place to read
config from on Windows before this patch (they read their config from
`{FOLDERID_RoamingAppData}`, which I don't think we can override in
tests).
2022-03-23 09:57:42 -07:00
Martin von Zweigbergk
3b507e4a2e config: use platform-specific directory separator in jj/config.toml
I don't know if Windows actually cares, but it seems more correct this
way.
2022-03-23 09:57:42 -07:00
Martin von Zweigbergk
095fb9fef4 config: drop support for ~/.jjconfig
I'm a little hesitant to do this because most tools I'm familiar with
have the config file directly in `~/`. It's also easier to describe
where to put the file if it doesn't vary across platforms. But we're
still early in the project, so let's try it and see if we get any
complaints.
2022-03-23 09:57:42 -07:00
Martin von Zweigbergk
1d3f909a3b config: move reading of config from lib crate to CLI crate
The library crate should be usable by e.g. server processes, so it
should not read from the current user's home directory.
2022-03-23 09:57:42 -07:00
Martin von Zweigbergk
3f24411bbf cargo: upgrade the config crate from 0.11.0 to 0.12.0
This required a bit of work.
2022-03-18 22:33:04 -07:00
Martin von Zweigbergk
c14e138698 cli: expand ~ in core.excludesFile, don't crash when missing
I thought that `std::fs::canonicalize()` expanded "~", but it doesn't
seem to do that, which caused #131. Git seems to do the expansion
itself, so we probably also should. More importantly
`std::fs::canonicalize()` crashes when the file doesn't exist. The
manual expansion we do now does not.

Closes #131.
2022-03-13 12:40:37 -07:00
Martin von Zweigbergk
326654952e cli: respect Git's core.excludesFile config (#87)
It probably doesn't make sense to respect Git's `core.excludesFile`
config when not running in a Git-backed repo, but we also already
respect `.gitignore` files in the working copy regardless of backend,
so at least it's consistent with that. We can revisit it when the
native backend becomes a reasonable choice.

Closes #87.
2022-03-12 10:48:06 -08:00
Martin von Zweigbergk
8336c489fa cli: respect .git/info/exclude if in Git-backed repo (#65)
Closes #65.
2022-03-12 10:48:06 -08:00
Martin von Zweigbergk
d56ae79d3f working_copy: let caller pass in base Git ignores (#65, #87)
The library crate shouldn't look up the user's `$HOME` directory
(maybe the library is used by a server process), so let's have the
caller pass it into the library crate instead.
2022-03-12 10:48:06 -08:00
Martin von Zweigbergk
2291bfffce cli: add a WorkspaceCommandHelper::edit_diff() proxy (#65, #87)
I'm about to make callers pass in "base" Git ignores when writing a
tree from the working copy. `edit_diff()` will then need to pass
that. It'll be easier to do that if we have a proxy on
`WorkspaceCommandHelper`.
2022-03-12 10:48:06 -08:00
Martin von Zweigbergk
124a064169 tests: set RUST_BACKTRACE=1 in e2e tests
This should be very useful when tests fail because of a panic.
2022-03-12 10:48:06 -08:00
Martin von Zweigbergk
cdc7a0c242 cli: when pushing all branches (the default), skip open commit
Open commits are work-in-progress and `jj git push --branch <name>`
therefore errors out if the branch points to an open commit. However,
we don't do the same check if you run `jj git push` to push all
branches. This patch introduces such a check. Rather than error out,
we skip such branches instead.

I didn't make it check for open commits in ancestors. It's quite
unusual (at least in my workflow) to have a closed commit on top of an
open one. We can revisit if users get surprised by it.
2022-03-12 10:46:58 -08:00
Martin von Zweigbergk
16c68ab821 cleanup: fix a Clippy warning about an unnecessary to_path_buf() 2022-03-10 22:00:45 -08:00
Martin von Zweigbergk
f6ba34f3c3 cli: when initializing repo backed by Git repo, check out Git's HEAD
Closes #102.
2022-03-10 12:53:40 -08:00
Martin von Zweigbergk
d475710d29 cli: print relative path to newly initialized repo
It's easier to test relative paths (no need to strip some prefix) and
it seems more user-friendly as well.
2022-03-10 12:53:40 -08:00
Martin von Zweigbergk
ea05f8f1e5 cli: prevent pushing commits with conflicts
It rarely makes sense to push commits with conflicts to a remote Git
repo (which is the only kind of remote we support so far), so let's
just error out instead of pushing a commit that others pulling from
the remote probably can't make sense of.

I've only added a simple test for the error case for now. `libgit2`
doesn't support pushing to a local repo, so it's harder to test the
success case. I suppose we'll have to have the regular `git` binary
running local servers in test eventually.

Closes #60.
2022-03-10 12:38:07 -08:00
Martin von Zweigbergk
a9eebe779e tests: set user and email in e2e tests
We don't display the user and email yet, so the only visible effect
this has on the tests is that some hashes change.
2022-03-10 12:38:07 -08:00
Martin von Zweigbergk
891641670c tests: don't propagate environment variables to tests
We don't want variables from the developer's environment to affect
tests. You can make tests fail if you set `XDG_CONFIG_HOME` such that
`$XDG_CONFIG_HOME/jj/config.toml` exists and has e.g. an email
set. The fix is to not propagate any environment variables. Thanks for
@arxanas for pointing this out in #104.

We still need to set `$HOME` to prevent configs from being read from
the process owner's home directory (because that's what
`dirs::config_dir()` seems to fall back to if `$HOME` is not set). By
the way, I suspect we'd still not immune to configs from the
developers home directory on Windows, because that doesn't seem to be
controlled by `$HOME`.
2022-03-07 20:23:55 -08:00
Martin von Zweigbergk
42252a2f00 cli: on jj init --git-repo=., use relative path to .git/
When the backing Git repo is inside the workspace (typically directly
in `.git/`), let's point to it by a relative path so the whole
workspace can be moved without breaking the link.

Closes #72.
2022-03-05 09:37:48 -08:00
Martin von Zweigbergk
bbf4ba4118 cli: on jj init --git-repo, point to Git repo's .git/
When using an internal Git repo (`jj init --git`), we make
`.jj/repo/store/git_target` point directly to the repo (which is bare
in that case). It makes sense to do the same when using an external
Git repo (`jj init --git-repo`), so the contents of
`.jj/repo/store/git_target` doesn't depend on whether the user
included the `.git/` on the CLI.
2022-03-05 09:37:48 -08:00
Martin von Zweigbergk
0c6d89581e tests: pass timestamps via env vars for reproducible hashes
This patch introduces a `JJ_TIMESTAMP` environment variable that lets
us specify the timestamp to use in tests. It also updates the tests to
use it, which means we get to simplify the tests a lot now that that
the hashes are predictable.
2022-03-05 08:48:42 -08:00
Martin von Zweigbergk
20ff88461b cli: error out if -R is not applicable
Closes #101.
2022-03-03 16:36:13 -08:00
Martin von Zweigbergk
eed9d48bf7 cli: pass clap app around instead of creating it in multiple places
We need the app (top-level `clap::Command`) in order to check if
e.g. `-R` was passed to `jj init` (for #101), and it seems cleaner to
pass the instance around than to re-create it when needed.
2022-03-03 16:36:13 -08:00
Martin von Zweigbergk
858776d3ee cli: leverage Clap's checking for conflicting arguments
I don't know why I didn't think of doing this earlier...
2022-03-03 16:36:13 -08:00
Martin von Zweigbergk
b45bada00f cli: clarify error message when jj untrack argument is not ignored
As pointed out by @arxanas in #88, the message saying something like
"At least 'bin/.DS_Store' was added back ..." is confusing especially
when the command you ran was just `jj untrack bin/.DS_Store`. Let's
clarify the message by saying exactly how many more files there are,
and specialize the message for when there is only one file. Also
update the message to say "would be added back" instead of "was added
back" since we don't actually change anything if some files would be
added back (since 4b91ad408c).

Should we even list all the files? I'm concerned that such a list
could be very long. On the other hand, it can also be annoying to have
to run `jj untrack some/dir/` and only be told about single file to
add to the ignore patterns every time.
2022-03-02 22:43:09 -08:00
Martin von Zweigbergk
6747a6c59c cli: add test of --no-commit-working-copy
I didn't add a test in #90 because the test cases needed to be cleaned
up first. They now look a bit better, so we can add test for the
flag.
2022-03-02 22:00:24 -08:00
Martin von Zweigbergk
834349a971 tests: add helper for matching regex and capturing groups 2022-03-02 22:00:24 -08:00
Martin von Zweigbergk
711f65303c tests: use assert_cmd for e2e tests
I didn't know about `assert_cmd` when I wrote the few e2e tests we
have. Let's switch to it and remove our own similar helpers.
2022-03-02 22:00:24 -08:00
Martin von Zweigbergk
59eee7e918 cli: don't print "Working copy now at:" when it's unchanged
When I recently changed the working copy to not have a commit ID
(e098c01935), I lost the check in `update_working_copy()` in
`commands.rs` that made us not print "Working copy now at: " if the
commit was unchanged. Now we always print, which is unnecessary and
confusing (it makes it seem like the commit changed even if it
didn't). Let's restore the check.
2022-03-02 13:16:10 -08:00
Cole Mickens
8cdfc81cc2 commands: add clap_mangen support 2022-03-02 08:46:54 -08:00
Martin von Zweigbergk
c59dcd76a4 cargo: upgrade clap to 3.1.0
This avoids some deprecation warnings from `cargo install` (which
picks the latest version instead of the locked version by default).
2022-02-27 13:16:02 -08:00
Martin von Zweigbergk
a88865a418 cli: add an option to avoid committing the working copy
It can be useful in command prompts and scripts to be able to quickly
get e.g. the `jj status` output without spending time committing the
working copy (perhaps because some background process continuously
commits the working copy). One can already do that by passing
`--at-op=<operation ID>`, but then one needs to look up the operation
ID first. That is both extra work for the user/script and it means
there's an extra `jj op log` invocation to get the operation ID. Let's
have a global flag to make it easy and efficient to do.
2022-02-27 12:12:24 -08:00
Martin von Zweigbergk
2916cb2d9f cli: exit with code 1 on invalid config
This should have been part of the previous commit (fix for #55).
2022-02-19 23:45:41 -08:00
Martin von Zweigbergk
108b785a36 cli: don't panic on invalid config
If `~/.jjconfig` is invalid, we currently simply panic. That results
in a poor error message. We should handle the error instead.

Closes #55.
2022-02-19 23:38:23 -08:00
Martin von Zweigbergk
1eb913d444 cli: when setting git HEAD in collocated repo, also update own record
When running in a working copy collocated with git's, we export the
working copy's commit's parent to git after every command. However, we
forgot to update our own record of git's HEAD. That means that on
subsequent imports from git, it'll look like the user had updated HEAD
using a git command. When we detect that, we trust that the user had
taken care of the changes in the working copy and we simply abandon
our old working copy commit. That led to the bug reported in $54,
where the second commit of a `jj split` got lost.

The fix is to also update our record of where git's HEAD is when we
tell git to update it.

Closes #54.
2022-02-17 22:12:30 -08:00
Martin von Zweigbergk
03e6b8c0e6 working_copy: take Tree, not CommitId, as argument to check_out()
We no longer need the commit ID, so we shouldn't make the callers pass
it. This lets us simplify several tests, because they no longer to
create commits just to check out a tree in the working copy.
2022-02-13 12:14:34 -08:00
Martin von Zweigbergk
315e5e87a3 working_copy: take a tree object instead of ID in TreeState::check_out()
The callers mostly have the tree object available anyway.
2022-02-13 12:12:08 -08:00
Martin von Zweigbergk
00c9a1ae11 working_copy: stop taking commit ID in LockedWorkingCopy::finish()
We used to use the value to detect races, but we use the tree ID and
the operation ID these days, so we don't need the commit ID.

By changing this, we can avoid creating some commit IDs in tests,
which is why I tackled this issue now.
2022-02-12 23:48:06 -08:00
Martin von Zweigbergk
bde7b8f449 cli: print working copy's operation ID instead of commit ID in debug command 2022-02-12 17:16:19 -08:00
Martin von Zweigbergk
e098c01935 working_copy: replace commit ID by tree ID for checking for changes
What matters for the working copy is the tree ID. We should be able to
remove the commit ID. This patch gets us close.
2022-02-12 17:16:19 -08:00
Martin von Zweigbergk
21d277b7dc cli: check for concurrent operation during jj untrack
This patch addresses the TODO about a (tiny) race that could happen if
`jj untrack` was run concurrently with another operation.
2022-02-12 16:52:18 -08:00
Martin von Zweigbergk
537b1de7d9 working_copy: move check of old commit ID on checkout to higher level
There are only two callers of `LockedWorkingCopy::check_out()`. One is
in `commands.rs`. That caller already checks after taking the lock
that the old commit ID is as expected. The other caller is
`WorkingCopy::check_out()`. We can simply move the check to that level
since it's the only caller that cares now.
2022-02-12 14:27:40 -08:00
Martin von Zweigbergk
68710366b4 cli: add support for restricting jj files by paths 2022-02-09 12:24:15 -08:00
Martin von Zweigbergk
2dbdff1ad1 cli: add support for matching directories
A few commands (`restore`, `diff`, and `untrack` so far) accept path
arguments, but they only support files. Let's make them work with
directories too.
2022-02-06 14:49:22 -08:00
Martin von Zweigbergk
80aeae48b5 cli: fix git diff to not add context lines to count twice
We add `num_after_lines` to the line ranges just a few lines before
the place I removed the addition from in this patch.
2022-02-05 16:00:54 -08:00
Martin von Zweigbergk
731aa7578e cli: allow specifying a custom workspace name
We use the destination directory's basename as the workspace
name. Let's allow the user to choose a different name.
2022-02-05 11:27:41 -08:00
Martin von Zweigbergk
0ee09c9f29 cli: don't allow creating multiple workspaces with the same name
It's harmless but potentially confusing to have multiple workspaces
with the same ID (it would mean that they always have the same
checkout). Let's just prevent it for now. We can add an override later
if people think of usecases for it.
2022-02-05 11:15:51 -08:00
Martin von Zweigbergk
53b458a601 cli: clarify error when trying to forget non-existent workspace
When you try to forget a workspace that doesn't exist, we say "Nothing
changed.", since the transaction is empty. Let's have a specific error
instead.
2022-02-05 11:04:11 -08:00
Martin von Zweigbergk
f6628923dc cli: when checking if jj co destination is checked out, handle absence (#13)
When you run `jj co abc123` and that commit is already checked out, we
just print a message. The condition for that assumed that the checkout
existed, which it won't if you just ran `jj workspace forget`. Let's
avoid that crash, especially since `jj co` is an easy way to restore
the working copy if you had accidentally run `jj workspace forget`
(though `jj undo` is even easier).
2022-02-02 21:56:58 -08:00
Martin von Zweigbergk
ef60da0472 cli: add a command for forgetting a workspace (#13) 2022-02-02 21:52:40 -08:00
Martin von Zweigbergk
4eddb72edb cli: add a command for listing workspaces (#13) 2022-02-02 21:37:34 -08:00
Martin von Zweigbergk
bcece02084 cli: indicate each workspace's checkout in log (#13)
It seems helpful to show in the log output which commit is checked out
in which workspace, so let's try that. I made it only show the
information if there are multiple checkouts for now.
2022-02-02 21:36:14 -08:00
Martin von Zweigbergk
5da9d600fd cli: add a command for adding an additional workspace (#13)
With all the groudwork done, everything should just work with multiple
workspaces now. So let's add a command for creating workspaces.
2022-02-02 17:00:03 -08:00
Martin von Zweigbergk
5fd060ca18 workspace: load repo from another workspace if .jj/repo is a file (#13)
In workspaces added after the initial one, the idea is to have
`.jj/repo` be a file whose contents is a path to the location of the
repo directory in some other workspace.
2022-02-02 13:47:07 -08:00
Martin von Zweigbergk
f2e7086172 cli: make jj [obs]log highlight current workspace's checkout (#13)
We should highlight (with bright colors by default) the current
workspace's checkout, not the default workspace's checkout.
2022-02-02 10:44:13 -08:00
Martin von Zweigbergk
92af544de0 templater: make current_checkout be about the current workspace (#13)
We don't use the `current_checkout` keyword in out default templates,
but let's still fix it, so it refers to the current workspace.
2022-02-02 10:33:10 -08:00
Martin von Zweigbergk
012b4c4d8e revsets: add syntax for a particular workspace's checkout (#13)
Because we record each workspace's checkout in the repo view, we can
-- unlike other VCSs -- let the user refer to any workspace's checkout
in revsets. This patch adds syntax for that, so you can show the
contents of the checkout in workspace "foo" with `jj show foo@`. That
won't automatically commit that workspace's working copy, however.
2022-02-02 10:05:31 -08:00
Martin von Zweigbergk
5b46fa3282 cli: make jj status show status for the current workspace (#13)
`jj status` shows the status for the default workspace. Make it use
the current workspace instead.
2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
3588934fc1 cli: when updating onto new commit from jj new, use right workspace (#13)
`jj new` will update onto the new commit if the previous commit was
the current checkout. That code needs to use the current workspace's
checkout.
2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
ee641bf7ad cli: when exporting Git HEAD, use right workspace's new checkout (#13)
If the workspace is shared with a Git repo, we sometimes update Git's
HEAD ref. We should get the new checkout from the right workspace ID
when doing that (though I'm not sure we'll ever support sharing the
working copy with Git in a non-default workspace).
2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
72b5d9a8c5 cli: when importing Git HEAD, abandon right workspace's old commit (#13)
When importing Git HEAD, we already use the right workspace ID for the
new checkout, but the old checkout we abandon is always the default
workspace's. We should fix that even if we will never support sharing
a working copy with Git in a non-default workspace.
2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
48bbb3abc0 cli: use right workspace when checking if working copy has changed (#13)
Before committing the working copy, we check if the working copy is
checked out to the commit we expect based on the repo's view. We
always use the default workspace's checkout, so we need to fix that.
2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
9cabb7eb35 cli: add an early return and reduce indentation (#13) 2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
daaf735e4b cli: update working copy to current workspace's checkout (#13)
When updating the working copy after committing a transaction, we
should update it based on the right checkout.
2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
5f38213e91 cli: detect concurrent working copy change in right workspace (#13)
We detect concurrent working copy changes by checking that the old
commit matches the repo's view. We should use the current workspace
when looking up the checkout in the view.
2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
766c01a6d9 view: add workspace_id argument to set_checkout() (#13) 2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
51c351f272 cli: rename --git-store to --git-repo
"store" is just used internally, it's not something we should expose
to users.
2022-02-02 08:13:10 -08:00
Martin von Zweigbergk
c74882b3c0 cli: fix typo "one revisions" 2022-01-28 17:01:58 -08:00
Martin von Zweigbergk
94dbcf3b7e cli: remove accidental -r argument from jj move 2022-01-27 22:48:28 -08:00
Martin von Zweigbergk
9c561429c0 cli: add a command for moving part of a change into another change
This adds a `jj move [--from <rev>] [--to <rev>] [-i]` command, which
lets you move some changes from one commit into another. `jj
squash/amend` is just a special case of this new command. Except for
that command's more specialized help text, instructions, etc., it
could be implemented as simply `jj move --to @-`.
2022-01-27 22:33:31 -08:00
Martin von Zweigbergk
d3b85783bd cli: adjust descriptions of --interactive flags
I thought it was a bit unclear which part of the process was
interactive (it's only choosing parts of the diffs that is
interactive, not choosing destination or anything else).
2022-01-27 22:20:14 -08:00
Martin von Zweigbergk
bedf96475d cleanup: format commands.rs, missed in previous commit 2022-01-27 20:46:33 -08:00
Martin von Zweigbergk
d588a309da cli: prevent rebasing to a descendant
We allow rebasing to a descendant, but that causes divergence because
the old commit remains visible. You could imagine making it work so
`jj rebase -r B -d D` on a linear chain "A-B-C-D" reorders it to
"A-C-D-B", but we don't do that yet, so let's just prevent the
divergence for now.
2022-01-27 16:17:13 -08:00
Martin von Zweigbergk
ed265afc68 cli: prepare rebase code for checking that destination is not descendant 2022-01-27 16:14:36 -08:00
Martin von Zweigbergk
10ebf35c27 repo: add a convenience function for rebasing all descendants
All non-test users of `create_descendant_rebaser()` just want to
rebase all commits, so let's make that easy.
2022-01-27 08:28:44 -08:00
Martin von Zweigbergk
f0240213cc cli: update the working copy if we detect that it's stale (#13)
Now that we have the operation ID recorded in the working copy state,
we can tell if the working copy is stale. When it is, we update it to
the repo view's checkout.
2022-01-19 22:26:16 -08:00
Martin von Zweigbergk
38180555de working_copy: keep track of operation ID (#13)
When there are concurrent operations that want to update the working
copy, it's useful to know which operation was the last to successfully
update the working copy. That can help use decide how to resolve a
mismatch between the repo view's record and the working copy's
record. If we detect such a difference, we can look at the working
copy's operation ID to see if it was updated by an operation before or
after we loaded the repo.

If the working copy's record says that it was updated at operation A
and we have loaded the repo at operation B (after A), we know that the
working copy is stale, so we can automatically update it (or tell the
user to run some command to update it if we think that's more
user-friendly).

Conversely, if we have loaded the repo at operation A and the working
copy's record says that it was updated at operation B, we know that
there was some concurrent operation that updated it. We can then
decide to print a warning telling the user that we skipped updating
because of the conflict. We already have logic for not updating the
working copy if the repo is loaded at an earlier operation, but maybe
we can drop that if we record the operation in the working copy (as
this patch does).
2022-01-19 19:15:29 -08:00
Martin von Zweigbergk
a2acb5fcb8 cli: while importing git HEAD, keep working copy locked
When importing git HEAD in a working copy shared with git, we reset
the working copy to the new commit at the end. If we fail to reset the
working copy, we shouldn't commit the operation. This patch mostly
fixes that by locking the working copy while we commit the
operation. There's still a small risk that the operation commits and
we fail to write the working copy state, but there's not much we can
do about that (or it's not worth the effort anyway).
2022-01-19 19:15:29 -08:00
Martin von Zweigbergk
cb5dd387ed cli: clarify a comment and some variable names 2022-01-19 15:12:23 -08:00
Martin von Zweigbergk
dd81e4a3a1 cli: create tree object from working copy right before using it
This is just to make the code more readable.
2022-01-19 13:32:09 -08:00
Martin von Zweigbergk
9e1869dcef working_copy: pass in old commit ID to check_out()
`WorkingCopy::check_out()` currently fails if the commit recorded on
disk has changed since it was last read. It fails with a "concurrent
checkout" error. That usually works well in practice, but one can
imagine cases where it's not correct. For an example where the current
behavior is wrong, consider this sequence of events:

 1. Process A loads the repo and working copy.

 2. Process B loads the repo at operation A. It has not loaded the
    working copy yet.

 3. Process A writes an operation and updates the working copy.

 4. Process B loads the working copy and sees that it is checked out
    to the commit process B set it to. We don't currently have any
    checks that the working copy commit matches the view's checkout
    (though I plan to add that).

 5. Process B finishes its operation (which is now divergent with the
    operation written by process A). It updates the working copy to
    the checkout set in the repo view by process B. There's no data
    loss here, but the behavior is surprising because we would usually
    tell the user that we detected a concurrent update to the working
    copy.

We should instead check that the working copy's commit on disk matches
what the previous repo view said, i.e. the view at the start of the
operation we just committed. This patch does that by having the caller
pass in the expected old commit ID.
2022-01-19 09:04:01 -08:00
Martin von Zweigbergk
7103860f7e cli: when untracking paths, release lock after finishing transaction 2022-01-19 09:04:01 -08:00
Martin von Zweigbergk
4b91ad408c cli: use reset() in jj untrack 2022-01-19 09:04:01 -08:00
Martin von Zweigbergk
c52b001d9c cli: when importing Git HEAD in shared working copy, use reset() 2022-01-19 09:04:01 -08:00
Martin von Zweigbergk
9a640bfe13 working_copy: save TreeState later, just before releasing lock
I was surprised that we save the `TreeState` before
`LockedWorkingCopy::finish()`. That means that even if the caller
instead decides to discard the changes, some changes will already have
been written.
2022-01-19 08:32:59 -08:00
Martin von Zweigbergk
25d19e8a65 working_copy: start improving interface for mutations
This patch changes the interface for making changes to the working
copy by replacing `write_tree()` and `untrack()` by a single
`start_mutation()` method. The two functions now live on the returned
`LockedWorkingCopy` object instead. That is more flexible because the
caller can make multiple changes while the working copy is locked. It
also helps us reduce the risk of buggy callers that read the commit ID
before taking the lock, because we can now make it accessible only on
`LockedWorkingCopy`.
2022-01-19 08:32:59 -08:00
Martin von Zweigbergk
6fcd3b3af6 cli: avoid an unnecessary read of the working copy commit 2022-01-16 17:37:24 -08:00
Martin von Zweigbergk
9ce56f6cb7 cli: use color only when stdout is a TTY
This adds a `ui.color` config that can be set to "always", "never", or
"auto". If set to "auto", we use color iff stdout is a TTY.
2022-01-16 17:37:14 -08:00
Martin von Zweigbergk
0fadac38d6 working_copy: remove current_commit() (leaving current_commit_id()
`WorkingCopy::current_commit()` has been there from the beginning. It
has made less sense since we made the repo view keep track of the
current checkout. Let's remove it.
2022-01-15 17:11:56 -08:00
Martin von Zweigbergk
91c8c27cc5 cli: when untracking paths, get old commit id while under lock
Before this patch, we got the old commit ID before we took the lock on
the working copy, which means we might unnecessarily create divergence
if another process just committed the working copy.
2022-01-15 11:15:01 -08:00
Martin von Zweigbergk
ed9c23281b cli: make jj untrack not create divergent commit
We need to call `workspace_command.finish_transaction()` to rebase
descendants and hide the old heads.
2022-01-15 11:09:41 -08:00
Martin von Zweigbergk
c47bb9373c cli: remove unnecessary override of --help description on subcommands
It turns out that the `--help` option is "global", so the description
we set on the top-level command already applies to subcommands (and
subsubcommands, etc.).
2022-01-12 09:23:19 -08:00
Martin von Zweigbergk
504148a81f cli: upgrade to clap 3.0 now that it's released 2022-01-05 12:43:14 -08:00
Martin von Zweigbergk
9eb4390a4d cli: fix a typo in help text of jj squash 2021-12-18 08:58:09 -08:00
Martin von Zweigbergk
423a894cba docs: consistently use hyphens in filenames 2021-12-18 07:56:48 -08:00
Martin von Zweigbergk
006cb37183 docs: replace jj concepts by markdown docs
I wanted to have all the documentation available on the command line,
but that makes it harder to maintain and link to. Let's move it to
markdown instead. We may later be able to add some way of presenting
the markdown in the terminal (or maybe by first converting it to
reStructuredText).
2021-12-17 15:18:41 -08:00
Martin von Zweigbergk
9e591def26 cli: add jj show command for showing commit description and diff
This functionality is probably what I miss most from git/hg.
2021-12-17 13:28:09 -08:00
Martin von Zweigbergk
8d3ad34009 cli: extract function for showing diff style based on args and config
I'm about to add a `jj show` command (like `git show`), and that'll
have the same arguments and config for deciding which style of diff to
show.
2021-12-17 11:28:07 -08:00
Martin von Zweigbergk
c185b395f6 revsets: swap meaning of operators ~ and - (#46)
As suggested by @arxanas, this makes `-` symmetric with `+` and `-` is
easier to type than `~`.
2021-12-12 23:02:29 -08:00
Martin von Zweigbergk
98659a16e1 revsets: change DAG range operator ,, operator to : (#46) 2021-12-12 00:20:00 -08:00
Martin von Zweigbergk
63c90c04c8 revsets: change parent/children operators to foo~/foo+ (#46) 2021-12-11 23:47:34 -08:00
Martin von Zweigbergk
7f61deeb21 cli: when run in git repo, hint about setting up collocated jj workspace (#44)
Now that it's much easier to use a shared working copy between git and
jj, let's update the hint about how to set up a jj repo backed by the
git repo to use a shared working copy.
2021-12-11 11:23:29 -08:00
Martin von Zweigbergk
63d1a87ef3 cli: automatically update Git refs and HEAD after command if collocated (#44) 2021-12-11 11:03:40 -08:00
Martin von Zweigbergk
9898547932 cli: add jj git export command (#44) 2021-12-11 10:20:30 -08:00
Martin von Zweigbergk
cd0192e1b3 cli: extract a function for importing Git refs and HEAD (#44)
`WorkspaceCommandHelper::for_loaded_repo()` was getting a bit long.
2021-12-11 10:20:30 -08:00
Martin von Zweigbergk
c678a89794 cleanup: fix some issues reported by new clippy and/or rustc 2021-12-10 14:12:45 -08:00
Martin von Zweigbergk
d451c1adf8 cli: add .jj/ to .git/info/exclude when collocated
When initializing a jj repo in the same directory as its backing git
repo, add `.jj/` to `.git/info/exclude` so it doesn't show up to `git`
commands.

This is part of #44.
2021-12-01 17:18:08 -08:00
Martin von Zweigbergk
e587071ffe cli: follow git HEAD update if collocated
If the workspace's working copy is shared with the backing Git repo,
we now automatically update the checkout in jj to match Git's HEAD
when that has changed.

With this change, I think users should be able to run `jj init
--git-store=.` and then continue to use `git` commands and
non-mutating `jj` commands without issue.

This is part of issue #44.
2021-12-01 16:29:50 -08:00
Martin von Zweigbergk
75f0abf396 cli: automatically import git refs if repos are collocated
This change makes commands automatically import git refs if they're
run in a workspace that shares its working copy with the underlying
git repo. The import is done in a separate transaction.

This is part of #44.
2021-12-01 16:18:53 -08:00
Martin von Zweigbergk
626fbee0dd cli: show Git HEAD in log output
It's useful to know which commit is checked out in the underlying Git
repo (if there is one), so let's show that. This patch indicates that
commit with `HEAD@git` in the log output. It's probably not very
useful when the Git repo is "internal" (i.e. stored inside `.jj/`),
because then it's unlikely to change often. I therefore considered not
showing it when the Git repo is internal. However, it turned out that
`HEAD` points to a non-existent branch in the repo I use, so it won't
get imported anyway (by the function added in the previous patch). We
can always review this decision later.

This is part of #44.
2021-12-01 11:08:53 -08:00
Martin von Zweigbergk
d06c74f5b8 cli: add option to edit description while closing commit
This lets you do `jj close -e` to edit the description even if it's
already set (we normally bring up the editor only if the description
is empty).
2021-12-01 10:44:24 -08:00
Martin von Zweigbergk
06bccb3387 transaction: remove Drop implementation
I can't remember when the `Drop` implementation last helped me find a
bug, so let's just remove it.
2021-12-01 10:31:35 -08:00
Martin von Zweigbergk
14e7d894f3 cli: report failure to import Git refs as internal error 2021-12-01 09:51:20 -08:00
Martin von Zweigbergk
0c441d9558 cli: don't commit no-op transaction
If nothing changed in a transaction, it's rarely useful to commit it,
so let's avoid that. For example, if you run `jj git import` without
changing the anything in the Git repo, we now just print "Nothing
changed.".
2021-12-01 09:51:20 -08:00
Martin von Zweigbergk
ba01c512ae cli: don't update working copy when running command at old operation
Some time ago, I made commands not commit the working copy when run at
an old operation, but it seems that I forgot to make it not update the
working copy. If you run e.g. `jj --at-op=<some operation> rebase -d
<some commit>`, it doesn't make sense for that to update the working
copy.
2021-11-26 23:49:00 -08:00
Martin von Zweigbergk
b8168bd106 cli: on checkout, don't create transaction for no-op update 2021-11-26 23:47:13 -08:00
Martin von Zweigbergk
c6cba59c27 workspace: move creation of .jj/ directory from Repo to Workspace 2021-11-25 21:08:43 -08:00
Martin von Zweigbergk
f17aced374 workspace: move search for .jj/ directory from Repo to Workspace 2021-11-25 21:08:43 -08:00
Martin von Zweigbergk
466d35d4bc workspace: add functions for initializing a repo
`ReadonlyRepo::init_*()` currently calls `WorkingCopy::init()`. In
order to remove that dependency, this patch wraps the
`ReadonlyRepo::init_*()` functions in new `Workspace` functions. A
later patch will have those functions call `WorkspaceCopy::init()`.`
2021-11-25 21:07:28 -08:00
Martin von Zweigbergk
66ee05d364 cli: avoid using Repo::working_copy_path() 2021-11-25 21:04:56 -08:00
Martin von Zweigbergk
70073b94a8 repo: stop keeping a WorkingCopy instance
The `Repo` doesn't do anything with the `WorkingCopy` except keeping a
reference to it for its users to use. In fact, the entire lib crate
doesn't do antyhing with the `WorkingCopy`. It therefore seems simpler
to have the users of the crate manage the `WorkingCopy` instance. This
patch does that by letting `Workspace` own it. By not keeping an
instance in `Repo`, which is `Sync`, we can also drop the
`Arc<Mutex<>>` wrapping.

I left `Repo::working_copy()` for convenience for now, but now it
creates a new instance every time. It's only used in tests.

This further decoupling should help us add support for multiple
working copies (#13).
2021-11-25 21:04:56 -08:00
Martin von Zweigbergk
c0711f47cf workspace: introduce Workspace type
Having a concept of a "workspace" will be useful for adding support
for multiple workspaces (#13). You can think of the "workspace" as a
repo combined with a working copy. A workspace corresponds 1:1 with a
`.jj/` directory. It's pretty close to what other VCS simply call a
"repo", but I've ended up using the word "repo" for what Git calls a
"bare repo".
2021-11-25 21:04:56 -08:00
Martin von Zweigbergk
046b3c0541 op_store: make Vec inside ViewId and OperationId non-public 2021-11-19 23:19:13 -08:00
Martin von Zweigbergk
d34060f013 cli: print "Added X files, ..." message only if any files changed
Looking at the impact on the smoke test and the tutorial, I think I
went overboard in 83c0519. Let's only print the message if any files
changed.
2021-11-19 23:14:19 -08:00
Martin von Zweigbergk
83c051984e cli: print "Added X files, modified Y files, removed Z files" on all updates
I was confused myself why the message was only printed by `jj co` and
not e.g. `jj undo`. That probably means that it should always be
printed (or never be printed).
2021-11-17 21:57:15 -08:00
Martin von Zweigbergk
33b272f5fa working_copy: make some functions require mutable references
We use interior mutability for caching in `WorkingCopy`, but let's
still take mutable reference in the functions where the state change
is visible.
2021-11-17 10:15:33 -08:00
Martin von Zweigbergk
32018da423 cli: add a command for untracking already tracked paths
Especially when working on a new-to-you project, it's common to end up
with unwanted files automatically tracked before you realize that you
should have added them to the `.gitignore`. Even after adding them to
the `.gitignore`, it's not trivial to make them no longer tracked (you
need to move them away, run e.g. `jj st`, then move them back). This
patch adds `jj untrack` to simplify that (without actually moving the
files).

Closes #14.
2021-11-17 09:19:41 -08:00
Martin von Zweigbergk
ae3ff4e1be cli: add command aliases such as "commit" for "close"
Although "commit" isn't technically correct for what `close` does,
it's how new users think of it, so let's make it a bit easier for
them.
2021-11-10 11:11:09 -08:00
Martin von Zweigbergk
ced252f766 cleanup: replace some as_slice() by & 2021-11-10 10:55:58 -08:00
Martin von Zweigbergk
9375106a05 cli: use same color for timestamps in operation log as in commit log 2021-11-07 21:41:22 -08:00
Martin von Zweigbergk
0a43bc7088 cleanup: fix a formatting regression 2021-11-07 15:56:30 -08:00
Martin von Zweigbergk
c1bdba5403 cli: make jj st list paths with conflicts
Now that the working copy preserves conflicts, we can easily list
them.
2021-11-07 15:17:51 -08:00
Martin von Zweigbergk
99e5a28d17 cli: don't materialize conflicts when editing diffs
The diff-editing code shares the `TreeState` functionality with the
working-copy code. That means we can now let the user edit conflicts
without materializing them first. So now the user can do e.g. `jj edit
-r <some commit>` and resolve only some of the conflicts.
2021-11-07 15:17:51 -08:00
Martin von Zweigbergk
60ea81882f cli: use same template for jj log --no-graph as for jj log
It is weird how the template changes because you ask for now
graph. Also, I've never wanted the long format. Let's just remove it.
2021-10-27 21:28:04 -07:00
Martin von Zweigbergk
853b40cf18 cleanup: run rustfmt on formatter (missed in recent commit) 2021-10-27 21:26:22 -07:00
Martin von Zweigbergk
3981cd90f8 cli: use bright colors for head of operation log 2021-10-27 16:35:48 -07:00
Martin von Zweigbergk
922fea0c18 cli: use bright color for the current checkout's description too 2021-10-27 16:31:04 -07:00
Martin von Zweigbergk
18f450e530 cli: fix TODO about formatter label
Maybe something has changed since I added the TODO, but it seems the
problem it describes doesn't exist now.
2021-10-27 16:26:27 -07:00
Martin von Zweigbergk
6687f98d8a cli and docs: replace "id" by more correct "ID" 2021-10-27 15:06:10 -07:00
Martin von Zweigbergk
3587d4ec7e cli: use bright colors for the current checkout
As @arxanas noted, it's hard to tell which commit is currently checked
out. Hopefully bright colors will help. Maybe setting a background
color would be even clearer, but that's harder to do because the
formatter doesn't support background colors yet.
2021-10-27 14:16:13 -07:00