Skip to content

[GitDsc/GitRemote] Set method doesn't work if remote already exists #45

Description

Brief description of your issue

If the RemoteName you're setting already exists in the local repository, Set method does not overwrite the existing remote url value for you. This means you're not in the desired state even after calling the Set method.

This is because how the resource internally works is by using the command git remote add <RemoteName> <RemoteUrl>
The above command only works if the remote does not exist. If it already exists, then you have to use the command git remote set-url <RemoteName> <RemoteUrl>. The resource should be updated to handle these states.

One approach can be to always try to remove RemoteName before calling git remote add. If the remote ref doesn't exist, git will throw an error which we could ignore and continue with setting the remote through git remote add. That way the command will always set the correct remote. There should be code to save the previous remote in case setting the new one fails so that we don't get the user's repo in a bad state.

Steps to reproduce

Run the following

$gitRemoteConfig = @{
    ProjectDirectory = "C:\Users\...\repos\winget-cli"
    RemoteName = "upstream"
    RemoteUrl = "https://github.com/mdanish-kh/test"
}
Invoke-DscResource -Name GitRemote -Method Set -Property $gitRemoteConfig

Expected behavior

The remote reference should be updated in the local git repo

Actual behavior

Remote reference isn't updated

 ~/repos/winget-cli > git remote -v
upstream        https://github.com/microsoft/winget-cli (fetch)
upstream        https://github.com/microsoft/winget-cli (push)

Should've been changed to RemoteUrl given in the config

Environment

Latest module code from main branch of the repo

No activity

Activity on this issue will appear here.

Activity

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

    Projects

    • Status
      To Do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions