From 6de75224de3c8c9bd75e8e4b9e78c22a3cf468e1 Mon Sep 17 00:00:00 2001 From: zeripath Date: Tue, 21 Dec 2021 18:27:46 +0000 Subject: [PATCH] Ensure that git repository is closed before transfer (#18049) (#18057) Backport #18049 Repository Transfer requires that the repository directory is renamed - which is not possible on Windows if the git repository is open. Fix #17885 Signed-off-by: Andrew Thornton --- routers/api/v1/repo/transfer.go | 5 +++++ routers/web/repo/repo.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go index 2e052aa4f..11e56defe 100644 --- a/routers/api/v1/repo/transfer.go +++ b/routers/api/v1/repo/transfer.go @@ -96,6 +96,11 @@ func Transfer(ctx *context.APIContext) { } } + if ctx.Repo.GitRepo != nil { + ctx.Repo.GitRepo.Close() + ctx.Repo.GitRepo = nil + } + if err := repo_service.StartRepositoryTransfer(ctx.User, newOwner, ctx.Repo.Repository, teams); err != nil { if models.IsErrRepoTransferInProgress(err) { ctx.Error(http.StatusConflict, "CreatePendingRepositoryTransfer", err) diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 8d5546f8c..0b300d32b 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -319,6 +319,11 @@ func acceptOrRejectRepoTransfer(ctx *context.Context, accept bool) error { } if accept { + if ctx.Repo.GitRepo != nil { + ctx.Repo.GitRepo.Close() + ctx.Repo.GitRepo = nil + } + if err := repo_service.TransferOwnership(repoTransfer.Doer, repoTransfer.Recipient, ctx.Repo.Repository, repoTransfer.Teams); err != nil { return err }