Skip to content

Commit bef93ab

Browse files
zeripathlunny
andauthored
Ensure that git repository is closed before transfer (#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 <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent be91df4 commit bef93ab

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

routers/api/v1/repo/transfer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ func Transfer(ctx *context.APIContext) {
9898
}
9999
}
100100

101+
if ctx.Repo.GitRepo != nil {
102+
ctx.Repo.GitRepo.Close()
103+
ctx.Repo.GitRepo = nil
104+
}
105+
101106
if err := repo_service.StartRepositoryTransfer(ctx.User, newOwner, ctx.Repo.Repository, teams); err != nil {
102107
if models.IsErrRepoTransferInProgress(err) {
103108
ctx.Error(http.StatusConflict, "CreatePendingRepositoryTransfer", err)

routers/web/repo/repo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ func acceptOrRejectRepoTransfer(ctx *context.Context, accept bool) error {
323323
}
324324

325325
if accept {
326+
if ctx.Repo.GitRepo != nil {
327+
ctx.Repo.GitRepo.Close()
328+
ctx.Repo.GitRepo = nil
329+
}
330+
326331
if err := repo_service.TransferOwnership(repoTransfer.Doer, repoTransfer.Recipient, ctx.Repo.Repository, repoTransfer.Teams); err != nil {
327332
return err
328333
}

0 commit comments

Comments
 (0)