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

76 commits

Author SHA1 Message Date
Martin von Zweigbergk
7494a03081 repo: return error when attempting to load repo where there is none
This commits makes it so that running commands outside a repo results
in an error message instead of a panic.

We still don't look for a `.jj/` directory in ancestors of the current
directory.
2021-01-04 09:18:09 -08:00
Martin von Zweigbergk
86b2c6b464 restore: restore all files by default
I often (try to) use the command for throwing away all working copy
changes. That currently results in a crash on
`submatches.values_of("paths").unwrap()`. Let's make it revert
everything by default instead, since that seems to be my
intuition. Unlike most VCS's, we have a backup of the working copy and
the user can simply do `jj op undo` if they realized it was a mistake.
2021-01-03 23:11:22 -08:00
Martin von Zweigbergk
0137acd0a8 cargo: release 0.1.1
This release is mostly to fix the regressed binary name (back from
`jujube` to `jj`).
2021-01-03 23:06:46 -08:00
Martin von Zweigbergk
3e048cd121 commands: change "about" line to match the parenthesis in Cargo.toml 2021-01-03 22:54:31 -08:00
Martin von Zweigbergk
762a367174 commands: set application version based on Cargo.toml 2021-01-03 22:52:27 -08:00
Martin von Zweigbergk
19adac7c50 cargo: set binary name to jj, not new crate name jujube
I recently renamed the crate from `jj` to `jujube` because `jj` was
taken on crates.io. I didn't realize that that would change the name
of the binary.
2021-01-03 22:50:39 -08:00
Martin von Zweigbergk
b40a40990b cargo: add version to jujube-lib dependency
`cargo publish --dry-run` wanted it.
2021-01-03 10:37:42 -08:00
Martin von Zweigbergk
bb4b028b2b cargo: fill in crates.io metadata 2021-01-03 10:37:40 -08:00
Martin von Zweigbergk
abc9dc1733 cargo: rename crates to names available on crates.io
I'm preparing to publish an early version before someone takes the
name(s) on crates.io. "jj" has been taken by a seemingly useless
project, but "jujube" and "jujube-lib" are still available, so let's
use those.
2021-01-03 10:16:00 -08:00
Martin von Zweigbergk
f88e8b6086 evolve: update working copy at end (if applicable)
The `evolve` command had TODOs about making it update the checkout and
the working copy after evolving commits. I've been running into that
(being left on an obsolete commit) quite often while dogfooding, so
let's fix it.
2021-01-02 22:58:36 -08:00
Martin von Zweigbergk
ba4d2c8a24 commands: respect $EDITOR from environment
Until recently, we didn't have support for `.gitignore` files. That
meant that editors (like Emacs) that leave backup files around were
annoying to use, because you'd have to manually remove the backup file
afterwards. For that reason, I had hard-coded the editor to be
`pico`. Now we have support for `.gitignore` files, so we can start
respecting the user's $EDITOR.
2021-01-02 20:15:21 -08:00
Martin von Zweigbergk
d7b9bd55e8 git: remove unnecessary taking of reference (reported by clippy) 2021-01-02 19:38:18 -08:00
Martin von Zweigbergk
e2d6252766 git: on push, check that remote branch was actually updated
I had missed in `git2-rs`'s documentation that you need to check
in a callback if the remote ref(s) got updated by the push or
not. This adds such a check and a new error variant for rejected
branch updates.
2021-01-02 19:27:42 -08:00
Martin von Zweigbergk
7542c484a8 git: pass ssh credentials from ssh-agent on push
I tried to push a commit from my Jujube repo to GitHub using `jj
git push --branch main` and it became clear that we need to pass
SSH credentials. This commit hopefully fixes that. I've only made
it pass credentials for ssh-agent for now, because that seems to
be enough to make it work for me personally. If this commit
becomes visible on GitHub, it should mean that it worked.
2021-01-02 19:27:39 -08:00
Martin von Zweigbergk
14fe58e76a git: use thiserror for errors
When you run e.g. `jj st` outside of a repo, it just
crashes. That'll probably give new users a bad impression, so I
was planning to improve error handling a bit. A good place to
start is by fixing the code I recently added (which obviously
should have been using `thiserror` from the beginning). That's
what this commit does.

Also, this is the first commit in this repo created with
Jujube! I've just started dogfooding it myself.
2021-01-02 08:24:27 -08:00
Martin von Zweigbergk
5b8e10394d transaction: add a message to check for unclosed transaction
I've forgotten to close a transaction a few times and while the
message ('assertion failed: self.closed') is clear to me now, it
probably won't be clear to others or to me in the future.
2021-01-01 12:24:53 -08:00
Martin von Zweigbergk
77bb8b600b git: add a jj git clone command to make it easier to get started
With this commit, you can do `jj git clone
https://github.com/martinvonz/jj jj` and such, which seems like a good
step towards making it easier to get started.
2021-01-01 12:24:25 -08:00
Martin von Zweigbergk
e14db781b0 git: add subcommand for fetching from remote
This adds `jj git fetch` for fetching from a git remote. There remote
has to be added in the underlying git repo if it doesn't already
exist. I think command will still be useful on typical small projects
with just a single remote on GitHub. With this and the `jj git push` I
added recently, I think I have enough for my most of my own
interaction with GitHub.
2021-01-01 11:11:09 -08:00
Martin von Zweigbergk
7e65a3d589 git: restructure test a bit to make the functions more reusable 2020-12-31 23:28:02 -08:00
Martin von Zweigbergk
d741abf5a2 git: make arguments of jj git push named flags instead of positional
This way we can have a default for the remote, which I set to
"origin".
2020-12-31 23:28:02 -08:00
Martin von Zweigbergk
634a04e234 git: return error instead of panicking on unexpected libgit2 error
This is obviously what I meant to do in the commit that introduced the
code.
2020-12-31 09:44:58 -08:00
Martin von Zweigbergk
aea1ea3707 commands: print help if no sub[sub]command given
I didn't know about the Clap setting to print help if no subcommand
was given, so I had reimplemented that myself for the top-level
command. However, if the user did e.g. `jj git`, they'd get a
crash. This commit fixes that by turning on the setting.
2020-12-30 00:22:34 -08:00
Martin von Zweigbergk
3a67952215 git: add command for refreshing heads based on git refs
The user can now run `jj git refresh` e.g. after running `git fetch`
in the underlying Git repo.
2020-12-30 00:05:19 -08:00
Martin von Zweigbergk
ff3b20c537 git: import git refs as anonymous heads when creating Git-backed repo
The fact that no commits from the underlying Git repo were imported
when creating a new Jujube repo from it was quite surprising. This
commit finally fixes that.
2020-12-29 23:59:35 -08:00
Martin von Zweigbergk
4235ea975d tests: clarify a test slightly by moving assertion of out helper 2020-12-29 23:37:09 -08:00
Martin von Zweigbergk
8377000fd9 git: add a function for updating heads from git refs
When using Git as a store, new commits created in the underlying Git
repo are only made visible by making changes on top of them (e.g by
checking them out, so a working copy commit is created on top). That's
especially confusing when creating a new repo backed by an existing
Git repo, because the commits from that repo don't show up.

This commit prepares for fixing that by adding a function for updating
heads based on git refs. Since we don't yet track git refs (or
anything similar), the function just makes sure the refs are visible
in the Jujube repo by making them (anonymous) heads.
2020-12-29 23:30:34 -08:00
Martin von Zweigbergk
905a5c97d6 transaction: make sure set of heads has only heads
`Transaction::add_head()` and others would let the caller add
non-heads to the set (i.e. ancestors of others heads) and the the
non-heads were filterd out when the transaction was committed. That's
a little surprising, so let's try to keep the set valid even within a
transaction. That will surely make commands that add many commits
noticeably slower in large repos. Hopefully we can improve that
later.
2020-12-29 20:44:17 -08:00
Martin von Zweigbergk
0d85850017 git: return a new repo instance from the store instead of the store's instance
Returning the store's internal `git2::Repository` instance wrapped in
a `Mutex` makes it easy to run into deadlocks. Let's return a freshly
loaded repo instance instead.
2020-12-28 23:38:20 -08:00
Martin von Zweigbergk
a8a9f7dedd init: add support for creating new repo backed by bare git repo in .jj/git/
It's annoying to have to have the Git repo and Jujube repo in separate
directories. This commit adds `jj init --git`, which creates a new
Jujube repo with an empty, bare git repo in `.jj/git/`. Hopefully the
`jj git` subcommands will eventually provide enough functionality for
working with the Git repo that the user won't have to use Git commands
directly. If they still do, they can run them from inside `.jj/git/`,
or create a new worktree based on that bare repo.

The implementation is quite straight-forward. One thing to note is
that I made `.jj/store` support relative paths to the Git repo. That's
mostly so the Jujube repo can be moved around freely.
2020-12-28 00:54:03 -08:00
Martin von Zweigbergk
e82197d981 git: extract function for pushing commit to remote branch, and test it 2020-12-28 00:53:41 -08:00
Martin von Zweigbergk
55a7621c45 commands: fix a formatting error
I had fixed this in the working copy but forgot to `git add` it. I'm
not used to Git's staging area yet...
2020-12-27 17:07:54 -08:00
Martin von Zweigbergk
d481001271 commands: add a jj git push command
This commit starts adding support for working with a Jujube repo's
underlyng Git repo (if there is one). It does so by adding a command
for pushing from the Git repo to a remote, so you can work with your
anonymous branches in Jujube and push to a remote Git repo without
having to switch repos and copy commit hashes.

For example, `jj git push origin main` will push to the "main" branch
on the remote called "origin". The remote name (such as "origin") is
resolved in that repo. Unlike most commands, it defaults to pushing
the working copy's parent, since it is probably a mistake to push a
working copy commit to a Git repo.

I plan to add more `jj git` subcommands later. There will probably be
at least a command (or several?) for making the Git repo's refs
available in the Jujube repo.
2020-12-27 00:59:05 -08:00
Martin von Zweigbergk
09e474a05a commands: split up definition of Clap App to help rustfmt
It seems the definition had gotten too large for rustfmt.
2020-12-26 19:03:52 -08:00
Erjan Kalybek
06401fc30d Fix typo 2020-12-26 12:12:24 -08:00
Martin von Zweigbergk
67d496a668 commands: add a command for splitting a commit in two
Unlike Mercurial's version of the command, it can currently only
create exactly two parts.
2020-12-26 11:55:06 -08:00
Martin von Zweigbergk
c04aa43232 commands: make edit_description() take just the initial description
This is just a little refactoring to prepare for making `jj split` ask
the user for commit descriptions. It's not actually needed, but it
doesn't make logical sense for the function to be about editing the
description of a particular commit.
2020-12-26 11:54:16 -08:00
Martin von Zweigbergk
a39b44f5cc commands: add command for editing contents of a commit
This adds `jj edit`, which lets the user edit the content changes in a
commit. It behaves similar to `jj restore` when restoring the parent
commit, except that it edits the change compared to the re-merged
parents if the commit is a merge commit.
2020-12-26 11:47:52 -08:00
Martin von Zweigbergk
3280d75ff4 diff_edit: mark "before" directory readonly to clarify to user
Changes to the "before" side of the diff will have no effect, so let's
clarify that by marking it readonly. At least Meld checks the
permissions and shows in the UI that the left side is readonly.
2020-12-26 11:47:52 -08:00
Martin von Zweigbergk
b6192a7ed5 diff_edit: add missing copyright header 2020-12-26 11:47:52 -08:00
Martin von Zweigbergk
b820eddde3 commands: add an interactive mode for jj restore
This adds an interactive mode for `jj restore`. It works by first
creating two temporary directories with the contents of the subset of
files that differ between the two trees, and then letting the user
edit the directory representing the right/after side. This has some
advantages compared to the interactive modes in Git and Mercurial:

 * It lets the user edit the final state as opposed to the diff itself
   (depending on the diff tool, of course). I think most users find it
   easier to edit the file contents than to edit the patch
   format.

 * It delegates the hard work to a tool that is already written (this
   is a big advantage for an immature tool like Jujube, but it is not
   an advantage from the user's point of view).

Almost all of the work in this commit went into adding a function that
takes two trees, lets the user edit the diff, and returns a new tree
id. I plan to reuse that function for other interactive commands. One
planned command is `jj edit`, which will let the user edit the changes
in a commit. `jj edit -r abc123` will be mostly about providing a more
intuitive name for `jj restore --source abc123^ --destination abc123`,
plus it will be different for merge commits (it will edit only the
changes in the merge commit). I also plan to add `jj split` by letting
the user edit the full diff, leaving only the parts that should go
into the first commit. Perhaps there will also be commands for moving
part of a commit out of or into a parent commit.
2020-12-26 01:16:19 -08:00
Martin von Zweigbergk
fa44ef8d1b conflicts: add another helper for writing materialized conflict to store
This extracts a bit from `Transaction::check_out()` for taking a
Conflict, materializing it, and writing the resulting plain file to
the store. It will soon be reused.
2020-12-26 00:35:45 -08:00
Martin von Zweigbergk
9ade41078a working_copy: remove a working_copy_path argument I missed earlier
This should clearly have been removed in 4734eb6.
2020-12-26 00:35:45 -08:00
Martin von Zweigbergk
4ce2aed17f lock: use exponential backoff 2020-12-25 15:08:49 -08:00
Martin von Zweigbergk
9138de6ff2 git_store: prevent conflict data from being GC'd
Before this commit, running Git's GC in a Git repo backing a Jujube
repo would risk deleting the conflict data we store as blobs in the
Git repo. This commit fixes that by adding a Git note pointing to the
conflict blob.

I wasn't able to add a test case for this because libgit2 doesn't
support gc [1]. Just testing that the ref is there doesn't seem very
useful.

 [1] https://github.com/libgit2/libgit2/issues/3247
2020-12-25 00:52:09 -08:00
Martin von Zweigbergk
3613fe3f59 git_store: avoid confusing delegation from write_conflict() to write_file()
Very little code was saved by reusing `write_file()` and it made it
confusing (needed to provide an unused filename). Also, I'll soon want
access to the `locked_repo` variable in `write_conflict()`.
2020-12-25 00:26:28 -08:00
Martin von Zweigbergk
8cca56ee77 git_store: extract function for retrying note-writing
I'll add a second call to it very soon.
2020-12-25 00:23:27 -08:00
Martin von Zweigbergk
ddf8416d92 git_store: use exponential backoff when retrying note-writing
I have never run into this being a problem in practice, but this
change is a stepping stone for two things:

 1. Using exponential backoff for other locks (in particular the
    working copy).

 2. Making the Git store write a ref for conflict objects, so they
    don't get GC'd (I want to do that before even I start dogfooding).
2020-12-24 23:22:07 -08:00
Martin von Zweigbergk
210405b21a cargo: update dependencies
For no reason other than to stay up to date.
2020-12-24 01:16:55 -08:00
Martin von Zweigbergk
9c8f13608f cargo: update blake2
For no reason other than to stay up to date.
2020-12-24 01:15:38 -08:00
Martin von Zweigbergk
c7ee24727a protobuf: generate code at build-time
I had tried to generate the protobuf code at build time many months
ago, but decided against it because it slowed down the build too
much. I didn't realize there was the
"cargo:rerun-if-changed=<filename>" feature that time. Given that that
exists, it seems like an obvious win to generate the source code at
build time.

I put the generated sources in `$OUT_DIR` (where [1] says they should
be), then include them in the `protos` module by using the `include!`
macro. The biggest problem with that is that I couldn't get IntelliJ
to understand it, even after enabling the experimental features
described in [2].

 [1] https://doc.rust-lang.org/cargo/reference/build-script-examples.html#code-generation

 [2] https://github.com/intellij-rust/intellij-rust/issues/1908#issuecomment-592773865
2020-12-24 01:05:17 -08:00