diff options
author | Kevin Saul <kevinsaul@gmail.com> | 2021-07-11 21:24:25 +1200 |
---|---|---|
committer | Kevin Saul <kevinsaul@gmail.com> | 2021-07-11 21:24:25 +1200 |
commit | e71505b3372028d073bf1d2268d3cdc7bc934708 (patch) | |
tree | 036b6c92b0198d84fd6f0aad2f391af497dfcb53 | |
parent | 6c78fd06e3cedec818122ecc7f90e6c81e497354 (diff) | |
download | libgit2-e71505b3372028d073bf1d2268d3cdc7bc934708.tar.gz |
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).
-rw-r--r-- | src/repository.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/repository.c b/src/repository.c index 692f71861..790dc161b 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2339,6 +2339,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; |