Skip to content

Commit b627f11

Browse files
xwjdshlafriks
authored andcommitted
Change local copy origin url after repository rename (#3399)
Fix #3378
1 parent 9e842c8 commit b627f11

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

models/repo.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,10 +1580,19 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
15801580
}
15811581

15821582
// Change repository directory name.
1583-
if err = os.Rename(repo.RepoPath(), RepoPath(u.Name, newRepoName)); err != nil {
1583+
newRepoPath := RepoPath(u.Name, newRepoName)
1584+
if err = os.Rename(repo.RepoPath(), newRepoPath); err != nil {
15841585
return fmt.Errorf("rename repository directory: %v", err)
15851586
}
15861587

1588+
localPath := repo.LocalCopyPath()
1589+
if com.IsExist(localPath) {
1590+
_, err := git.NewCommand("remote", "set-url", "origin", newRepoPath).RunInDir(localPath)
1591+
if err != nil {
1592+
return fmt.Errorf("git remote set-url origin %s: %v", newRepoPath, err)
1593+
}
1594+
}
1595+
15871596
wikiPath := repo.WikiPath()
15881597
if com.IsExist(wikiPath) {
15891598
if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil {

0 commit comments

Comments
 (0)