Skip to content

Commit 44a6125

Browse files
authored
Merge pull request #5100 from Byron/fix-5099
fix 5099
2 parents 373ba60 + 9175e60 commit 44a6125

File tree

9 files changed

+263
-200
lines changed

9 files changed

+263
-200
lines changed

Cargo.lock

Lines changed: 192 additions & 191 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ resolver = "2"
4141
[workspace.dependencies]
4242
bstr = "1.10.0"
4343
# Add the `tracing` or `tracing-detail` features to see more of gitoxide in the logs. Useful to see which programs it invokes.
44-
gix = { git = "https://github.com/Byron/gitoxide", rev = "72daa46bad9d397ef2cc48a3cffda23f414ccd8a", default-features = false, features = [
44+
gix = { git = "https://github.com/Byron/gitoxide", rev = "64872690e60efdd9267d517f4d9971eecd3b875c", default-features = false, features = [
4545
] }
4646
git2 = { version = "0.19.0", features = [
4747
"vendored-openssl",

crates/gitbutler-branch-actions/src/branch.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use gitbutler_repo::{GixRepositoryExt, RepositoryExt as _};
1313
use gitbutler_serde::BStringForFrontend;
1414
use gitbutler_stack::{Stack as GitButlerBranch, StackId, Target};
1515
use gix::object::tree::diff::Action;
16-
use gix::prelude::ObjectIdExt;
16+
use gix::prelude::{ObjectIdExt, TreeDiffChangeExt};
1717
use gix::reference::Category;
1818
use serde::{Deserialize, Serialize};
1919
use std::borrow::Cow;
@@ -598,7 +598,9 @@ pub fn get_branch_listing_details(
598598
};
599599
base_tree
600600
.changes()?
601-
.track_rewrites(None)
601+
.options(|opts| {
602+
opts.track_rewrites(None);
603+
})
602604
// NOTE: `stats(head_tree)` is also possible, but we have a separate thread for that.
603605
.for_each_to_obtain_tree(&head_tree, move |change| -> anyhow::Result<Action> {
604606
change_tx.send(change.detach()).ok();

crates/gitbutler-project/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ resolve-path = "0.1.0"
2323
# for locking
2424
fslock = "0.2.1"
2525

26-
[[test]]
27-
name="project"
28-
path = "tests/mod.rs"
29-
3026
[dev-dependencies]
3127
gitbutler-testsupport.workspace = true
3228
tempfile = "3.13"

crates/gitbutler-project/src/controller.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@ impl Controller {
4545
bail!("can only work in main worktrees");
4646
};
4747
}
48-
Ok(_repo) => {}
48+
Ok(repo) => {
49+
match repo.work_dir() {
50+
None => bail!("Cannot add non-bare repositories without a workdir"),
51+
Some(wd) => {
52+
if !wd.join(".git").is_dir() {
53+
bail!("A git-repository without a `.git` directory cannot currently be added");
54+
}
55+
}
56+
}
57+
}
4958
Err(err) => {
5059
return Err(anyhow::Error::from(err))
5160
.context(error::Context::new("must be a Git repository"));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
git init simple
5+
(cd simple
6+
>file && git add file && git commit -m "init"
7+
)
8+
9+
git clone simple submodule
10+
11+
git clone simple with-submodule
12+
(cd with-submodule
13+
git submodule add ../submodule
14+
git commit -m "add submodule"
15+
)
16+
17+
git clone --bare simple non-bare-without-worktree
18+
(cd non-bare-without-worktree
19+
git config core.bare false
20+
)

crates/gitbutler-project/tests/mod.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

crates/gitbutler-project/tests/projects.rs renamed to crates/gitbutler-project/tests/projects/main.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@ mod add {
2323

2424
mod error {
2525
use super::*;
26+
use std::path::PathBuf;
27+
28+
#[test]
29+
fn non_bare_without_worktree() {
30+
let (controller, _tmp) = new();
31+
let root = repo_path_at("non-bare-without-worktree");
32+
let err = controller.add(root).unwrap_err();
33+
assert_eq!(
34+
err.to_string(),
35+
"Cannot add non-bare repositories without a workdir"
36+
);
37+
}
38+
39+
#[test]
40+
fn submodule() {
41+
let (controller, _tmp) = new();
42+
let root = repo_path_at("with-submodule").join("submodule");
43+
let err = controller.add(root).unwrap_err();
44+
assert_eq!(
45+
err.to_string(),
46+
"A git-repository without a `.git` directory cannot currently be added"
47+
);
48+
}
2649

2750
#[test]
2851
fn missing() {
@@ -113,6 +136,14 @@ mod add {
113136
)
114137
.unwrap()
115138
}
139+
140+
fn repo_path_at(name: &str) -> PathBuf {
141+
gitbutler_testsupport::gix_testtools::scripted_fixture_read_only(
142+
"various-repositories.sh",
143+
)
144+
.unwrap()
145+
.join(name)
146+
}
116147
}
117148
}
118149

crates/gitbutler-testsupport/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#![forbid(rust_2018_idioms)]
22
pub const VAR_NO_CLEANUP: &str = "GITBUTLER_TESTS_NO_CLEANUP";
33

4+
/// Direct access to lower-level utilities for cases where this is enough.
5+
///
6+
/// Prefer to use [`read_only`] and [`writable`] otherwise.
7+
pub use gix_testtools;
8+
49
mod test_project;
510
pub use test_project::TestProject;
611

0 commit comments

Comments
 (0)