summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-08-30 23:10:24 -0400
committerGitHub <noreply@github.com>2021-08-30 23:10:24 -0400
commit3addb796d392ff6bbd3917a48d81848d40821c5b (patch)
treed36a9e577cb73818a1fa6c06d6443f7aee49f058
parent4e8840fd195953af7a7fb2c61e46d6f177cbd81d (diff)
parente71505b3372028d073bf1d2268d3cdc7bc934708 (diff)
downloadlibgit2-3addb796d392ff6bbd3917a48d81848d40821c5b.tar.gz
Merge pull request #5943 from kcsaul/fix/5851
Fix worktree iteration when repository has no common directory
-rw-r--r--src/repository.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/repository.c b/src/repository.c
index 9ed46bf4d..aae0c910b 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -2335,6 +2335,12 @@ int git_repository_foreach_worktree(git_repository *repo,
int error;
size_t i;
+ /* apply operation to repository supplied when commondir is empty, implying there's
+ * no linked worktrees to iterate, which can occur when using custom odb/refdb
+ */
+ if (!repo->commondir)
+ return cb(repo, payload);
+
if ((error = git_repository_open(&worktree_repo, repo->commondir)) < 0 ||
(error = cb(worktree_repo, payload) != 0))
goto out;