Skip to content

Commit 88143f1

Browse files
committed
models/repo: UpdateLocalCopy should always aceept valid branch name
1 parent 3137665 commit 88143f1

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/gogits/gogs/modules/setting"
1717
)
1818

19-
const APP_VER = "0.9.149.0215"
19+
const APP_VER = "0.9.150.0216"
2020

2121
func init() {
2222
setting.AppVer = APP_VER

models/repo.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,17 @@ func (repo *Repository) LocalCopyPath() string {
469469
}
470470

471471
// UpdateLocalCopy fetches latest changes of given branch from repoPath to localPath.
472-
// It creates a new clone if local copy does not exist.
473-
// This function checks out target branch by default, it is safe to assume subsequent
474-
// operations are operating against target branch when caller has confidence for no race condition.
475-
func UpdateLocalCopyBranch(repoPath, localPath, branch string) (err error) {
472+
// It creates a new clone if local copy does not exist, but does not checks out to a
473+
// specific branch if the local copy belongs to a wiki.
474+
// For existing local copy, it checks out to target branch by default, and safe to
475+
// assume subsequent operations are against target branch when caller has confidence
476+
// about no race condition.
477+
func UpdateLocalCopyBranch(repoPath, localPath, branch string, isWiki bool) (err error) {
476478
if !com.IsExist(localPath) {
479+
// Checkout to a specific branch fails when wiki is an empty repository.
480+
if isWiki {
481+
branch = ""
482+
}
477483
if err = git.Clone(repoPath, localPath, git.CloneRepoOptions{
478484
Timeout: time.Duration(setting.Git.Timeout.Clone) * time.Second,
479485
Branch: branch,
@@ -502,7 +508,7 @@ func UpdateLocalCopyBranch(repoPath, localPath, branch string) (err error) {
502508

503509
// UpdateLocalCopyBranch makes sure local copy of repository in given branch is up-to-date.
504510
func (repo *Repository) UpdateLocalCopyBranch(branch string) error {
505-
return UpdateLocalCopyBranch(repo.RepoPath(), repo.LocalCopyPath(), branch)
511+
return UpdateLocalCopyBranch(repo.RepoPath(), repo.LocalCopyPath(), branch, false)
506512
}
507513

508514
// PatchPath returns corresponding patch file path of repository by given issue ID.

models/wiki.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ func (repo *Repository) LocalWikiPath() string {
7676

7777
// UpdateLocalWiki makes sure the local copy of repository wiki is up-to-date.
7878
func (repo *Repository) UpdateLocalWiki() error {
79-
// Don't pass branch name here because it fails to clone and
80-
// checkout to a specific branch when wiki is an empty repository.
81-
return UpdateLocalCopyBranch(repo.WikiPath(), repo.LocalWikiPath(), "")
79+
return UpdateLocalCopyBranch(repo.WikiPath(), repo.LocalWikiPath(), "master", true)
8280
}
8381

8482
func discardLocalWikiChanges(localPath string) error {

templates/.VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.149.0215
1+
0.9.150.0216

0 commit comments

Comments
 (0)