diff options
author | Wendell Sun <iwendellsun@gmail.com> | 2018-01-28 01:54:26 +0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2018-01-27 19:54:26 +0200 |
commit | b627f1131b59172cf4a9f238fb89cd415cbc38e0 (patch) | |
tree | 991253f32eef302f1a0f738c64effe153f08a1d0 /models | |
parent | 9e842c8a722eb1db50cfbdbe7146b67d3670052f (diff) | |
download | gitea-b627f1131b59172cf4a9f238fb89cd415cbc38e0.tar.gz gitea-b627f1131b59172cf4a9f238fb89cd415cbc38e0.zip |
Change local copy origin url after repository rename (#3399)
Fix #3378
Diffstat (limited to 'models')
-rw-r--r-- | models/repo.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/models/repo.go b/models/repo.go index a9e116d6bd..59d2336781 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1580,10 +1580,19 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error) } // Change repository directory name. - if err = os.Rename(repo.RepoPath(), RepoPath(u.Name, newRepoName)); err != nil { + newRepoPath := RepoPath(u.Name, newRepoName) + if err = os.Rename(repo.RepoPath(), newRepoPath); err != nil { return fmt.Errorf("rename repository directory: %v", err) } + localPath := repo.LocalCopyPath() + if com.IsExist(localPath) { + _, err := git.NewCommand("remote", "set-url", "origin", newRepoPath).RunInDir(localPath) + if err != nil { + return fmt.Errorf("git remote set-url origin %s: %v", newRepoPath, err) + } + } + wikiPath := repo.WikiPath() if com.IsExist(wikiPath) { if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil { |