libgit2 / libgit2/libgit2sharp
Index.Remove with directory/pattern does not always work
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C#
- Sterne
- 3.5k
- Forks
- 925
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
The problem could be related to the commit operation but I'm not sure. If instead of repo.Index.Remove("*") you pass the filename, it is correctly removed from the Index.
Also if you commit the file using the console git client the * version starts working correctly.
For reproduction please see the following unit test:
using LibGit2Sharp;
using NUnit.Framework;
using System;
using System.IO;
using System.Linq;
namespace Tests
{
public class LibGitTest
{
[Test]
public void TestRemove()
{
var tempPath = Path.Combine(Path.GetTempPath(), "LibGitTest");
if (Directory.Exists(tempPath))
{
DeleteDirectory(tempPath);
}
Directory.CreateDirectory(tempPath);
using (var repo = new Repository(Repository.Init(tempPath)))
{
File.WriteAllText(Path.Combine(tempPath, "a.txt"), "some text");
repo.Stage("*.*");
var signature = repo.Config.BuildSignature(DateTimeOffset.Now);
repo.Commit("Initial commit", signature, signature);
repo.Index.Remove("*");
// repo.Index.Remove("a.txt"); // uncomment this line to make the test pass
var status = repo.RetrieveStatus();
Assert.Contains("a.txt", status.Removed.Select(entry => entry.FilePath).ToArray());
}
}
private static void DeleteDirectory(string tempPath)
{
// Some files in the .git folder are readonly, I'm not sure whether that's normal, but we need to reset the flag in order to successfully delete the directory
Directory.EnumerateFiles(Path.Combine(tempPath), "*", SearchOption.AllDirectories)
.ForEach(f => File.SetAttributes(f, File.GetAttributes(f) & ~FileAttributes.ReadOnly));
Directory.Delete(tempPath, recursive: true);
}
}
}
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, den Unit-Test TestRemove auszuführen und das Verhalten von repo.Index.Remove("*") im Vergleich zum direkten Entfernen von "a.txt" zu untersuchen. Verfolge das Entfernen aus dem Index und das anschließende Ergebnis von RetrieveStatus(), einschließlich der Frage, ob der Commit-Vorgang das Pattern-Matching beeinflusst. Als abgeschlossen gilt die Aufgabe, wenn der bestehende Test mit der Wildcard-Entfernung erfolgreich ist und das Verhalten beim direkten Dateinamen weiterhin korrekt bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp, git
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100