Skip to content

Commit e71505b

Browse files
committed
repo: fix worktree iteration when repo has no common directory
When applying an operation to a repository created without a common directory, which is known to occur in scenarios where custom odb/refdb backends are used, git_repository_foreach_worktree currently asserts while attempting to open the repository located in the common directory. Fix this issue by applying operation to repository supplied when there are no linked worktrees to iterate (implied by common directory being empty).
1 parent 6c78fd0 commit e71505b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/repository.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,12 @@ int git_repository_foreach_worktree(git_repository *repo,
23392339
int error;
23402340
size_t i;
23412341

2342+
/* apply operation to repository supplied when commondir is empty, implying there's
2343+
* no linked worktrees to iterate, which can occur when using custom odb/refdb
2344+
*/
2345+
if (!repo->commondir)
2346+
return cb(repo, payload);
2347+
23422348
if ((error = git_repository_open(&worktree_repo, repo->commondir)) < 0 ||
23432349
(error = cb(worktree_repo, payload) != 0))
23442350
goto out;

0 commit comments

Comments
 (0)