libgit2 / libgit2/libgit2sharp
Index.Remove with directory/pattern does not always work
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C#
- Star
- 3.5k
- Fork
- 925
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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);
}
}
}
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy unit test TestRemove và kiểm tra hành vi của repo.Index.Remove("*") so với việc xóa trực tiếp "a.txt". Theo dõi việc xóa khỏi index và kết quả RetrieveStatus() sau đó, bao gồm cả việc thao tác commit có ảnh hưởng đến việc khớp mẫu hay không. Hoàn thành khi test hiện có chạy thành công với việc xóa bằng wildcard và hành vi với tên tệp trực tiếp vẫn chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- csharp, git
- Lĩnh vực
- devtools
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 45/100