Skip to content

Change local copy origin url after repository rename #3399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You usually need to acquire a lock before running a git command in the local copy repo, although I suppose in this case it may be alright not to

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if we really wanted to be safe, we would hold the local-copy lock while renaming the bare repo and while running git remote set-url origin ....

Between renaming the bare repo and running git remote set-url origin ..., any other threads that try to run git commands involving origin in the local copy will fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, you are right, I'll try to do it.

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 {
Expand Down