Skip to content
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

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

Open
mdanish-kh opened this issue Jun 23, 2024 · 0 comments
Open

Comments

@mdanish-kh
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants