8000 repo.Network.Remotes.Remove does not remove the remote · Issue #1437 · libgit2/libgit2sharp · GitHub
[go: up one dir, main page]

Skip to content

repo.Network.Remotes.Remove does not remove the remote #1437

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

Open
suwatch opened this issue Apr 17, 2017 · 5 comments
Open

repo.Network.Remotes.Remove does not remove the remote #1437

suwatch opened this issue Apr 17, 2017 · 5 comments

Comments

@suwatch
Copy link
suwatch commented Apr 17, 2017

We have this code below where we remove remote (origin) before adding a new one. From time to time, Add would fail with remote already exists. Is there an issue where remote is not removed when calling repo.Network.Remotes.Remove? Is it a race condition? We doubt it is since rerun the same code still yield remote already exists. Anything we do wrong or can improve? BTW, if we run git remote remove origin command, then it is removed - so repo is not corrupted.

repo.Network.Remotes.Remove(_remoteAlias);

// Configure the remote
remote = repo.Network.Remotes.Add(_remoteAlias, remoteUrl, refSpec);
@arutkowski00
Copy link

I have the same issue. It does remove url and fetch fields from remote section but does not remove the section header.

[remote "origin"]
	url = ssh://test@test.com/test/repo
	fetch = +refs/heads/*:refs/remotes/origin/*
[remote "32137c08-b0d0-45e4-88b9-a3b15fc72d95"]
[remote "aef18d06-5524-4fd3-9f2e-4d5849048a48"]
[remote "00d58c81-3bf2-4276-8695-7167a10b6caf"]
[remote "10044228-77c9-4355-bc3a-11e444c5a8f8"]
[remote "e87ecf5a-37c7-4619-9214-9bfcd9f9b9a3"]

@ethomson
Copy link
Member

Thanks for reporting this and @arutkowski00 for the helpful clarification. We'll take a look.

@carlosmn
Copy link
Member

The section header should be irrelevant for the existence of the remote. A remote does not exist because the header exists. Not removing the header is just a cosmetic bug because we do not remove entire sections but individual configuration entries.

What is the state of the config file when this error occurs? Is there concurrent access that might stop us from modifying the file (assuming you're on Windows).

@suwatch
Copy link
Author
suwatch commented Apr 18, 2017

@carlosmn We always synchronize call to git operation (so no concurrent access). As for file may not be writable, we are sure it was since calling git remote remove origin successfully remove it. Unfortunately, we did not capture the state of the config file - will do once it repro-ed again.

@jskeet
Copy link
jskeet commented May 6, 2025

I can still reproduce this with 0.31.0.

Repro steps

Step 1: Create a new repo with git init

Step 2: Add a remote: git add remote abc https://abc

Step 3: Run the following code:

using LibGit2Sharp;

var repo = new Repository(".");

LogRemotes("Initial");
repo.Network.Remotes.Add("test", "https://bogus");
LogRemotes("After adding");
repo.Network.Remotes.Remove("test");
LogRemotes("After removing");

void LogRemotes(string description)
{
    Console.WriteLine(description);
    foreach (var remote in repo.Network.Remotes)
    {
        Console.WriteLine($"{remote.Name}: {remote.Url}");
    }
    Console.WriteLine();
}

Step 4: cat .git/config

Repro output

Step 3 - this looks okay

Initial
abc: https://abc

After adding
abc: https://abc
test: https://bogus

After removing
abc: https://abc

Step 4 - this is broken:

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "abc"]
        url = https://abc
        fetch = +refs/heads/*:refs/remotes/abc/*
[remote "test"]

The empty [remote "test"] at the end is causing problems elsewhere in my system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
0