diff options
author | Unknwon <u@gogs.io> | 2015-10-04 20:54:06 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-10-04 20:54:06 -0400 |
commit | 215920772ab8d84418e982ee1de8986f911fe3c1 (patch) | |
tree | b3cd6bce4ae72ca497cf9835ea2f7b6cd96bff4b /models/repo.go | |
parent | 02d3b662654d1627ad510b7b330c016e97a7d1af (diff) | |
download | gitea-215920772ab8d84418e982ee1de8986f911fe3c1.tar.gz gitea-215920772ab8d84418e982ee1de8986f911fe3c1.zip |
save PR info as patch and minor fix on PR
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/models/repo.go b/models/repo.go index d70454fc1c..31e3660ae7 100644 --- a/models/repo.go +++ b/models/repo.go @@ -296,6 +296,35 @@ func (repo *Repository) DescriptionHtml() template.HTML { return template.HTML(DescPattern.ReplaceAllStringFunc(base.Sanitizer.Sanitize(repo.Description), sanitize)) } +func (repo *Repository) LocalCopyPath() string { + return path.Join(setting.RepoRootPath, "local", com.ToStr(repo.ID)) +} + +// UpdateLocalCopy makes sure the local copy of repository is up-to-date. +func (repo *Repository) UpdateLocalCopy() error { + repoPath, err := repo.RepoPath() + if err != nil { + return err + } + + localPath := repo.LocalCopyPath() + if !com.IsExist(localPath) { + _, stderr, err := process.Exec( + fmt.Sprintf("UpdateLocalCopy(git clone): %s", repoPath), "git", "clone", repoPath, localPath) + if err != nil { + return fmt.Errorf("git clone: %v - %s", err, stderr) + } + } else { + _, stderr, err := process.ExecDir(-1, localPath, + fmt.Sprintf("UpdateLocalCopy(git pull): %s", repoPath), "git", "pull") + if err != nil { + return fmt.Errorf("git pull: %v - %s", err, stderr) + } + } + + return nil +} + func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) { has, err := e.Get(&Repository{ OwnerID: u.Id, |