jj/lib/src
Kevin Liao 86b6a11e63 Fix jj init --git-repo fails and leaves broken .jj folder
This commit fixes #1305

Before this commit, running `jj init --git-repo=./` in a folder that
does not have a .git would cause jj to panick and leave an unfinished corrupted jj repo.

This commit fixes that by changing the call chain to return an error
instead of calling .unwrap() and panicking. This commit also adds logic to delete the unfinished jj
repository when the git backend initialization failed.

Before this commit, running the above command would result in the following
```
Running `jj/target/debug/jj init --git-repo=./`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { code: -3, klass: 2, message: "failed to resolve path '/Users/kevincliao/github/jj/test-repo/.jj/repo/store/../../../.git': No such file or directory" }', lib/src/git_backend.rs:83:75
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

After this commit, the result is the following and the jj repo is deleted:
```
Running `jj/target/debug/jj init --git-repo=./`
Error: Failed to access the repository: Error: Failed to open git repository: failed to resolve path '/Users/kevincliao/github/jj/test-repo/.jj/repo/store/../../../.git': No such file or directory; class=Os (2); code=NotFound (-3)
```
2023-06-20 11:02:06 -07:00
..
lock lib: use advisory locks on Unix targets 2023-05-07 09:52:09 -07:00
protos working_copy: get conflict id from the current tree 2023-05-31 06:28:15 -07:00
backend.rs backend: take commit to write by value and return new value 2023-05-12 15:20:44 -07:00
commit.rs lib: add Commit::is_discardable() 2023-03-05 23:50:20 +01:00
commit_builder.rs commit_builder: add accessors for most fields 2023-03-19 00:48:05 -07:00
conflicts.rs conflicts: add resolve_trivial() and test invariants 2023-06-19 08:30:09 +02:00
content_hash.rs style: do not dereference self to perform pattern-matching 2023-01-14 19:28:24 +01:00
dag_walk.rs dag_walk: add lazy topo-order iterator for chronological data 2023-06-11 11:38:03 +09:00
default_index_store.rs index: turn CompositeIndex::walk_revs() into position-based API 2023-06-19 13:41:43 +09:00
default_revset_engine.rs index: turn CompositeIndex::walk_revs() into position-based API 2023-06-19 13:41:43 +09:00
default_revset_graph_iterator.rs revset: minor fixes to documentation of graph iterator 2023-05-26 15:55:29 -07:00
default_submodule_store.rs repo: add submodule_store, default impl 2023-06-19 09:48:58 -07:00
diff.rs cargo: upgrade regex 1.7.3 to 1.8.1 2023-04-24 11:28:12 -07:00
file_util.rs copyright: change from "Google LLC" to "The Jujutsu Authors" 2022-11-28 06:05:45 -10:00
files.rs conflicts: resolve trivial merge of A+A-B+C-C to A 2023-06-19 08:30:09 +02:00
git.rs git: return early from import_refs() if no commits to abandon 2023-06-16 09:45:41 +09:00
git_backend.rs Fix jj init --git-repo fails and leaves broken .jj folder 2023-06-20 11:02:06 -07:00
gitignore.rs gitignore: any character can be backslash-escaped 2023-01-16 21:35:54 +01:00
hex_util.rs revset: allow resolving change id using hex digits from reverse alphabet 2023-02-13 22:49:21 -08:00
id_prefix.rs revset: add iterator of (CommitId, ChangeId) pairs, use it in id_index 2023-05-24 01:02:37 +09:00
index.rs index: move Index::as_any() to MutableIndex, obtain CompositeIndex from there 2023-05-29 08:15:40 +09:00
lib.rs repo: add submodule_store, default impl 2023-06-19 09:48:58 -07:00
local_backend.rs cleanup: consistently (?) put removed conflict terms before added ones 2023-05-25 04:24:26 -07:00
lock.rs cleanup: leverage scoped thread in tests 2023-05-21 21:02:58 +09:00
matchers.rs matchers: rename Dirs to RepoPathTree as it no longer represents directory 2022-12-30 14:15:27 +09:00
merge.rs conflicts: resolve trivial merge of A+A-B+C-C to A 2023-06-19 08:30:09 +02:00
nightly_shims.rs build: suppress unstable_name_collisions warnings on stable 2022-02-23 23:41:55 -08:00
op_heads_store.rs dag_walk: reorder and adjust signature of neighbors_fn for consistency 2023-06-04 11:47:49 +09:00
op_store.rs cleanup: consistently (?) put removed conflict terms before added ones 2023-05-25 04:24:26 -07:00
operation.rs operation: iterate ancestors incrementally with timestamp-based heuristic 2023-06-11 11:38:03 +09:00
refs.rs cleanup: consistently (?) put removed conflict terms before added ones 2023-05-25 04:24:26 -07:00
repo.rs Fix jj init --git-repo fails and leaves broken .jj folder 2023-06-20 11:02:06 -07:00
repo_path.rs repo_path: micro-optimize .join() to not reallocate cloned Vec 2023-06-15 00:45:07 +09:00
revset.pest revset: ignore all ascii whitespace characters 2023-03-04 00:01:54 +09:00
revset.rs revsets: stop jj parsing br as a git_ref refs/heads/br 2023-06-12 14:31:44 -07:00
rewrite.rs dag_walk: unbox topo_order_reverse() callback 2023-06-04 11:47:49 +09:00
settings.rs feat(diff): add ui.diff-instructions option to suppress JJ-INSTRUCTIONS file 2023-06-06 22:43:14 -07:00
simple_op_heads_store.rs op_heads_store: let caller create initial operation 2023-02-28 08:08:31 -08:00
simple_op_store.rs proto_op_store: Add two minor comments 2023-04-16 22:04:27 -07:00
stacked_table.rs cleanup: avoid some unnecessary uses of Cursor 2023-05-30 21:06:24 -07:00
store.rs conflicts: extract methods for converting to/from generic legacy form 2023-06-13 21:48:35 +02:00
submodule_store.rs repo: add submodule_store, default impl 2023-06-19 09:48:58 -07:00
transaction.rs cli: in jj git push, create transaction in a single place 2023-06-04 20:50:11 -07:00
tree.rs tree: reuse caller-provided path in known_sub_tree(), mark it as private 2023-06-15 00:45:07 +09:00
tree_builder.rs tree_builder: populate base trees by recursion 2023-06-02 12:23:37 +09:00
view.rs index: delete IndexRef, use Index trait 2023-02-14 06:51:49 -08:00
working_copy.rs conflicts: move describe_conflict() etc. onto Conflict 2023-06-19 07:05:02 +02:00
workspace.rs Fix jj init --git-repo fails and leaves broken .jj folder 2023-06-20 11:02:06 -07:00