ok/jj
1
0
Fork 0
forked from mirrors/jj
Commit graph

1120 commits

Author SHA1 Message Date
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
62f541e8cd tests: check that workspace's repo path match canonicalized source path
Hopefully this will fix the failing test on Windows.
2022-02-02 22:22:52 -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
c09a4e15c5 workspace: add a function for initializing additional workspace (#13) 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
a6ef792ba6 repo: initialize without checkouts, let Workspace add it (#13)
As part of creating a new repository, we create an open commit on top
of the root and set that as the current checkout. Now that we have
support for multiple checkouts in the model, we also have support for
zero checkouts, which means we don't need to create that commit on top
of the root when creating the repo. We can therefore move out of
`ReadonlyRepo`'s initialization code and let `Workspace` instead take
care of it. A user-visible effect of this change is that we now create
one operation for initilizing the repo and another one for checking
out the root commit. That seems fine, and will be consistent with the
additional operation we will create when adding further workspaces.
2022-02-02 11:09:12 -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
a41fcb39eb repo: respect workspace ID for old checkout (#13)
When checking out a new commit, we look at the old checkout to see if
it's empty so we should abandon it. We current use the default
workspace's checkout. We need to respect the workspace ID we're given
in `MutableRepo::check_out()`, and we need to be able to deal with
that workspace not existing yet (i.e. this being the first checkout in
that workspace).
2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
ac0d040bb5 rewrite: update all checkouts, not just the default workspace's (#13) 2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
6d3e2017f8 view: merge checkouts for all workspaces, not just the default one (#13) 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
fb8fbdc4b3 working_copy: keep track of workspace ID (#13)
This patch makes it so the workspace ID can be stored in
`.jj/working_copy/checkout`. The workspace ID is still always
"default".
2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
0098edd3d2 op_store: add support for tracking multiple workspaces (#13)
This patch teaches the `View` object to keep track of the checkout in
each workspace. It serializes that information into the `OpStore`. For
compatibility with existing repos, the existing field for a single
workspace's checkout is interpreted as being for the workspace called
"default".

This is just an early step towards support for multiple
workspaces. Remaining things to do:

 * Record the workspace ID somewhere in `.jj/` (maybe in
   `.jj/working_copy/`)

 * Update existing code to use the workspace ID instead of assuming
   it's always "default" as we do after this patch

 * Add a way of indicating in `.jj/` that the repo lives elsewhere and
   make it possible to load a repo from such workspaces

 * Add a command for creating additional workspaces

 * Show each workspace's checkout in log output
2022-02-02 08:15:22 -08:00
Martin von Zweigbergk
ca055d91d9 workspace: store repo in .jj/repo/ (#13)
The `.jj/` directory contains information about two distinct parts:
the repo and the working copy. Most subdirectories are related to the
repo; only `.jj/working_copy/` is about the working copy. Let's move
the repo-related bits into a new `.jj/repo/` subdirectory. That makes
it clearer that they're related to the repo. It will probably also be
easier to manage when we have support for multiple workspaces backed
by a single repo.
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
8fe21b0438 docs: mention history rewriting as a feature in README
I think we have better support rewriting history than most other tools
do, so it seems worth mentioning.
2022-01-28 23:07:52 -08:00
Martin von Zweigbergk
377741c5c6 docs: make "features" in readme a heading with sub-headings instead of bullets
The list of features outgrew the bullet form a long time ago...
2022-01-28 22:45:55 -08:00
Martin von Zweigbergk
35e0b855a9 tests: avoid depending on .jj/ structure in test_bad_locking (#13) 2022-01-28 22:28:32 -08:00
Martin von Zweigbergk
35f0c17380 workspace: rename some symbols related to .jj/ to jj_dir (#13) 2022-01-28 21:31:51 -08:00
Martin von Zweigbergk
0725d4326d repo: don't create unused .jj/view/ directory 2022-01-28 21:27:13 -08:00
Martin von Zweigbergk
81edd92523 workspace: take over creation of .jj/working_copy/ from repo.rs (#13)
It's clearly `Workspace`'s job to create `.jj/working_copy/`, I must
have just forgotten to move it there.
2022-01-28 20:35:13 -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
0c8a116771 rewrite: fix auto-rebasing after "branchy" rewrites
The `DescendantRebaser` was designed to help with rebasing in two
different use cases: 1) after regular rewriting of commits where the
change ID is preserved, and 2) after importing moved branches from
other repo (e.g. backing Git repo or remote). Many of the tests are
for the second use case, such as where a branch was moved
forward. However, I just noticed that there's a pretty common scenario
from the first use case that is not supported.

Let's say you have this history:

```
D
|
C C'
|/
B B'
|/
A
```

Here we want C' to be rebased onto B' and then D to be rebased onto
C''. However, because of the support for moving branches forward, we
would not rebase commits that were already rewritten, such as C' here
(see affected tests for details), which resulted in D getting rebased
onto C', and both B and B' remaining visible.

I think I was thinking when I designed it that it would be nice if you
could just tell `DescendantRebaser` that any descendants of a commit
should be moved forward. That may be useful, but I don't think we'll
want that for the general case of a branch moving forward. Perhaps
we'll want to make it configurable which branches it should happen
for. Either way, the way it was coded by not rebasing already
rewritten commits did not work for the case above. We may be able to
handle both cases better by considering each rewrite separately
instead of all destinations at once. For now, however, I've decided to
keep it simple, so I'm fixing the case above by sacrificing some of
the potentially useful functionality for moving branches forward.

Another fix necessary for the scenario shown above was to make sure we
always rebase C' before D. Before this patch, that depended on the
order in the index. This patch fixes that by modifying the topological
order to take rewrites into account, making D depend not only on C but
also on C'. (I suppose you could instead say that C depends on both B
and C'; I don't know if that'd make a difference.)
2022-01-27 22:20:14 -08:00
Martin von Zweigbergk
5b93ae6d4b rewrite: make it possible to rebase descendants multiple times
Despite what the documentation said, we don't clear the record of
rewritten and abandoned commits at the end. This change fixes that,
and adds a test showing that it's possible to call
`MutableRepo::rebase_descendants()` multiple times.
2022-01-27 22:11:07 -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
9f8c6fe07d clippy: return_self_not_must_use is now disabled (pedantic) by default 2022-01-26 22:13:09 -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
419efb88f9 working_copy: update stale comment on LockedWorkingCopy
The recent refactoring introducing `WorkgingCopy::start_mutation()`
(25d19e8a65) made this comment incorrect.
2022-01-19 15:12:45 -08:00