Skip to content

Conversation

Byron
Copy link
Collaborator

@Byron Byron commented Oct 19, 2025

Tasks

  • proper resolution of .git files
  • Allow opening submodules - it's easy to open them , and it generally works, but for some reason stack_details() runs into trouble and I am out of time. Let's say that once heads_info() is used it's worth looking into this. See patch.
  • See if minimal changes would allow worktrees to be opened as well (single-branch mode)
    • Probably out of scope, as it would mean that back-to-worktree shouldn't be supported
    • Out of time and it's not super important right now. But should happen once single-branch mode is more advanced maybe.
  • fix CI/tests

Another insight: these changes show that we'd really benefit from a CI-driven journey test.

Validation

  • projects added with the new version are opened correctly with the old version, and vice-versa.
  • persisted state of the new version is backwards compatible with the old - the new git_dir field is just ignore.

Discarded Patch

commit 115cae1661417c62fba15169d8a3d113da5840eb
Author: Sebastian Thiel <[email protected]>
Date:   Sun Oct 19 17:45:15 2025 +0200

    Allow submodules to be opened as well (but no worktrees yet) (#5099)
    
    Note that worktrees could also be opened, but they need more testing
    and care as we can't just checkout what we want there, and generally
    need to either prohibit workspaces, or support them on the branch
    the user is currently on. And for that `apply()` needs an upgrade.

diff --git a/crates/gitbutler-project/src/controller.rs b/crates/gitbutler-project/src/controller.rs
index b7bdd92bac..839f9223da 100644
--- a/crates/gitbutler-project/src/controller.rs
+++ b/crates/gitbutler-project/src/controller.rs
@@ -77,9 +77,6 @@ impl Controller {
         if !worktree_dir.exists() {
             return Ok(AddProjectOutcome::PathNotFound);
         }
-        if !worktree_dir.is_dir() {
-            return Ok(AddProjectOutcome::NotADirectory);
-        }
         let resolved_path = gix::path::realpath(worktree_dir)?;
         // Make sure the repo is opened from the resolved path - it must be absolute for persistence.
         let repo = match gix::open_opts(&resolved_path, gix::open::Options::isolated()) {
@@ -92,17 +89,13 @@ impl Controller {
                 };
                 repo
             }
-            Ok(repo) => match repo.workdir() {
-                None => {
+            Ok(repo) => {
+                if repo.workdir().is_none() {
                     return Ok(AddProjectOutcome::NoWorkdir);
-                }
-                Some(wd) => {
-                    if !wd.join(".git").is_dir() {
-                        return Ok(AddProjectOutcome::NoDotGitDirectory);
-                    }
+                } else {
                     repo
                 }
-            },
+            }
             Err(err) => {
                 return Ok(AddProjectOutcome::NotAGitRepository(err.to_string()));
             }
diff --git a/crates/gitbutler-project/src/project.rs b/crates/gitbutler-project/src/project.rs
index 8e701a4f45..5e16cffaaf 100644
--- a/crates/gitbutler-project/src/project.rs
+++ b/crates/gitbutler-project/src/project.rs
@@ -329,11 +329,9 @@ pub enum AddProjectOutcome {
     Added(Project),
     AlreadyExists(Project),
     PathNotFound,
-    NotADirectory,
     BareRepository,
     NonMainWorktree,
     NoWorkdir,
-    NoDotGitDirectory,
     NotAGitRepository(String),
 }
 
@@ -355,9 +353,6 @@ impl AddProjectOutcome {
             AddProjectOutcome::Added(p) => Ok(p),
             AddProjectOutcome::AlreadyExists(_) => Err(anyhow::anyhow!("project already exists")),
             AddProjectOutcome::PathNotFound => Err(anyhow::anyhow!("project path not found")),
-            AddProjectOutcome::NotADirectory => {
-                Err(anyhow::anyhow!("project path is not a directory"))
-            }
             AddProjectOutcome::BareRepository => {
                 Err(anyhow::anyhow!("bare repositories are not supported"))
             }
@@ -365,9 +360,6 @@ impl AddProjectOutcome {
                 Err(anyhow::anyhow!("non-main worktrees are not supported"))
             }
             AddProjectOutcome::NoWorkdir => Err(anyhow::anyhow!("no workdir found for repository")),
-            AddProjectOutcome::NoDotGitDirectory => {
-                Err(anyhow::anyhow!("no .git directory found in repository"))
-            }
             AddProjectOutcome::NotAGitRepository(msg) => {
                 Err(anyhow::anyhow!("not a git repository: {}", msg))
             }

Copy link

vercel bot commented Oct 19, 2025

@Byron is attempting to deploy a commit to the GitButler Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added the rust Pull requests that update Rust code label Oct 19, 2025
This is achieved by somewhat costly, but still cost-minimized handling
of the Git repository itself.
@Byron Byron force-pushed the fix branch 2 times, most recently from 14fdf6b to 0f01651 Compare October 19, 2025 11:59
@Byron
Copy link
Collaborator Author

Byron commented Oct 19, 2025

@krlvi Just as a heads-up, this PR is something to watch out for. While I implement it in such a way that it's backwards compatible, with a path to cleaning up everything, there is always a risk.

Having it now is good as clears the way for supporting opening submodules and worktrees directly (while also laying the foundation for supporting bare repos).

This simply makes a method that we shouldn't have a in the first place fallible.
@Byron Byron marked this pull request as ready for review October 19, 2025 17:08
@Byron Byron enabled auto-merge October 19, 2025 17:08
@Byron Byron merged commit 08f0f5e into gitbutlerapp:master Oct 19, 2025
20 of 21 checks passed
@Byron Byron deleted the fix branch October 19, 2025 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@gitbutler/desktop rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant