Skip to content

Commit 037d5a3

Browse files
Update only the repository columns that need updating (#12900)
We should only update is_empty, default_branch and updated time columns during commitRepoAction and not update other columns as we risk overwriting incorrect information. Fix #11823 Fix #10536 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 7e54995 commit 037d5a3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

services/repository/push.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"fmt"
1111
"strings"
12+
"time"
1213

1314
"code.gitea.io/gitea/models"
1415
"code.gitea.io/gitea/modules/cache"
@@ -291,6 +292,10 @@ func commitRepoAction(repo *models.Repository, gitRepo *git.Repository, optsList
291292
}
292293
}
293294
}
295+
// Update the is empty and default_branch columns
296+
if err := models.UpdateRepositoryCols(repo, "default_branch", "is_empty"); err != nil {
297+
return fmt.Errorf("UpdateRepositoryCols: %v", err)
298+
}
294299
}
295300

296301
opType := models.ActionCommitRepo
@@ -359,9 +364,9 @@ func commitRepoAction(repo *models.Repository, gitRepo *git.Repository, optsList
359364
}
360365
}
361366

362-
// Change repository empty status and update last updated time.
363-
if err := models.UpdateRepository(repo, false); err != nil {
364-
return fmt.Errorf("UpdateRepository: %v", err)
367+
// Change repository last updated time.
368+
if err := models.UpdateRepositoryUpdatedTime(repo.ID, time.Now()); err != nil {
369+
return fmt.Errorf("UpdateRepositoryUpdatedTime: %v", err)
365370
}
366371

367372
if err := models.NotifyWatchers(actions...); err != nil {

0 commit comments

Comments
 (0)