diff -r 610b676336be -r b11c36cba2a1 Plugins/VcsPlugins/vcsGit/git.py --- a/Plugins/VcsPlugins/vcsGit/git.py Sun Jun 03 11:30:57 2018 +0200 +++ b/Plugins/VcsPlugins/vcsGit/git.py Sun Jun 03 14:03:19 2018 +0200 @@ -2787,6 +2787,35 @@ return remotesList + def gitGetRemoteUrl(self, repodir, remoteName): + """ + Public method to get the URL of a remote repository. + + @param repodir directory name of the repository + @type str + @param remoteName name of the remote repository + @type str + @return URL of the remote repository + @rtype str + """ + args = self.initCommand("remote") + args.append("get-url") + args.append(remoteName) + + output = "" + process = QProcess() + process.setWorkingDirectory(repodir) + process.start('git', args) + procStarted = process.waitForStarted(5000) + if procStarted: + finished = process.waitForFinished(30000) + if finished and process.exitCode() == 0: + output = str(process.readAllStandardOutput(), + Preferences.getSystem("IOEncoding"), + 'replace').strip() + + return output + def gitGetRemoteBranchesList(self, repodir, remote): """ Public method to get the list of a remote repository branches. @@ -2909,6 +2938,74 @@ self.startSynchronizedProcess(QProcess(), "git", args, workingDir=repodir) + def gitChangeRemoteUrl(self, projectDir, remoteName, remoteUrl=""): + """ + Public method to change the URL of a remote repository. + + @param projectDir name of the project directory + @type str + @param remoteName name of the remote repository + @type str + @param remoteUrl URL of the remote repository + @type str + """ + # find the root of the repo + repodir = projectDir + while not os.path.isdir(os.path.join(repodir, self.adminDir)): + repodir = os.path.dirname(repodir) + if os.path.splitdrive(repodir)[1] == os.sep: + return + + if not remoteUrl: + remoteUrl = self.gitGetRemoteUrl(repodir, remoteName) + + from .GitChangeRemoteUrlDialog import GitChangeRemoteUrlDialog + dlg = GitChangeRemoteUrlDialog(remoteName, remoteUrl) + if dlg.exec_() == QDialog.Accepted: + name, url = dlg.getData() + if url != remoteUrl: + args = self.initCommand("remote") + args.append("set-url") + args.append(name) + args.append(url) + + self.startSynchronizedProcess(QProcess(), "git", args, + workingDir=repodir) + + def gitChangeRemoteCredentials(self, projectDir, remoteName, remoteUrl=""): + """ + Public method to change the user credentials of a remote repository. + + @param projectDir name of the project directory + @type str + @param remoteName name of the remote repository + @type str + @param remoteUrl URL of the remote repository + @type str + """ + # find the root of the repo + repodir = projectDir + while not os.path.isdir(os.path.join(repodir, self.adminDir)): + repodir = os.path.dirname(repodir) + if os.path.splitdrive(repodir)[1] == os.sep: + return + + if not remoteUrl: + remoteUrl = self.gitGetRemoteUrl(repodir, remoteName) + + from .GitRemoteCredentialsDialog import GitRemoteCredentialsDialog + dlg = GitRemoteCredentialsDialog(remoteName, remoteUrl) + if dlg.exec_() == QDialog.Accepted: + name, url = dlg.getData() + if url != remoteUrl: + args = self.initCommand("remote") + args.append("set-url") + args.append(name) + args.append(url) + + self.startSynchronizedProcess(QProcess(), "git", args, + workingDir=repodir) + def gitRemoveRemote(self, projectDir, remoteName): """ Public method to remove a remote repository.