You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue seems to be in libgit2 libgit2/libgit2#6049 where the is_empty function only returns true if the branch is called "master". This causes the issue in this line where is_empty is set to false for empty repositories with a "main" branch instead of "master".
The fix is pretty simple, just need to try and get the head, if we can't get the head the repo is empty, otherwise, it is not.
src/git/commit.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/git/commit.rs b/src/git/commit.rs--- a/src/git/commit.rs+++ b/src/git/commit.rs@@ -8,7 +8,7 @@ impl Repository {
let sig = self.0.signature()?;
let tree_id = self.0.index()?.write_tree()?;
let tree = self.0.find_tree(tree_id)?;
- let is_empty = self.0.is_empty()?;+ let is_empty = self.0.head().is_err();
let has_delta = self.get_diff(false).is_some();
if !is_empty && has_delta {
I'd be happy to submit a pull request for this as well if you prefer.
The `is_empty` function exposed by libgit2 requires the default branch to be
"master". If a repository is created with a default branch not named master `is_empty`
will return false even when the repository is empty.
The fix is simply to try and access the HEAD of the repository. If the head
cant be accessed it means that the repository is still empty.
Closescocogitto#145
The `is_empty` function exposed by libgit2 requires the default branch to be
"master". If a repository is created with a default branch not named master `is_empty`
will return false even when the repository is empty.
The fix is simply to try and access the HEAD of the repository. If the head
cant be accessed it means that the repository is still empty.
Closescocogitto#145
Describe the bug
The text was updated successfully, but these errors were encountered: