Commit graph

236 commits

Author SHA1 Message Date
Martin von Zweigbergk
4883261c2a cli: rebase descendants without using evolution
This change makes it so we rebase descendants based on the rewrite
information recorded in `MutableRepo` instead of using evolution for
it. This is an important step towards removing evolution (#32).
2021-10-02 10:30:09 -07:00
Martin von Zweigbergk
0cb43c72d0 cli: make jj split manually rebase descendants
When we remove evolution (#32), I don't intend to replicate the hack
it had for rebasing descendants onto a split commit. Let's instead
have `jj split` manually rebase descendants of the original commit
onto the second part of the split. We use `DescendantRebaser` for
that. Branches and the working copy pointing to the split commit are
still updated using evolution in
`RepoCommandHelper::finish_transaction()`. I plan to have
`DescendantRebaser` update branches and working copies as well. That
should then also work as expected for `jj split`.
2021-10-02 10:30:09 -07:00
Martin von Zweigbergk
6949dab389 cli: make squash and unsquash commands record abandoned commits
This change makes `jj squash` and `jj unsquash` record the child or
parent (respectively) as abandoned if it becomes empty. We need to do
that because it won't get automatically recorded by
`CommitBuilder`. We could make `CommitBuilder` record abandoned
commits when `set_pruned()` was called, but that would be
short-sighted since we're about to delete that function as part of
removing support for evolution (#32).
2021-09-29 15:56:09 -07:00
Martin von Zweigbergk
3e938752d1 cli: also update descendant branches after rewriting working copy commit
After writing a new working copy commit, we update branches pointing
to it, and we rebase descendants on top. However, we should be doing
that in the opposite order, so the branch updates apply to rewritten
descendants as well.
2021-09-29 10:13:32 -07:00
Martin von Zweigbergk
38474a9fb9 cli: remove non-visible heads after every operation
This makes it so that almost every command will remove non-visible
heads. That shouldn't have much visible effect, except that the
`all_heads()` revset will become the same as
`non_obsolete_heads()`.

It will help us remove support for evolution by cleaning up existing
repos. Existing repos (like mine) will lose the unwanted heads (~8.5k
heads in my case), so they don't clutter the repo once evolution is
gone.

This is part of issue #32.
2021-09-29 10:13:32 -07:00
Martin von Zweigbergk
ff71af1e11 MutableRepo: accept just CommitId instead of whole Commit where possible 2021-09-29 10:13:32 -07:00
Martin von Zweigbergk
76782b20dd cli: add debug command for generating command-line-completion scripts 2021-09-24 10:04:16 -07:00
Martin von Zweigbergk
d121cd7f75 cli: add a jj branch --forget for forgetting everything about a branch 2021-09-22 21:29:46 -07:00
Martin von Zweigbergk
4b9282ed40 cli: make jj abandon explicitly rebase descendant commits
This change makes it so `jj abandon` uses `DescendantRebaser` for
rebasing descendants of the abandoned commits. That makes it not
depend on evolution for it.
2021-09-19 22:57:09 -07:00
Martin von Zweigbergk
d4004fcb6f rewrite: teach DescendantRebaser to handle abandoned commits specially
Descendants of abandoned commits should be rebased onto their parents,
or the rewritten parents if they had been rewritten. This patch
teaches `DescendantRebaser` to do that. It updates `jj rebase -r` to
use the functionality. I plan to also use it in `jj abandon`
(naturally, given the name), and for rebasing descendants of deleted
refs imported from `jj git refresh/fetch/push`.
2021-09-19 22:51:12 -07:00
Martin von Zweigbergk
ae7f00e7b1 cli: rename jj prune to jj abandon
The command's help text says "Abandon a revision", which I think is a
good indication that the command's name should be `abandon`. This
patch renames the command and other user-facing occurrences of the
word. The remaining occurrences should be removed when I remove
support for evolution.
2021-09-19 22:51:12 -07:00
Martin von Zweigbergk
84081a5727 cli: use new helper for updating branches after committing working copy
This makes conflicted branches pointing to the working copy get
updated when the working copy changes, just like they are when it
changes for other reason (such as `jj describe`).
2021-09-18 10:04:55 -07:00
Martin von Zweigbergk
ef4cb663ae cli: move logic for updating branches after rewrite to lib crate
This patch moves the function for updating branches after rewrite from
`commands.rs` into `rewrite.rs`.

It also changes the function to update branches even if they were
conflicted or become conflicted. I think that seems better than
leaving branches on old commits. For example, let's say you have start
with this:

```
C main
|
B origin@main
|
A
```

You now pull from origin, which has updated the main branch from B to
B'. We apply that change to both the remote branch and the local
branch, which results in a conflict in the local branch:

```
C main?
|
B B' main? origin@main
|/
A
```

If you now rewrite C to C', the conflicted main branch will still
point to C, which is just weird. This patch changes that so the
conflicted side of main gets repointed to C'.

I also refactored the code to reuse our existing
`MutableRepo::merge_single_ref()`, which improves the behavior in
several cases, such as the conflict-resolution case in the last test
case.
2021-09-18 10:03:26 -07:00
Martin von Zweigbergk
e76dc5a425 cli: don't crash when . is given as file pattern 2021-09-15 22:46:27 -07:00
Martin von Zweigbergk
a02b5af1e8 cli: use RepoCommandHelper::finish_transaction() for git commands as well
I don't know why I hadn't already updated these. Maybe I thought it
wasn't necessary. That's probably true right now, but I want to make
`jj git fetch` and `jj git refresh` automatically rebase commits when
branches were updated on a remote or in the underlying Git repo. We
want to make sure that the working copy also gets updated then.
2021-09-15 22:33:21 -07:00
Martin von Zweigbergk
ca114d6d7e rewrite: add support for rebasing descendants of multiple rewritten commits
I plan to use this for rebasing descendants of rewritten remote
branches (on fetch).
2021-09-15 22:13:40 -07:00
Martin von Zweigbergk
d9ddd6ed09 cli: fix an obsolete variable name
I forgot to remove the `fetch_head` from a variable name when I
recently realized that Git's `FETCH_HEAD` is not what we want to check
out after fetching.
2021-09-15 09:37:10 -07:00
Martin von Zweigbergk
48f237e33e cli: correctly update to remote's default branch after clone
It turns out that `FETCH_HEAD` is not the remote's `HEAD` (it's
actually not even a normal symbolic ref; it contains many lines of
commits and names). We're supposed to ask the remote for its default
branch instead. That's what this patch does.
2021-09-13 22:28:13 -07:00
Martin von Zweigbergk
ce5e95fa80 store: rename Store to Backend and StoreWrapper to Store
For what's currently called `Store` in the code, I have been using
"backend" in plain text. That probably means that `Backend` is a good
name for it.
2021-09-12 12:02:10 -07:00
Martin von Zweigbergk
cea3c1537a cli: make jj git push push all branches by default
It's annoying to have to add `--branch main` every time I push to
GitHub.

Maybe we should make it push only the current branch by default, but
we don't even have a concept of a current branch yet...
2021-09-11 23:51:53 -07:00
Martin von Zweigbergk
0bc42c0066 cli: extract function for figuring out how to update branches on a remote 2021-09-11 23:41:53 -07:00
Martin von Zweigbergk
344435e90f git: add support for pushing multiple ref updates at once 2021-09-11 22:54:29 -07:00
Martin von Zweigbergk
2a23ee3f15 cli: guess destination for jj git clone if it's not provided 2021-09-11 10:25:46 -07:00
Martin von Zweigbergk
be64e5118d cli: teach jj discard to discard a public head
I'm not sure what the interface should be, but until public heads are
automatically removed when they disappear from a remote, this will at
least be useful as a workaround.
2021-09-10 21:57:43 -07:00
Martin von Zweigbergk
15858b7630 cli: make jj branches say how much remote branches are ahead/behind
For example:
```
main: 4f2efc5bb873 cli: make `jj branches` say how much remote branches are ahead/behind
  @origin (behind by 2 commits): 5023d8d360 Merge pull request #26 from martinvonz/git-comparison
```
2021-09-10 18:33:28 -07:00
Martin von Zweigbergk
8b2db95897 cli: make jj branches indent remote branches and not repeat the branch name
Before:
```
git-comparison: de5aa1ac6c docs: add a table of git/jj command equivalences
git-comparison@origin: 15bbd1083b0e cli: add a table of git/jj command equivalences
main: 4aa1fd7cbb docs: move tutorial from README.md to docs/tutorial.md
```

After:
```
git-comparison: de5aa1ac6c docs: add a table of git/jj command equivalences
  @origin: 15bbd1083b0e cli: add a table of git/jj command equivalences
main: 4aa1fd7cbb docs: move tutorial from README.md to docs/tutorial.md
```
2021-09-10 18:19:42 -07:00
Martin von Zweigbergk
de5aa1ac6c docs: add a table of git/jj command equivalences 2021-09-10 13:52:07 -07:00
Martin von Zweigbergk
4aa1fd7cbb docs: move tutorial from README.md to docs/tutorial.md 2021-09-09 11:10:40 -07:00
Martin von Zweigbergk
014cf6e297 cli: make short description for jj describe fit on one line 2021-09-09 10:55:56 -07:00
Martin von Zweigbergk
118d0cc31d cli: clarify that --help provides more help than -h
It turns out that `--help` provides a longer version of the help text
than `-h` does. I only discovered that because I was wondering what
the difference between `clap::App::about()` and
`clap::App::long_about()` was. There's clap-rs/clap#1015 for tracking
it in clap, but let's clarify it ourselves for now by changing the
help text for `-h/--help`.
2021-09-08 10:01:57 -07:00
Martin von Zweigbergk
826e69a10c cli: add help texts for all CLI arguments 2021-09-08 09:51:50 -07:00
Martin von Zweigbergk
ad96820642 cli: add concepts guide about the operation log 2021-09-06 22:24:55 -07:00
Martin von Zweigbergk
b3a93b903f cli: add concept guide about the working copy 2021-09-04 11:46:00 -07:00
Martin von Zweigbergk
fa73b17c66 cli: add jj concepts subcommand for concept help, starting with "branches"
With this commit, you can run `jj concepts branches` to get help about
the "branches" concept. We don't have much help for other commands and
their arguments yet, but I'm starting with concept guides so we can
point to them as we add help for commands and their arguments.

I initially tried to make the command to get help be `jj help
--concept branches`. That would require replacing clap's
implementation of the help command with our own. clap-rs/clap#1350
prevented me from doing that. But I'm pretty happy with having it
under `jj concepts` anyway. It's probably more discoverable that way.

I tried to mimic clap's styling with yellow headings.
2021-09-02 23:06:46 -07:00
Martin von Zweigbergk
fddcaaada1 cli: set custom, imperative messages for --help and --version
Clap uses present tense by default (e.g. "Prints help information"). I
considered switching our message to that style, but I found it harder
to describe some flags that way.
2021-09-02 11:01:02 -07:00
Martin von Zweigbergk
d7cc09e918 cli: disable --version on subcommands
`jj st --version` and `jj op log --version` don't make any sense.
2021-09-02 11:01:02 -07:00
Martin von Zweigbergk
4e9be8d2a4 rustfmt: format string literals 2021-09-02 11:01:02 -07:00
Martin von Zweigbergk
88fef10eac cleanup: use literal newlines in string literals
I'm about to enable `rustfmt`'s formatting of string literals, and
that makes these string literals with escaped newlines harder to read.
2021-09-02 11:01:02 -07:00
Martin von Zweigbergk
ecbbac23be cli: require argument for jj open
The current checkout is always open, so it doesn't make sense to have
that as default.
2021-08-30 00:07:55 -07:00
Martin von Zweigbergk
f13f15e057 cli: add jj rebase -s and make jj rebase -r rebase descendants onto parents
I think it makes sense to have a version of rebase that rebases the
descendants of the rebased commit onto the parents of the rebased
commit. Let's make `jj rebase -r` do just that. Let's also add `jj
rebase -s` (matching Mercurial's `hg rebase -s`) for rebasing a commit
and its descendants onto another commit.

Since both flavors of the command now explicitly rebase the
descendants (just to different destinations), I also made the command
not evolve orphans afterwards. That would have made sense regardless
of this commit.
2021-08-28 10:01:00 -07:00
Martin von Zweigbergk
451451563b revset: work with Rc<RevsetExpression> everywhere
It's about break-even in this commit to `Rc` everywhere, but it will
allow big savings in the next commit.
2021-08-25 22:53:57 -07:00
Martin von Zweigbergk
52678237a7 cli: after cloning git repo, update to remote's HEAD 2021-08-25 21:42:32 -07:00
Martin von Zweigbergk
723ebb3809 cleanup: restructure escaped newlines to make new rustc happy 2021-08-18 10:06:15 -07:00
Martin von Zweigbergk
c310477765 cleanup: fix formatting of commands.rs 2021-08-18 09:58:17 -07:00
Martin von Zweigbergk
b4d0549146 cli: make jj status report conflicted branches
This change makes `jj status` include a section about conflicted local
branches and another section about conflicted remote branches. They
show up only if there are conflicts. They include hints about how to
resolve.
2021-08-15 19:40:55 -07:00
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
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