8000 Teach Index.Stage to stage files in ignored dirs · philhack/libgit2sharp@885de34 · GitHub
[go: up one dir, main page]

Skip to content

Commit 885de34

Browse files
author
Edward Thomson
committed
Teach Index.Stage to stage files in ignored dirs
If a directory is ignored and you attempt to stage a file beneath that directory, the file is not staged. By having diff return files beneath that ignored dir, we can add that file.
1 parent 27dd2c0 commit 885de34

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

LibGit2Sharp.Tests/StageFixture.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,5 +298,21 @@ public void CanStageWithMultiplePathspecs()
298298
Assert.Equal(count, repo.Index.Count); // 1 added file, 1 deleted file, so same count
299299
}
300300
}
301+
302+
[Theory]
303+
[InlineData("ignored_file.txt")]
304+
[InlineData("ignored_folder/file.txt")]
305+
public void CanStageIgnoredPaths(string path)
306+
{
307+
using (var repo = new Repository(CloneStandardTestRepo()))
308+
{
309+
Touch(repo.Info.WorkingDirectory, ".gitignore", "ignored_file.txt\nignored_folder/\n");
310+
Touch(repo.Info.WorkingDirectory, path, "This file is ignored.");
311+
312+
Assert.Equal(FileStatus.Ignored, repo.Index.RetrieveStatus(path));
313+
repo.Index.Stage(path);
314+
Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(path));
315+
}
316+
}
301317
}
302318
}

LibGit2Sharp/Core/GitDiff.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ internal enum GitDiffOptionFlags
111111
/// Ignore file mode changes.
112112
/// </summary>
113113
GIT_DIFF_IGNORE_FILEMODE = (1 << 17),
114+
115+
/// <summary>
116+
/// Even with GIT_DIFF_INCLUDE_IGNORED, an entire ignored directory
117+
/// will be marked with only a single entry in the diff list; this flag
118+
/// adds all files under the directory as IGNORED entries, too.
119+
/// </summary>
120+
GIT_DIFF_RECURSE_IGNORED_DIRS = (1 << 18),
114121
}
115122

116123
internal delegate int diff_notify_cb(

LibGit2Sharp/Diff.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ private static GitDiffOptions BuildOptions(DiffModifiers diffOptions, FilePath[]
3838

3939
if (diffOptions.HasFlag(DiffModifiers.IncludeIgnored))
4040
{
41-
options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_IGNORED;
41+
options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_IGNORED |
42+
GitDiffOptionFlags.GIT_DIFF_RECURSE_IGNORED_DIRS;
4243
}
4344

4445
if (diffOptions.HasFlag(DiffModifiers.IncludeUnmodified))

0 commit comments

Comments
 (0)
0