libgit2 / libgit2/libgit2sharp

Index.Remove with directory/pattern does not always work

Abierto
#1,350 11 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
C#
Estrellas
3.5k
Forks
925
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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);
        }
    }
}

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza ejecutando la prueba unitaria TestRemove e inspecciona el comportamiento de repo.Index.Remove("*") en comparación con la eliminación directa de "a.txt". Traza la eliminación del índice y el resultado posterior de RetrieveStatus(), incluyendo si la operación de commit afecta a la coincidencia de patrones. Se considera completado cuando la prueba existente pasa con la eliminación mediante comodín y el comportamiento con el nombre de archivo directo sigue siendo correcto.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
csharp, git
Área
devtools
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.