From 6d10abcf67200a9ea7dcbfed3f02e5078e559344 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Mon, 20 Dec 2021 21:56:34 +0000 Subject: [PATCH] Ensure that git repository is closed before transfer 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 abaed4d587076..dd7730b42c86f 100644 --- a/routers/api/v1/repo/transfer.go +++ b/routers/api/v1/repo/transfer.go @@ -98,6 +98,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 a1e652f94cc9a..9a36e6ee1db08 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -323,6 +323,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 }