Skip to content

fix 5099 #5100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
383 changes: 192 additions & 191 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ resolver = "2"
[workspace.dependencies]
bstr = "1.10.0"
# Add the `tracing` or `tracing-detail` features to see more of gitoxide in the logs. Useful to see which programs it invokes.
gix = { git = "https://github.com/Byron/gitoxide", rev = "72daa46bad9d397ef2cc48a3cffda23f414ccd8a", default-features = false, features = [
gix = { git = "https://github.com/Byron/gitoxide", rev = "64872690e60efdd9267d517f4d9971eecd3b875c", default-features = false, features = [
] }
git2 = { version = "0.19.0", features = [
"vendored-openssl",
Expand Down
6 changes: 4 additions & 2 deletions crates/gitbutler-branch-actions/src/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use gitbutler_repo::{GixRepositoryExt, RepositoryExt as _};
use gitbutler_serde::BStringForFrontend;
use gitbutler_stack::{Stack as GitButlerBranch, StackId, Target};
use gix::object::tree::diff::Action;
use gix::prelude::ObjectIdExt;
use gix::prelude::{ObjectIdExt, TreeDiffChangeExt};
use gix::reference::Category;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
Expand Down Expand Up @@ -598,7 +598,9 @@ pub fn get_branch_listing_details(
};
base_tree
.changes()?
.track_rewrites(None)
.options(|opts| {
opts.track_rewrites(None);
})
// NOTE: `stats(head_tree)` is also possible, but we have a separate thread for that.
.for_each_to_obtain_tree(&head_tree, move |change| -> anyhow::Result<Action> {
change_tx.send(change.detach()).ok();
Expand Down
4 changes: 0 additions & 4 deletions crates/gitbutler-project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ resolve-path = "0.1.0"
# for locking
fslock = "0.2.1"

[[test]]
name="project"
path = "tests/mod.rs"

[dev-dependencies]
gitbutler-testsupport.workspace = true
tempfile = "3.13"
Expand Down
11 changes: 10 additions & 1 deletion crates/gitbutler-project/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ impl Controller {
bail!("can only work in main worktrees");
};
}
Ok(_repo) => {}
Ok(repo) => {
match repo.work_dir() {
None => bail!("Cannot add non-bare repositories without a workdir"),
Some(wd) => {
if !wd.join(".git").is_dir() {
bail!("A git-repository without a `.git` directory cannot currently be added");
}
}
}
}
Err(err) => {
return Err(anyhow::Error::from(err))
.context(error::Context::new("must be a Git repository"));
Expand Down
20 changes: 20 additions & 0 deletions crates/gitbutler-project/tests/fixtures/various-repositories.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -eu -o pipefail

git init simple
(cd simple
>file && git add file && git commit -m "init"
)

git clone simple submodule

git clone simple with-submodule
(cd with-submodule
git submodule add ../submodule
git commit -m "add submodule"
)

git clone --bare simple non-bare-without-worktree
(cd non-bare-without-worktree
git config core.bare false
)
1 change: 0 additions & 1 deletion crates/gitbutler-project/tests/mod.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ mod add {

mod error {
use super::*;
use std::path::PathBuf;

#[test]
fn non_bare_without_worktree() {
let (controller, _tmp) = new();
let root = repo_path_at("non-bare-without-worktree");
let err = controller.add(root).unwrap_err();
assert_eq!(
err.to_string(),
"Cannot add non-bare repositories without a workdir"
);
}

#[test]
fn submodule() {
let (controller, _tmp) = new();
let root = repo_path_at("with-submodule").join("submodule");
let err = controller.add(root).unwrap_err();
assert_eq!(
err.to_string(),
"A git-repository without a `.git` directory cannot currently be added"
);
}

#[test]
fn missing() {
Expand Down Expand Up @@ -113,6 +136,14 @@ mod add {
)
.unwrap()
}

fn repo_path_at(name: &str) -> PathBuf {
gitbutler_testsupport::gix_testtools::scripted_fixture_read_only(
"various-repositories.sh",
)
.unwrap()
.join(name)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions crates/gitbutler-testsupport/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#![forbid(rust_2018_idioms)]
pub const VAR_NO_CLEANUP: &str = "GITBUTLER_TESTS_NO_CLEANUP";

/// Direct access to lower-level utilities for cases where this is enough.
///
/// Prefer to use [`read_only`] and [`writable`] otherwise.
pub use gix_testtools;

mod test_project;
pub use test_project::TestProject;

Expand Down
Loading