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

636 commits

Author SHA1 Message Date
Martin von Zweigbergk
5493b44ba5 cli: update branches when working copy committed 2021-08-15 19:01:14 -07:00
Martin von Zweigbergk
e66d3120c5 cli: evolve descendants when working copy committed 2021-08-15 19:01:14 -07:00
Martin von Zweigbergk
2afed65132 working_copy: move logic for creating commit to caller
The auto-rebasing of descendants doesn't work if you have an open
commit checked out, which means that you may still end up with orphans
in that case (though that's usually a short-lived problem since they
get rebased when you close the commit). I'm also about to make
branches update to successors, but that also doesn't work when the
branch is on a working copy commit that gets rewritten. To fix this
problem, I've decided to let the caller of `WorkingCopy::commit()`
responsible for the transaction.

I expect that some of the code that this change moves from the lib
crate to the cli crate will later move back into the lib crate in some
form.
2021-08-15 18:55:09 -07:00
Martin von Zweigbergk
0d24e72260 cli: extract a helper for evolving descendants
I want to reuse this bit of code for evolving descendants of a
rewritten working copy commit.

I expect this to change again soon (I'll probably make it do a regular
rebase instead of evolve), but this will do for now.
2021-08-15 18:37:08 -07:00
Martin von Zweigbergk
7deba1172c tests: remove an unnecessary wc.commit() right after wc.check_out() 2021-08-15 18:37:08 -07:00
Martin von Zweigbergk
3c1a9b4d10 cli: update branches after rewriting commits
This makes it so (local) branches get updated when the commit they
point to gets rewritten. If the branch was conflicted, we just print a
warning and don't update the branch (though one could imagine
rewriting the conflict). We also just print a warning if the new
target is unclear because the commit was rewritten into multiple new
commits (divergent).

The updating doesn't work when the working copy commit gets rewritten
because the working copy changed on disk. That's because that's done
in a separate transaction inside `working_copy.rs`. That's similar to
how orphans of the working copy commit don't get automatically
evolved. I'll fix both problems soon.
2021-08-15 18:35:24 -07:00
Martin von Zweigbergk
8fe4433c9c cli: make revision argument positional for jj describe
I missed this command in the previous change.
2021-08-15 18:29:02 -07:00
Martin von Zweigbergk
8ad60f8c99 cli: make revision argument position for some commands
For example, `jj open/close` doesn't seem to make sense with paths, so
let's save the user from typing "-r".
2021-08-15 17:20:26 -07:00
Martin von Zweigbergk
45f926c234 cli: don't require --allow-backwards when creating a branch
If a branch doesn't exist yet, it's clearly safe to move it "forward"
to any commit (it was simply a bug that we required
`--allow-backards`).
2021-08-11 11:15:14 -07:00
Martin von Zweigbergk
7f335a4632 repo: remove some incorrect "mut" modifiers 2021-08-11 10:58:38 -07:00
Martin von Zweigbergk
aba0d200e2 cleanup: fix bad formatting of commands.rs 2021-08-11 10:58:22 -07:00
Martin von Zweigbergk
42090c8078 cli: make jj branches also list remote branches if different from local 2021-08-11 09:19:20 -07:00
Martin von Zweigbergk
4878c94052 cli: color branch name and conflict marker in jj branches output 2021-08-11 09:15:08 -07:00
Martin von Zweigbergk
4594932fc0 git: remove trailing single quotes from error messages 2021-08-11 08:21:42 -07:00
Martin von Zweigbergk
81ba65e3a5 git: force push when not known to be a fast-forward
With this change, we no longer fail if the user moves a branch
sideways or backwards and then push.

The push should ideally only succeed if the remote branch is where we
thought it was (like `git push --force-with-lease`), but that requires
rust-lang/git2-rs#733 to be fixed first.
2021-08-04 23:28:42 -07:00
Martin von Zweigbergk
d555e0c326 git: when fetching, prune refs that have been deleted on the remote
Otherwise remote-tracking branches just pile up.

It seems that both git and libgit2 remove the remote-tracking branch
when you push a deletion, so `jj branch --delete foo; jj git push
--branch foo` already sees `foo` disappear locally as well. However,
if a branch has been deleted on the remote, we would never know before
this change.
2021-08-04 23:00:43 -07:00
Martin von Zweigbergk
8b8aff171e cli: delete branch from git remote when pushing locally deleted branch 2021-08-04 22:50:52 -07:00
Martin von Zweigbergk
e57948347e git: extract a function that can be reused for pushing branch-deletion 2021-08-04 22:14:43 -07:00
Martin von Zweigbergk
7dc82c1580 cli: make jj git push push given branch
Now that we have native branches, we can make `jj git push` only be
about pushing a branch to a remote branch with the same name.

We may want to add back support for the more advanced case of pushing
an arbitrary commit to an arbitrary branch later, but let's get the
common case simplified first.
2021-08-04 22:14:43 -07:00
Martin von Zweigbergk
f85613cf66 cli: make branch command's --delete flag actually a flag, and require name arg
I had forgotten to make the `delete` argument a flag by giving it a
name, so instead it conflicted with `name` argument, as tests
discovered.

While at it, I also made `name` required. It wasn't before because I
originally had a single command for `jj branch` and `jj branches` and
then I didn't think to make it required when I split them up.
2021-08-04 14:26:50 -07:00
Martin von Zweigbergk
10b2e25c30 cli: add a command for listing branches 2021-08-04 14:07:19 -07:00
Martin von Zweigbergk
40a260a37f cli: add a command for updating branches 2021-08-04 14:04:06 -07:00
Martin von Zweigbergk
aeab6660d9 revsets: add branches() and tags() functions
The `branches()` function resolves to all "adds" on both local and
remote branches.
2021-08-04 12:03:13 -07:00
Martin von Zweigbergk
15132a1166 cli: replace git refs by branches and tags in log output
Now that our own branches and tags are updated when git refs are
updated and the user can use them to specify revisions, we can start
displaying them instead of the git refs. This commit adds new
`branches` and `tags` template keywords and updates the default
templates to use them instead of `git_refs`.
2021-08-04 11:53:37 -07:00
Martin von Zweigbergk
7fad705062 revsets: add support for resolving symbols as tags and branches
This adds support for resolving tags and branches in revsets. Branches
and tags can be resolved by specifying their name (e.g. "main"). To
specify a branch's target on a remote, use e.g. "main@origin". In case
of conflicts, they get resolved to their "adds".
2021-08-04 11:42:03 -07:00
Martin von Zweigbergk
8738421990 git: update own branch and tag records based on git refs
Now that we have our own representation of branches and tags, let's
update them when we import git refs. The View object's git refs are
now just a record of what the refs are in the underlying git ref last
time we imported them (we don't -- and won't -- provide a way for the
user to update our record of the git refs). We can therefore do a nice
3-way ref-merge using the `refs` module we added recently. That means
that we'll detect conflicts caused by changes made concurrently in the
underlying git repo and in jj's view.
2021-08-04 11:39:07 -07:00
Martin von Zweigbergk
044f23bc33 view: add support for ref-based branches and tags to model
I've finally decided to copy Git's branching model (issue #21), except
that I'm letting the name identify the branch across
remotes. Actually, now that I think about, that makes them more like
Mercurial's "bookmarks". Each branch will record the commit it points
to locally, as well as the commits it points to on each remote (as far
as the repo knows, of course). Those records are effectively the same
thing as Git's "remote-tracking branches"; the difference is that we
consider them the same branch. Consequently, when you pull a new
branch from a remote, we'll create that branch locally.

For example, if you pull branch "main" from a remote called "origin",
that will result in a local branch called "main", and also a record of
the position on the remote, which we'll show as "main@origin" in the
CLI (not part of this commit). If you then update the branch locally
and also pull a new target for it from "origin", the local "main"
branch will be divergent. I plan to make it so that pushing "main"
will update the remote's "main" iff it was currently at "main@origin"
(i.e. like using Git's `git push --force-with-lease`).

This commit adds a place to store information about branches in the
view model. The existing git_refs field will be used as input for the
branch information. For example, we can use it to tell if
"refs/heads/main" has changed and how it has changed. We will then use
that ref diff to update our own record of the "main" branch. That will
come later. In order to let git_refs take a back seat, I've also added
tags (like Git's lightweight tags) to the model in this commit.

I haven't ruled out *also* having some more persistent type of
branches (like Mercurials branches or topics).
2021-08-04 11:33:57 -07:00
Martin von Zweigbergk
b1e60b37ea view: add tests of merging views
I'm about to add some support for branches and tags (for issue #21)
and it seems that we didn't have explicit testing of merging of
views. There was `test_import_refs_merge()` in `test_git.rs` but
that's specifically for git refs. It seems that it's made obsolete by
the tests added by this commit, so I'm removing it.
2021-08-04 11:33:57 -07:00
Martin von Zweigbergk
9fb3521bf5 view: rename insert_git_ref() to set_git_ref()
I just feel like `set_git_ref()` is a more natural name (I was looking
for it the other day before I realized I had called it
`insert_git_ref()`).
2021-08-04 08:45:37 -07:00
Martin von Zweigbergk
2650681117 tests: randomize commit messages in test_git
I had previously created commit messages based only on the ref name,
which meant that `commit4` and `commit5` ended up being the same
commit. This fixes that problem.
2021-08-01 21:26:26 -07:00
Martin von Zweigbergk
7511b02da8 simple_op_store: add some tests
I'm about to start branches and tags in the view and we didn't have
any tests of the store itself (only via higher-level tests).
2021-07-31 19:49:30 -07:00
Martin von Zweigbergk
38032b0132 cleanup: commit transactions in tests when it's simpler
There were some tests that discarded a transaction only because it
used to be easier to do that than to commit and reload the repo. We
get the new repo back when we commit the transaction these days, so
now it's often easier to commit the transaction instead.
2021-07-30 17:47:00 -07:00
Martin von Zweigbergk
6b1ccd4512 view: add support for merging git ref targets
When there are two concurrent operations, we would resolve conflicting
updates of git refs quite arbitrarily before this change. This change
introduces a new `refs` module with a function for doing a 3-way merge
of ref targets. For example, if both sides moved a ref forward but by
different amounts, we pick the descendant-most target. If we can't
resolve it, we leave it as a conflict. That's fine to do for git refs
because they can be resolved by simply running `jj git refresh` to
import refs again (the underlying git repo is the source of truth).

As with the previous change, I'm doing this now because mostly because
it is a good stepping stone towards branch support (issue #21). We'll
soon use the same 3-way merging for updating the local branch
definition (once we add that) when a branch changes in the git repo or
on a remote.
2021-07-24 19:01:56 -07:00
Martin von Zweigbergk
0aa738a518 view: add support for conflicting git refs in the model
This adds support for having conflicting git refs in the view, but we
never create conflicts yet. The `git_refs()` revset includes all "add"
sides of any conflicts. Similarly `origin/main` (for example) resolves
to all "adds" if it's conflicted (meaning that `jj co origin/main` and
many other commands will error out if `origin/main` is
conflicted). The `git_refs` template renders the reference for all
"adds" and adds a "?" as suffix for conflicted refs.

The reason I'm adding this now is not because it's high priority on
its own (it's likely extremely uncommon to run two concurrent `jj git
refresh` and *also* update refs in the underlying git repo at the same
time) but because it's a building block for the branch support I've
planned (issue #21).
2021-07-24 19:01:56 -07:00
Martin von Zweigbergk
a14114256e cleanup: propagate some errors up when failing to write to file 2021-07-24 10:49:32 -07:00
Martin von Zweigbergk
d6a1f9848a cleanup: add explicit import of assert_matches, as required by new rustc 2021-07-24 10:48:52 -07:00
Martin von Zweigbergk
c889baaabe cli: make jj describe not rewrite commit if description was unchanged 2021-07-24 10:33:40 -07:00
Martin von Zweigbergk
203843fc75 readme: some clarifications and minor grammatical corrections 2021-07-08 15:45:49 -07:00
Martin von Zweigbergk
1a4d9d5644 evolution: don't create merge commits with one parent ancestor of another 2021-07-02 23:49:36 -07:00
Martin von Zweigbergk
443528159e conflicts: use new multi-way diff for materialized multi-way conflicts
This copies the conflict marker format I added a while ago to
Mercurial (https://phab.mercurial-scm.org/D9551), except that it uses
`+++++++` instead of `=======` for sections that are pure adds. The
reason I made that change is because we also have support for pure
removes (Mercurial never ends up in that situation because it has
exactly one remove and two adds).

This change resolves part of issue #19.
2021-06-30 12:29:20 -07:00
Martin von Zweigbergk
1390a044e7 files: make merge() accept any number of removes and adds as input 2021-06-30 12:09:36 -07:00
Martin von Zweigbergk
f8c016a8ea files: make MergeHunk support any number of removes and adds
I think `files::merge()` will be a useful place to share code for
resolving conflicting hunks after all. We'll want `MergeHunk` to
support multi-way merges then.
2021-06-30 09:55:16 -07:00
Martin von Zweigbergk
c93e806265 conflicts: make materialized tree/file conflicts etc a little more useful
When there are conflicts between different types of tree entries, we
currently materialize them as "Unresolved complex conflict.". This
change makes it so we mention what types were involved and what their
ids were (though we still don't have an easy way of resolving an id).
2021-06-29 10:49:15 -07:00
Martin von Zweigbergk
720677c7f3 cargo: update test-case to 1.2.0 now that frondeus/test-case#66 is fixed 2021-06-28 12:13:14 -07:00
Martin von Zweigbergk
7effefa802 files: rewrite 3-way content merge using new multi-way diff 2021-06-26 23:49:58 -07:00
Martin von Zweigbergk
81b51de300 diff: rewrite diff() using new multi-way diff 2021-06-26 23:49:58 -07:00
Martin von Zweigbergk
9448fe665a files: use diff::DiffHunk in DiffLine definition
The new `diff::DiffHunk` type is very similar but more generic. We
don't need the generality here. I just don't two very similar types
with the same name.
2021-06-26 23:49:58 -07:00
Martin von Zweigbergk
987aecc749 diff: add a type for diffing arbitrary number of inputs
I have been trying to figure out how to generalize diffs and merges
for arbitrary number of inputs. For example, I want to have an
internal representation of an octopus merge adding 5 inputs (file
states/contents) and removing 4 inputs. I also want to be to represent
a diff from a regular 3-way-conflict state to a resolved state. Such a
diff would be from a state adding two inputs and removing one, to a
state adding just one input.

I finally realized last week that the problem is simple if you don't
care about adds vs removes. Instead, you line up the matching and
differing parts of all the inputs. It's then up to the caller to use
it in an appropriate way for its use case. For example, a regular diff
would pass in two inputs and would get back a list of matching and
dffering hunks. It might then present the first element of differing
hunks in red and the second element in green. Similarly, a 3-way merge
would pass in three inputs with the base first. It would then compare
the sides and decide on a resolution (or leave it unresolved if all
three sides are different).

This change adds a type representing this kind of multi-way
diff. Coming changes will update existing code to use it. In addition
to making the existing code simpler and more consistent, having this
in place should also:

 * Make it much easier to present merge conflicts involving more than
   3 parts.

 * Experiment with different ways of displaying diffs from/to conflict
   states.

 * Experiment with sub-line-level merging.
2021-06-26 23:49:58 -07:00
Martin von Zweigbergk
f2100ed533 cargo: point test-case dependency to my fork
This is work around frondeus/test-case#66 until my pull request (or
other fix) gets accepted.
2021-06-23 17:07:51 -07:00
Martin von Zweigbergk
40a25d4f59 cargo: update dependencies
We need (at least) a new version of `quote` (1.0.9) to be compatible
with a newer version of `test-case` that I want to upgrade to.
2021-06-23 17:05:00 -07:00