8000 Merge pull request #1124 from libgit2/ntk/upgrade · odedw/libgit2sharp@37bdb63 · GitHub
[go: up one dir, main page]

Skip to content

Commit 37bdb63

Browse files
committed
Merge pull request libgit2#1124 from libgit2/ntk/upgrade
Upgrade to latest libgit2
8000
2 parents 126351e + 1a12ea6 commit 37bdb63

13 files changed

+176
-93
lines changed

LibGit2Sharp.Tests/FilterFixture.cs

Lines changed: 99 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,14 @@ public void InitCallbackNotMadeWhenFilterNeverUsed()
6969
initializeCallback);
7070
var registration = GlobalSettings.RegisterFilter(filter);
7171

72-
Assert.False(called);
73-
74-
GlobalSettings.DeregisterFilter(registration);
72+
try
73+
{
74+
Assert.False(called);
75+
}
76+
finally
77+
{
78+
GlobalSettings.DeregisterFilter(registration);
79+
}
7580
}
7681

7782
[Fact]
@@ -89,16 +94,22 @@ public void InitCallbackMadeWhenUsingTheFilter()
8994
successCallback,
9095
initializeCallback);
9196
var registration = GlobalSettings.RegisterFilter(filter);
92-
Assert.False(called);
9397

94-
string repoPath = InitNewRepository();
95-
using (var repo = CreateTestRepository(repoPath))
98+
try
9699
{
97-
StageNewFile(repo);
98-
Assert.True(called);
99-
}
100+
Assert.False(called);
100101

101-
GlobalSettings.DeregisterFilter(registration);
102+
string repoPath = InitNewRepository();
103+
using (var repo = CreateTestRepository(repoPath))
104+
{
105+
StageNewFile(repo);
106+
Assert.True(called);
107+
}
108+
}
109+
finally
110+
{
111+
GlobalSettings.DeregisterFilter(registration);
112+
}
102113
}
103114

104115
[Fact]
@@ -116,13 +127,18 @@ public void WhenStagingFileApplyIsCalledWithCleanForCorrectPath()
116127
var filter = new FakeFilter(FilterName, attributes, clean);
117128
var registration = GlobalSettings.RegisterFilter(filter);
118129

119-
using (var repo = CreateTestRepository(repoPath))
130+
try
120131
{
121-
StageNewFile(repo);
122-
Assert.True(called);
132+
using (var repo = CreateTestRepository(repoPath))
133+
{
134+
StageNewFile(repo);
135+
Assert.True(called);
136+
}
137+
}
138+
finally
139+
{
140+
GlobalSettings.DeregisterFilter(registration);
123141
}
124-
125-
GlobalSettings.DeregisterFilter(registration);
126142
}
127143

128144
[Fact]
@@ -138,17 +154,22 @@ public void CleanFilterWritesOutputToObjectTree()
138154
var filter = new FakeFilter(FilterName, attributes, cleanCallback);
139155
var registration = GlobalSettings.RegisterFilter(filter);
140156

141-
using (var repo = CreateTestRepository(repoPath))
157+
try
142158
{
143-
FileInfo expectedFile = StageNewFile(repo, decodedInput);
144-
var commit = repo.Commit("Clean that file");
145-
var blob = (Blob)commit.Tree[expectedFile.Name].Target;
159+
using (var repo = CreateTestRepository(repoPath))
160+
{
161+
FileInfo expectedFile = StageNewFile(repo, decodedInput);
162+
var commit = repo.Commit("Clean that file");
163+
var blob = (Blob)commit.Tree[expectedFile.Name].Target;
146164

147-
var textDetected = blob.GetContentText();
148-
Assert.Equal(encodedInput, textDetected);
165+
var textDetected = blob.GetContentText();
166+
Assert.Equal(encodedInput, textDetected);
167+
}
168+
}
169+
finally
170+
{
171+
GlobalSettings.DeregisterFilter(registration);
149172
}
150-
151-
GlobalSettings.DeregisterFilter(registration);
152173
}
153174

154175
[Fact]
@@ -165,19 +186,24 @@ public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory()
165186
var filter = new FakeFilter(FilterName, attributes, null, smudgeCallback);
166187
var registration = GlobalSettings.RegisterFilter(filter);
167188

168-
FileInfo expectedFile = CheckoutFileForSmudge(repoPath, branchName, encodedInput);
169-
170-
string combine = Path.Combine(repoPath, "..", expectedFile.Name);
171-
string readAllText = File.ReadAllText(combine);
172-
Assert.Equal(decodedInput, readAllText);
189+
try
190+
{
191+
FileInfo expectedFile = CheckoutFileForSmudge(repoPath, branchName, encodedInput);
173192

174-
GlobalSettings.DeregisterFilter(registration);
193+
string combine = Path.Combine(repoPath, "..", expectedFile.Name);
194+
string readAllText = File.ReadAllText(combine);
195+
Assert.Equal(decodedInput, readAllText);
196+
}
197+
finally
198+
{
199+
GlobalSettings.DeregisterFilter(registration);
200+
}
175201
}
176202

177203
[Fact]
178204
public void CanFilterLargeFiles()
179205
{
180-
const int ContentLength = 128 * 1024 * 1024;
206+
const int ContentLength = 128 * 1024 * 1024 - 13;
181207
const char ContentValue = 'x';
182208

183209
char[] content = (new string(ContentValue, 1024)).ToCharArray();
@@ -187,51 +213,60 @@ public void CanFilterLargeFiles()
187213
var filter = new FileExportFilter(FilterName, attributes);
188214
var registration = GlobalSettings.RegisterFilter(filter);
189215

190-
string filePath = Path.Combine(Directory.GetParent(repoPath).Parent.FullName, Guid.NewGuid().ToString() + ".blob");
191-
FileInfo contentFile = new FileInfo(filePath);
192-
using (var writer = new StreamWriter(contentFile.OpenWrite()) { AutoFlush = true })
216+
try
193217
{
194-
for (int i = 0; i < ContentLength / content.Length; i++)
218+
string filePath = Path.Combine(Directory.GetParent(repoPath).Parent.FullName, Guid.NewGuid().ToString() + ".blob");
219+
FileInfo contentFile = new FileInfo(filePath);
220+
using (var writer = new StreamWriter(contentFile.OpenWrite()) { AutoFlush = true })
195221
{
196-
writer.Write(content);
197-
}
198-
}
222+
int remain = ContentLength;
199223

200-
string attributesPath = Path.Combine(Directory.GetParent(repoPath).Parent.FullName, ".gitattributes");
201-
FileInfo attributesFile = new FileInfo(attributesPath);
224+
while (remain > 0)
225+
{
226+
int chunkSize = remain > content.Length ? content.Length : remain;
227+
writer.Write(content, 0, chunkSize);
228+
remain -= chunkSize;
229+
}
230+
}
202231

203-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
204-
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
232+
string attributesPath = Path.Combine(Directory.GetParent(repoPath).Parent.FullName, ".gitattributes");
233+
FileInfo attributesFile = new FileInfo(attributesPath);
205234

206-
using (Repository repo = new Repository(repoPath, repositoryOptions))
207-
{
208-
File.WriteAllText(attributesPath, "*.blob filter=test");
209-
repo.Stage(attributesFile.Name);
210-
repo.Stage(contentFile.Name);
211-
repo.Commit("test");
212-
contentFile.Delete();
213-
repo.Checkout("HEAD", new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
214-
}
235+
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
236+
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
215237

216-
contentFile = new FileInfo(filePath);
217-
Assert.True(contentFile.Exists, "Contents not restored correctly by forced checkout.");
218-
using (StreamReader reader = contentFile.OpenText())
219-
{
220-
int totalRead = 0;
221-
char[] block = new char[1024];
222-
int read;
223-
while ((read = reader.Read(block, 0, block.Length)) > 0)
238+
using (Repository repo = new Repository(repoPath, repositoryOptions))
224239
{
225-
Assert.True(CharArrayAreEqual(block, content, read));
226-
totalRead += read;
240+
File.WriteAllText(attributesPath, "*.blob filter=test");
241+
repo.Stage(attributesFile.Name);
242+
repo.Stage(contentFile.Name);
243+
repo.Commit("test");
244+
contentFile.Delete();
245+
repo.Checkout("HEAD", new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
227246
}
228247

229-
Assert.Equal(ContentLength, totalRead);
230-
}
248+
contentFile = new FileInfo(filePath);
249+
Assert.True(contentFile.Exists, "Contents not restored correctly by forced checkout.");
250+
using (StreamReader reader = contentFile.OpenText())
251+
{
252+
int totalRead = 0;
253+
char[] block = new char[1024];
254+
int read;
255+
while ((read = reader.Read(block, 0, block.Length)) > 0)
256+
{
257+
Assert.True(CharArrayAreEqual(block, content, read));
258+
totalRead += read;
259+
}
231260

232-
contentFile.Delete();
261+
Assert.Equal(ContentLength, totalRead);
262+
}
233263

234-
GlobalSettings.DeregisterFilter(registration);
264+
contentFile.Delete();
265+
}
266+
finally
267+
{
268+
GlobalSettings.DeregisterFilter(registration);
269+
}
235270
}
236271

237272
[Fact]

LibGit2Sharp.Tests/StashFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public void CanStashAndApplyWithOptions()
219219
repo.Stashes.< 10000 /span>Add(stasher, "This stash with default options");
220220
Assert.Equal(StashApplyStatus.Applied, repo.Stashes.Apply(0));
221221

222-
Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(filename));
222+
Assert.Equal(FileStatus.NewInIndex, repo.RetrieveStatus(filename));
223223
Assert.Equal(1, repo.Stashes.Count());
224224

225225
repo.Stage(filename);
@@ -258,13 +258,13 @@ public void CanStashAndPop()
258258
Assert.Equal(StashApplyStatus.Applied, repo.Stashes.Pop(0));
259259
Assert.Equal(0, repo.Stashes.Count());
260260

261-
Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(filename));
261+
Assert.Equal(FileStatus.NewInIndex, repo.RetrieveStatus(filename));
262262
Assert.Equal(contents, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, filename)));
263263
}
264264
}
265265

266266
[Fact]
267-
public void StashReportsConflictsWhenReinstated()
267+
public void StashFailsWithUncommittedChangesIntheIndex()
268268
{
269269
string path = SandboxStandardTestRepo();
270270
using (var repo = new Repository(path))
@@ -286,7 +286,7 @@ public void StashReportsConflictsWhenReinstated()
286286
repo.Stage(filename);
287287
Touch(repo.Info.WorkingDirectory, filename2, newContents);
288288

289-
Assert.Equal(StashApplyStatus.Conflicts, repo.Stashes.Pop(0, new StashApplyOptions
289+
Assert.Equal(StashApplyStatus.UncommittedChanges, repo.Stashes.Pop(0, new StashApplyOptions
290290
{
291291
ApplyModifiers = StashApplyModifiers.ReinstateIndex,
292292
}));

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private static void SetUpTestEnvironment()
5656
{
5757
IsFileSystemCaseSensitive = IsFileSystemCaseSensitiveInternal();
5858

59-
string initialAssemblyParentFolder = Directory.GetParent(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath).FullName;
59+
string initialAssemblyParentFolder = Directory.GetParent(new Uri(typeof(BaseFixture).Assembly.EscapedCodeBase).LocalPath).FullName;
6060

6161
const string sourceRelativePath = @"../../Resources";
6262
ResourcesDirectory = new DirectoryInfo(Path.Combine(initialAssemblyParentFolder, sourceRelativePath));

LibGit2Sharp.Tests/TestHelpers/FileExportFilter.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ public FileExportFilter(string name, IEnumerable<FilterAttributeEntry> attribute
1919
FilesFiltered = new HashSet<string>();
2020
}
2121

22+
protected override void Create(string path, string root, FilterMode mode)
23+
{
24+
if (mode == FilterMode.Clean)
25+
{
26+
string filename = Path.GetFileName(path);
27+
string cachePath = Path.Combine(root, ".git", filename);
28+
29+
if (File.Exists(cachePath))
30+
{
31+
File.Delete(cachePath);
32+
}
33+
}
34+
}
35+
2236
protected override void Clean(string path, string root, Stream input, Stream output)
2337
{
2438
CleanCalledCount++;

LibGit2Sharp/Core/GitErrorCode.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ internal enum GitErrorCode
9191
/// </summary>
9292
Peel = -19,
9393

94+
/// <summary>
95+
/// Unexpected EOF.
96+
/// </summary>
97+
EndOfFile = -20,< BD94 /div>
98+
99+
/// <summary>
100+
/// Invalid operation or input.
101+
/// </summary>
102+
Invalid = -21,
103+
104+
/// <summary>
105+
/// Uncommitted changes in index prevented operation.
106+
/// </summary>
107+
Uncommitted = -22,
108+
94109
/// <summary>
95110
/// Skip and passthrough the given ODB backend.
96111
/// </summary>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace LibGit2Sharp.Core
2+
{
3+
internal enum GitSubmoduleIgnore
4+
{
5+
Unspecified = -1,
6+
None = 1,
7+
Untracked = 2,
8+
Dirty = 3,
9+
All = 4,
10+
}
11+
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 3 additions & 5 deletions
< 4E34 div class="border position-relative rounded-bottom-2">
Original file line numberDiff line numberDiff line change
@@ -1526,10 +1526,6 @@ internal static extern int git_submodule_add_to_index(
15261526
SubmoduleSafeHandle submodule,
15271527
[MarshalAs(UnmanagedType.Bool)] bool write_index);
15281528

1529-
[DllImport(libgit2)]
1530-
internal static extern int git_submodule_save(
1531-
SubmoduleSafeHandle submodule);
1532-
15331529
[DllImport(libgit2)]
15341530
internal static extern void git_submodule_free(
15351531
IntPtr submodule);
@@ -1576,7 +1572,9 @@ internal static extern int git_submodule_reload(
15761572
[DllImport(libgit2)]
15771573
internal static extern int git_submodule_status(
15781574
out SubmoduleStatus status,
1579-
SubmoduleSafeHandle submodule);
1575+
RepositorySafeHandle repo,
1576+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath name,
1577+
GitSubmoduleIgnore ignore);
15801578

15811579
[DllImport(libgit2)]
15821580
internal static extern int git_submodule_init(

LibGit2Sharp/Core/Proxy.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,6 +2679,11 @@ private static StashApplyStatus get_stash_status(int res)
26792679
return StashApplyStatus.Conflicts;
26802680
}
26812681

2682+
if (res == (int)GitErrorCode.Uncommitted)
2683+
{
2684+
return StashApplyStatus.UncommittedChanges;
2685+
}
2686+
26822687
if (res == (int)GitErrorCode.NotFound)
26832688
{
26842689
return StashApplyStatus.NotFound;
@@ -2805,12 +2810,6 @@ public static void git_submodule_add_to_index(SubmoduleSafeHandle submodule, boo
28052810
Ensure.ZeroResult(res);
28062811
}
28072812

2808-
public static void git_submodule_save(SubmoduleSafeHandle submodule)
2809-
{
2810-
var res = NativeMethods.git_submodule_save(submodule);
2811-
Ensure.ZeroResult(res);
2812-
}
2813-
28142813
public static void git_submodule_update(SubmoduleSafeHandle submodule, bool init, ref GitSubmoduleOptions options)
28152814
{
28162815
var res = NativeMethods.git_submodule_update(submodule, init, ref options);
@@ -2868,10 +2867,10 @@ public static void git_submodule_reload(SubmoduleSafeHandle submodule)
28682867
Ensure.ZeroResult(res);
28692868
}
28702869

2871-
public static SubmoduleStatus git_submodule_status(SubmoduleSafeHandle submodule)
2870+
public static SubmoduleStatus git_submodule_status(RepositorySafeHandle repo, string name)
28722871
{
28732872
SubmoduleStatus status;
2874-
var res = NativeMethods.git_submodule_status(out status, submodule);
2873+
var res = NativeMethods.git_submodule_status(out status, repo, name, GitSubmoduleIgnore.Unspecified);
28752874
Ensure.ZeroResult(res);
28762875
return status;
28772876
}

0 commit comments

Comments
 (0)
0