Skip to content

URLs passed to repo.git.remote in reverse in Remote.set_url #562

Closed
@GDYendell

Description

@GDYendell

In Remote.set_url, the new_url and old_url seem to be passed to the repo.git.remote command in the wrong order if old_url is provided:

def set_url(self, new_url, old_url=None, **kwargs):
        """Configure URLs on current remote (cf command git remote set_url)
        This command manages URLs on the remote.
        :param new_url: string being the URL to add as an extra remote URL
        :param old_url: when set, replaces this URL with new_url for the remote
        :return: self
        """
        scmd = 'set-url'
        kwargs['insert_kwargs_after'] = scmd
        if old_url:
            self.repo.git.remote(scmd, self.name, old_url, new_url, **kwargs)
        else:
            self.repo.git.remote(scmd, self.name, new_url, **kwargs)
        return self

The git scm says they should be the other way around:

git remote set-url [--push] <name> <newurl> [<oldurl>]

This leads to the following behaviour:

remote = repo.create_remote("upstream", "place")
remote.set_url("new_place", "place")

results in:

git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git remote set-url upstream place new_place
  stderr: 'fatal: No such URL found: new_place'

Activity

Byron

Byron commented on Dec 22, 2016

@Byron
Member

Thanks a lot for reporting this! A fix fix is on the way.

tik9

tik9 commented on Jul 18, 2021

@tik9

I want to change a remote with set-url, how is it: remote = repo.create_remote("upstream", "place") remote.set_url("new_place", "place") will not work, becaue I do not want to create a remote. Any help?

Byron

Byron commented on Jul 19, 2021

@Byron
Member

repo.remotes[name].set_url(…) should do the job, assuming the remote definitely exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Byron@tik9@GDYendell

        Issue actions

          URLs passed to repo.git.remote in reverse in Remote.set_url · Issue #562 · gitpython-developers/GitPython