libgit2 / libgit2/libgit2sharp
Index.Remove with directory/pattern does not always work
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 3.5k
- Fork
- 925
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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);
}
}
}
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo il test unitario TestRemove e analizza il comportamento di repo.Index.Remove("*") rispetto alla rimozione diretta di "a.txt". Segui la rimozione dall'indice e il risultato successivo di RetrieveStatus(), verificando anche se l'operazione di commit influisce sulla corrispondenza dei pattern. Il lavoro è completato quando il test esistente passa con la rimozione tramite wildcard e il comportamento con il nome file diretto rimane corretto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp, git
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100