Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LibGit2Sharp.Tests/StageFixture.cs24
-rw-r--r--LibGit2Sharp.Tests/UnstageFixture.cs2
-rw-r--r--LibGit2Sharp/Index.cs46
-rw-r--r--LibGit2Sharp/LibGit2Sharp.csproj3
-rw-r--r--LibGit2Sharp/StageOptions.cs22
5 files changed, 87 insertions, 10 deletions
diff --git a/LibGit2Sharp.Tests/StageFixture.cs b/LibGit2Sharp.Tests/StageFixture.cs
index 5499f578..3355645f 100644
--- a/LibGit2Sharp.Tests/StageFixture.cs
+++ b/LibGit2Sharp.Tests/StageFixture.cs
@@ -67,7 +67,7 @@ namespace LibGit2Sharp.Tests
Assert.Null(repo.Index[relativePath]);
Assert.Equal(status, repo.Index.RetrieveStatus(relativePath));
- Assert.Throws<UnmatchedPathException>(() => repo.Index.Stage(relativePath, new ExplicitPathsOptions()));
+ Assert.Throws<UnmatchedPathException>(() => repo.Index.Stage(relativePath, new StageOptions { ExplicitPathsOptions = new ExplicitPathsOptions() }));
}
}
@@ -82,7 +82,7 @@ namespace LibGit2Sharp.Tests
Assert.Equal(status, repo.Index.RetrieveStatus(relativePath));
Assert.DoesNotThrow(() => repo.Index.Stage(relativePath));
- Assert.DoesNotThrow(() => repo.Index.Stage(relativePath, new ExplicitPathsOptions { ShouldFailOnUnmatchedPath = false }));
+ Assert.DoesNotThrow(() => repo.Index.Stage(relativePath, new StageOptions { ExplicitPathsOptions = new ExplicitPathsOptions { ShouldFailOnUnmatchedPath = false } }));
Assert.Equal(status, repo.Index.RetrieveStatus(relativePath));
}
@@ -99,7 +99,7 @@ namespace LibGit2Sharp.Tests
Assert.Equal(status, repo.Index.RetrieveStatus(relativePath));
repo.Index.Stage(relativePath);
- repo.Index.Stage(relativePath, new ExplicitPathsOptions { ShouldFailOnUnmatchedPath = false });
+ repo.Index.Stage(relativePath, new StageOptions { ExplicitPathsOptions = new ExplicitPathsOptions { ShouldFailOnUnmatchedPath = false } });
}
}
@@ -302,6 +302,22 @@ namespace LibGit2Sharp.Tests
[Theory]
[InlineData("ignored_file.txt")]
[InlineData("ignored_folder/file.txt")]
+ public void CanIgnoreIgnoredPaths(string path)
+ {
+ using (var repo = new Repository(CloneStandardTestRepo()))
+ {
+ Touch(repo.Info.WorkingDirectory, ".gitignore", "ignored_file.txt\nignored_folder/\n");
+ Touch(repo.Info.WorkingDirectory, path, "This file is ignored.");
+
+ Assert.Equal(FileStatus.Ignored, repo.Index.RetrieveStatus(path));
+ repo.Index.Stage("*");
+ Assert.Equal(FileStatus.Ignored, repo.Index.RetrieveStatus(path));
+ }
+ }
+
+ [Theory]
+ [InlineData("ignored_file.txt")]
+ [InlineData("ignored_folder/file.txt")]
public void CanStageIgnoredPaths(string path)
{
using (var repo = new Repository(CloneStandardTestRepo()))
@@ -310,7 +326,7 @@ namespace LibGit2Sharp.Tests
Touch(repo.Info.WorkingDirectory, path, "This file is ignored.");
Assert.Equal(FileStatus.Ignored, repo.Index.RetrieveStatus(path));
- repo.Index.Stage(path);
+ repo.Index.Stage(path, new StageOptions { IncludeIgnored = true });
Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(path));
}
}
diff --git a/LibGit2Sharp.Tests/UnstageFixture.cs b/LibGit2Sharp.Tests/UnstageFixture.cs
index 47562a6f..d5878442 100644
--- a/LibGit2Sharp.Tests/UnstageFixture.cs
+++ b/LibGit2Sharp.Tests/UnstageFixture.cs
@@ -50,7 +50,7 @@ namespace LibGit2Sharp.Tests
Assert.Equal(FileStatus.Ignored, repo.Index.RetrieveStatus(relativePath));
- repo.Index.Stage(relativePath);
+ repo.Index.Stage(relativePath, new StageOptions { IncludeIgnored = true });
Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(relativePath));
repo.Index.Unstage(relativePath);
diff --git a/LibGit2Sharp/Index.cs b/LibGit2Sharp/Index.cs
index ee5e0297..f7e26318 100644
--- a/LibGit2Sharp/Index.cs
+++ b/LibGit2Sharp/Index.cs
@@ -129,32 +129,70 @@ namespace LibGit2Sharp
/// <summary>
/// Promotes to the staging area the latest modifications of a file in the working directory (addition, updation or removal).
+ ///
+ /// If this path is ignored by configuration then it will not be staged.
/// </summary>
/// <param name="path">The path of the file within the working directory.</param>
/// <param name="explicitPathsOptions">
/// If set, the passed <paramref name="path"/> will be treated as explicit paths.
/// Use these options to determine how unmatched explicit paths should be handled.
/// </param>
- public virtual void Stage(string path, ExplicitPathsOptions explicitPathsOptions = null)
+ [Obsolete("This will be removed in a future release. Supply ExplicitPathsOptions to StageOptions.")]
+ public virtual void Stage(string path, ExplicitPathsOptions explicitPathsOptions)
+ {
+ Stage(path, new StageOptions { ExplicitPathsOptions = explicitPathsOptions });
+ }
+
+ /// <summary>
+ /// Promotes to the staging area the latest modifications of a file in the working directory (addition, updation or removal).
+ ///
+ /// If this path is ignored by configuration then it will not be staged unless <see cref="StageOptions.IncludeIgnored"/> is unset.
+ /// </summary>
+ /// <param name="path">The path of the file within the working directory.</param>
+ /// <param name="stageOptions">If set, determines how paths will be staged.</param>
+ public virtual void Stage(string path, StageOptions stageOptions = null)
{
Ensure.ArgumentNotNull(path, "path");
- Stage(new[] { path }, explicitPathsOptions);
+ Stage(new[] { path }, stageOptions);
}
/// <summary>
/// Promotes to the staging area the latest modifications of a collection of files in the working directory (addition, updation or removal).
+ ///
+ /// Any paths (even those listed explicitly) that are ignored by configuration will not be staged.
/// </summary>
/// <param name="paths">The collection of paths of the files within the working directory.</param>
/// <param name="explicitPathsOptions">
/// If set, the passed <paramref name="paths"/> will be treated as explicit paths.
/// Use these options to determine how unmatched explicit paths should be handled.
/// </param>
- public virtual void Stage(IEnumerable<string> paths, ExplicitPathsOptions explicitPathsOptions = null)
+ [Obsolete("This will be removed in a future release. Supply ExplicitPathsOptions to StageOptions.")]
+ public virtual void Stage(IEnumerable<string> paths, ExplicitPathsOptions explicitPathsOptions)
+ {
+ Stage(paths, new StageOptions { ExplicitPathsOptions = explicitPathsOptions });
+ }
+
+ /// <summary>
+ /// Promotes to the staging area the latest modifications of a collection of files in the working directory (addition, updation or removal).
+ ///
+ /// Any paths (even those listed explicitly) that are ignored by configuration will not be staged unless <see cref="StageOptions.IncludeIgnored"/> is unset.
+ /// </summary>
+ /// <param name="paths">The collection of paths of the files within the working directory.</param>
+ /// <param name="stageOptions">If set, determines how paths will be staged.</param>
+ public virtual void Stage(IEnumerable<string> paths, StageOptions stageOptions = null)
{
Ensure.ArgumentNotNull(paths, "paths");
- var changes = repo.Diff.Compare<TreeChanges>(DiffModifiers.IncludeUntracked | DiffModifiers.IncludeIgnored, paths, explicitPathsOptions);
+ DiffModifiers diffModifiers = DiffModifiers.IncludeUntracked;
+ ExplicitPathsOptions explicitPathsOptions = stageOptions != null ? stageOptions.ExplicitPathsOptions : null;
+
+ if (stageOptions != null && stageOptions.IncludeIgnored)
+ {
+ diffModifiers |= DiffModifiers.IncludeIgnored;
+ }
+
+ var changes = repo.Diff.Compare<TreeChanges>(diffModifiers, paths, explicitPathsOptions);
foreach (var treeEntryChanges in changes)
{
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 8ed8c54c..d8814ab9 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -132,6 +132,7 @@
<Compile Include="RevertResult.cs" />
<Compile Include="SignatureExtensions.cs" />
<Compile Include="RevertOptions.cs" />
+ <Compile Include="StageOptions.cs" />
<Compile Include="StatusOptions.cs" />
<Compile Include="SimilarityOptions.cs" />
<Compile Include="UnbornBranchException.cs" />
@@ -351,4 +352,4 @@
</CreateItem>
<Copy SourceFiles="@(NativeBinaries)" DestinationFiles="@(NativeBinaries->'$(OutputPath)NativeBinaries\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>
-</Project>
+</Project> \ No newline at end of file
diff --git a/LibGit2Sharp/StageOptions.cs b/LibGit2Sharp/StageOptions.cs
new file mode 100644
index 00000000..7701b894
--- /dev/null
+++ b/LibGit2Sharp/StageOptions.cs
@@ -0,0 +1,22 @@
+using System;
+
+namespace LibGit2Sharp
+{
+ /// <summary>
+ /// Options to define file staging behavior.
+ /// </summary>
+ public sealed class StageOptions
+ {
+ /// <summary>
+ /// Stage ignored files. (Default = false)
+ /// </summary>
+ public bool IncludeIgnored { get; set; }
+
+ /// <summary>
+ /// If set, the passed paths will be treated as explicit paths.
+ /// Use these options to determine how unmatched explicit paths
+ /// should be handled. (Default = null)
+ /// </summary>
+ public ExplicitPathsOptions ExplicitPathsOptions { get; set; }
+ }
+}