Skip to content

various fixes #1684

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 2 commits into from
Nov 17, 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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ default = ["max"]
##
## As fast as possible, tracing, with TUI progress, progress line rendering with autoconfiguration, all transports based on their most mature implementation (HTTP), all `ein` tools, CLI colors and local-time support, JSON output, regex support for rev-specs.
## Can be amended with the `http-client-curl-rustls` feature to avoid `openssl` as backend.
max = ["max-control", "fast", "gitoxide-core-blocking-client", "http-client-curl"]
max = ["max-control", "fast", "gitoxide-core-tools-query", "gitoxide-core-tools-corpus", "gitoxide-core-blocking-client", "http-client-curl"]

## Like `max`, but only Rust is allowed.
##
Expand All @@ -47,9 +47,9 @@ max = ["max-control", "fast", "gitoxide-core-blocking-client", "http-client-curl
max-pure = ["max-control", "gix-features/rustsha1", "gix-features/zlib-rust-backend", "http-client-reqwest", "gitoxide-core-blocking-client"]

## Like `max`, but with more control for configuration. See the *Package Maintainers* headline for more information.
max-control = ["tracing", "fast-safe", "pretty-cli", "gitoxide-core-tools-query", "gitoxide-core-tools-corpus", "gitoxide-core-tools", "prodash-render-line", "prodash-render-tui", "prodash/render-line-autoconfigure", "gix/revparse-regex"]
max-control = ["tracing", "fast-safe", "pretty-cli", "gitoxide-core-tools", "prodash-render-line", "prodash-render-tui", "prodash/render-line-autoconfigure", "gix/revparse-regex"]

## All of the good stuff, with less fanciness for smaller binaries.
## All the good stuff, with less fanciness for smaller binaries.
##
## As fast as possible, progress line rendering, all transports based on their most mature implementation (HTTP), all `ein` tools, CLI colors and local-time support, JSON output.
lean = ["fast", "tracing", "pretty-cli", "http-client-curl", "gitoxide-core-tools-query", "gitoxide-core-tools-corpus", "gitoxide-core-tools", "gitoxide-core-blocking-client", "prodash-render-line"]
Expand Down
34 changes: 26 additions & 8 deletions gix/src/open/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,33 @@ impl ThreadSafeRepository {
}
}

match worktree_dir {
None if !config.is_bare && refs.git_dir().file_name() == Some(OsStr::new(gix_discover::DOT_GIT_DIR)) => {
worktree_dir = Some(git_dir.parent().expect("parent is always available").to_owned());
}
Some(_) => {
// note that we might be bare even with a worktree directory - work trees don't have to be
// the parent of a non-bare repository.
{
let looks_like_standard_git_dir =
|| refs.git_dir().file_name() == Some(OsStr::new(gix_discover::DOT_GIT_DIR));
match worktree_dir {
None if !config.is_bare && looks_like_standard_git_dir() => {
worktree_dir = Some(git_dir.parent().expect("parent is always available").to_owned());
}
Some(_) => {
// We may assume that the presence of a worktree-dir means it's not bare, but only if there
// is no configuration saying otherwise.
// Thus, if we are here and the common-dir config claims it's bare and we have inferred a worktree anyway,
// forget about it.
if looks_like_standard_git_dir()
&& config
.resolved
.boolean_filter("core.bare", |md| md.source == gix_config::Source::Local)
.transpose()
.ok()
.flatten()
.is_some()
&& config.is_bare
{
worktree_dir = None;
}
}
None => {}
}
None => {}
}

refs.write_reflog = config::cache::util::reflog_or_default(config.reflog, worktree_dir.is_some());
Expand Down
8 changes: 8 additions & 0 deletions gix/tests/fixtures/make_worktree_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ mkdir $worktree && touch $worktree/file
git add file
git commit -m "make sure na index exists"
)

git init non-bare-turned-bare
(cd non-bare-turned-bare
git commit --allow-empty -m 'empty'
git config core.bare true

git worktree add ../worktree-of-bare-repo
)
35 changes: 33 additions & 2 deletions gix/tests/gix/repository/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,37 @@ fn bare_repo_with_index() -> crate::Result {
Ok(())
}

#[test]
fn non_bare_turned_bare() -> crate::Result {
let repo = named_subrepo_opts(
"make_worktree_repo.sh",
"non-bare-turned-bare",
gix::open::Options::isolated(),
)?;
assert!(
repo.is_bare(),
"the configuration dictates this, even though it looks like a main worktree"
);
assert_eq!(repo.work_dir(), None);
Ok(())
}

#[test]
fn worktree_of_bare_repo() -> crate::Result {
let repo = named_subrepo_opts(
"make_worktree_repo.sh",
"worktree-of-bare-repo",
gix::open::Options::isolated(),
)?;
assert!(!repo.is_bare(), "even though the main worktree is bare, this isn't");
assert_ne!(
repo.work_dir(),
None,
"we have opened the repo through a worktree, which is never bare"
);
Ok(())
}

#[test]
fn non_bare_non_git_repo_without_worktree() -> crate::Result {
let repo = named_subrepo_opts(
Expand Down Expand Up @@ -182,12 +213,12 @@ mod missing_config_file {
"worktree-no-config",
gix::open::Options::isolated(),
)?;
assert!(repo.work_dir().is_some());
assert!(repo.worktree().is_some());
assert!(
!repo.is_bare(),
"without config, we can't really know what the repo is actually but can guess as there is a worktree"
);
assert!(repo.work_dir().is_some());
assert!(repo.worktree().is_some());
assert_eq!(
repo.config_snapshot().meta().source,
gix::config::Source::Local,
Expand Down
Loading