Skip to content

Commit 0332c35

Browse files
committed
Merge pull request #260 from ben/great-renaming
The Great Libgit2 Renaming of 2012
2 parents ceef2f7 + ed8c978 commit 0332c35

38 files changed

+506
-190
lines changed

Lib/NativeBinaries/amd64/git2.dll

32.5 KB
Binary file not shown.

Lib/NativeBinaries/amd64/git2.pdb

696 KB
Binary file not shown.

Lib/NativeBinaries/x86/git2.dll

23.5 KB
Binary file not shown.

Lib/NativeBinaries/x86/git2.pdb

224 KB
Binary file not shown.

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public void CanCheckoutAnExistingBranch(string branchName)
2323
Branch master = repo.Branches["master"];
2424
Assert.True(master.IsCurrentRepositoryHead);
2525

26-
// Hard reset to ensure that working directory, index, and HEAD match
27-
repo.Reset(ResetOptions.Hard);
26+
// Set the working directory to the current head
27+
ResetAndCleanWorkingDirectory(repo);
28+
2829
Assert.False(repo.Index.RetrieveStatus().IsDirty);
2930

3031
Branch branch = repo.Branches[branchName];
@@ -55,8 +56,9 @@ public void CanCheckoutAnExistingBranchByName(string branchName)
5556
Branch master = repo.Branches["master"];
5657
Assert.True(master.IsCurrentRepositoryHead);
5758

58-
// Hard reset to ensure that working directory, index, and HEAD match
59-
repo.Reset(ResetOptions.Hard);
59+
// Set the working directory to the current head
60+
ResetAndCleanWorkingDirectory(repo);
61+
6062
Assert.False(repo.Index.RetrieveStatus().IsDirty);
6163

6264
Branch test = repo.Checkout(branchName);
@@ -84,8 +86,9 @@ public void CanCheckoutAnArbitraryCommit(string commitPointer)
8486
Branch master = repo.Branches["master"];
8587
Assert.True(master.IsCurrentRepositoryHead);
8688

87-
// Hard reset to ensure that working directory, index, and HEAD match
88-
repo.Reset(ResetOptions.Hard);
89+
// Set the working directory to the current head
90+
ResetAndCleanWorkingDirectory(repo);
91+
8992
Assert.False(repo.Index.RetrieveStatus().IsDirty);
9093

9194
Branch detachedHead = repo.Checkout(commitPointer);
@@ -197,8 +200,9 @@ public void CanForcefullyCheckoutWithStagedChanges()
197200
Branch master = repo.Branches["master"];
198201
Assert.True(master.IsCurrentRepositoryHead);
199202

200-
// Hard reset to ensure that working directory, index, and HEAD match
201-
repo.Reset(ResetOptions.Hard);
203+
// Set the working directory to the current head
204+
ResetAndCleanWorkingDirectory(repo);
205+
202206
Assert.False(repo.Index.RetrieveStatus().IsDirty);
203207

204208
// Add local change
@@ -335,5 +339,19 @@ private void PopulateBasicRepository(Repository repo)
335339

336340
repo.CreateBranch(otherBranchName);
337341
}
342+
343+
/// <summary>
344+
/// Reset and clean current working directory. This will ensure that the current
345+
/// working directory matches the current Head commit.
346+
/// </summary>
347+
/// <param name="repo">Repository whose current working directory should be operated on.</param>
348+
private void ResetAndCleanWorkingDirectory(Repository repo)
349+
{
350+
// Reset the index and the working tree.
351+
repo.Reset(ResetOptions.Hard);
352+
353+
// Clean the working directory.
354+
repo.RemoveUntrackedFiles();
355+
}
338356
}
339357
}

LibGit2Sharp.Tests/CleanFixture.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Linq;
2+
using LibGit2Sharp.Tests.TestHelpers;
3+
using Xunit;
4+
5+
namespace LibGit2Sharp.Tests
6+
{
7+
public class CleanFixture : BaseFixture
8+
{
9+
[Fact]
10+
public void CanCleanWorkingDirectory()
11+
{
12+
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
13+
using (var repo = new Repository(path.RepositoryPath))
14+
{
15+
// Verify that there are the expected number of entries and untracked files
16+
Assert.Equal(6, repo.Index.RetrieveStatus().Count());
17+
Assert.Equal(1, repo.Index.RetrieveStatus().Untracked.Count());
18+
19+
repo.RemoveUntrackedFiles();
20+
21+
// Verify that there are the expected number of entries and 0 untracked files
22+
Assert.Equal(5, repo.Index.RetrieveStatus().Count());
23+
Assert.Equal(0, repo.Index.RetrieveStatus().Untracked.Count());
24+
}
25+
}
26+
27+
[Fact]
28+
public void CannotCleanABareRepository()
29+
{
30+
using (var repo = new Repository(BareTestRepoPath))
31+
{
32+
Assert.Throws<BareRepositoryException>(() => repo.RemoveUntrackedFiles());
33+
}
34+
}
35+
}
36+
}

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public void CanCorrectlyCountCommitsWhenSwitchingToAnotherBranch()
2828
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
2929
using (var repo = new Repository(path.RepositoryPath))
3030
{
31+
// Hard reset and then remove untracked files
3132
repo.Reset(ResetOptions.Hard);
33+
repo.RemoveUntrackedFiles();
3234

3335
repo.Checkout("test");
3436
Assert.Equal(2, repo.Commits.Count());
@@ -227,7 +229,9 @@ public void CanEnumerateFromDetachedHead()
227229
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
228230
using (var repoClone = new Repository(path.RepositoryPath))
229231
{
232+
// Hard reset and then remove untracked files
230233
repoClone.Reset(ResetOptions.Hard);
234+
repoClone.RemoveUntrackedFiles();
231235

232236
string headSha = repoClone.Head.Tip.Sha;
233237
repoClone.Checkout(headSha);

LibGit2Sharp.Tests/ConfigurationFixture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public void CanUnsetAnEntryFromTheGlobalConfiguration()
7777
.AppendFormat("Man-I-am-totally-global = 42{0}", Environment.NewLine);
7878

7979
File.WriteAllText(globalLocation, sb.ToString());
80+
File.WriteAllText(systemLocation, string.Empty);
8081

8182
var options = new RepositoryOptions
8283
{

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
</ItemGroup>
5959
<ItemGroup>
6060
<Compile Include="CheckoutFixture.cs" />
61+
<Compile Include="CleanFixture.cs" />
6162
<Compile Include="MetaFixture.cs" />
6263
<Compile Include="MockedRepositoryFixture.cs" />
6364
<Compile Include="ConfigurationFixture.cs" />

LibGit2Sharp.Tests/RepositoryFixture.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,5 +537,17 @@ public void CallsProgressCallbacks()
537537
Assert.True(checkoutWasCalled);
538538
}
539539
}
540+
541+
[Fact]
542+
public void QueryingTheRemoteForADetachedHeadBranchReturnsNull()
543+
{
544+
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
545+
using (var repo = new Repository(path.DirectoryPath))
546+
{
547+
repo.Checkout(repo.Head.Tip.Sha, CheckoutOptions.Force, null);
548+
Branch trackLocal = repo.Head;
549+
Assert.Null(trackLocal.Remote);
550+
}
551+
}
540552
}
541553
}

LibGit2Sharp.Tests/RepositoryOptionsFixture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public void CanProvideDifferentConfigurationFilesToARepository()
157157
.AppendFormat("email = {0}{1}", email, Environment.NewLine);
158158

159159
File.WriteAllText(globalLocation, sb.ToString());
160+
File.WriteAllText(systemLocation, string.Empty);
160161

161162
var options = new RepositoryOptions {
162163
GlobalConfigurationLocation = globalLocation,

LibGit2Sharp.Tests/ResetHeadFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void HardResetInABareRepositoryThrows()
164164
}
165165
}
166166

167-
[Fact]
167+
[Fact(Skip = "Not working against current libgit2 version")]
168168
public void HardResetUpdatesTheContentOfTheWorkingDirectory()
169169
{
170170
var clone = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
@@ -175,7 +175,7 @@ public void HardResetUpdatesTheContentOfTheWorkingDirectory()
175175
names.Sort(StringComparer.Ordinal);
176176

177177
File.Delete(Path.Combine(repo.Info.WorkingDirectory, "README"));
178-
File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, "WillBeRemoved.txt"), "content\n");
178+
File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, "WillNotBeRemoved.txt"), "content\n");
179179

180180
Assert.True(names.Count > 4);
181181

@@ -184,7 +184,7 @@ public void HardResetUpdatesTheContentOfTheWorkingDirectory()
184184
names = new DirectoryInfo(repo.Info.WorkingDirectory).GetFileSystemInfos().Select(fsi => fsi.Name).ToList();
185185
names.Sort(StringComparer.Ordinal);
186186

187-
Assert.Equal(new[] { ".git", "README", "branch_file.txt", "new.txt" }, names);
187+
Assert.Equal(new[] { ".git", "README", "WillNotBeRemoved.txt", "branch_file.txt", "new.txt", "new_untracked_file.txt" }, names);
188188
}
189189
}
190190
}

LibGit2Sharp/Blob.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using LibGit2Sharp.Core;
34

45
namespace LibGit2Sharp
@@ -8,7 +9,7 @@ namespace LibGit2Sharp
89
/// </summary>
910
public class Blob : GitObject
1011
{
11-
private readonly ILazy<int> lazySize;
12+
private readonly ILazy<Int64> lazySize;
1213

1314
/// <summary>
1415
/// Needed for mocking purposes.
@@ -25,7 +26,7 @@ internal Blob(Repository repo, ObjectId id)
2526
/// <summary>
2627
/// Gets the size in bytes of the contents of a blob
2728
/// </summary>
28-
public virtual int Size { get { return lazySize.Value; } }
29+
public virtual int Size { get { return (int)lazySize.Value; } }
2930

3031
/// <summary>
3132
/// Gets the blob content in a <see cref="byte" /> array.

LibGit2Sharp/Branch.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ public virtual Remote Remote
170170
get
171171
{
172172
string remoteName = repo.Config.Get<string>("branch", Name, "remote", null);
173-
Remote remote = null;
174173

175-
if (!string.IsNullOrEmpty(remoteName))
174+
if (string.IsNullOrEmpty(remoteName) ||
175+
string.Equals(remoteName, ".", StringComparison.Ordinal))
176176
{
177-
remote = repo.Remotes[remoteName];
177+
return null;
178178
}
179179

180-
return remote;
180+
return repo.Remotes[remoteName];
181181
}
182182
}
183183

LibGit2Sharp/BranchCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public virtual Branch Add(string name, Commit commit, bool allowOverwrite = fals
120120
Ensure.ArgumentNotNullOrEmptyString(name, "name");
121121
Ensure.ArgumentNotNull(commit, "commit");
122122

123-
Proxy.git_branch_create(repo.Handle, name, commit.Id, allowOverwrite);
123+
using (Proxy.git_branch_create(repo.Handle, name, commit.Id, allowOverwrite)) {}
124124

125125
return this[ShortToLocalName(name)];
126126
}

LibGit2Sharp/ContentChanges.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal ContentChanges(Repository repo, Blob oldBlob, Blob newBlob, GitDiffOpti
2323
options, FileCallback, HunkCallback, LineCallback);
2424
}
2525

26-
private int FileCallback(IntPtr data, GitDiffDelta delta, float progress)
26+
private int FileCallback(GitDiffDelta delta, float progress, IntPtr payload)
2727
{
2828
IsBinaryComparison = delta.IsBinary();
2929

@@ -37,17 +37,17 @@ private int FileCallback(IntPtr data, GitDiffDelta delta, float progress)
3737
return 0;
3838
}
3939

40-
private int HunkCallback(IntPtr data, GitDiffDelta delta, GitDiffRange range, IntPtr header, uint headerlen)
40+
private int HunkCallback(GitDiffDelta delta, GitDiffRange range, IntPtr header, UIntPtr headerlen, IntPtr payload)
4141
{
42-
string decodedContent = Utf8Marshaler.FromNative(header, headerlen);
42+
string decodedContent = Utf8Marshaler.FromNative(header, (uint)headerlen);
4343

4444
AppendToPatch(decodedContent);
4545
return 0;
4646
}
4747

48-
private int LineCallback(IntPtr data, GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, uint contentlen)
48+
private int LineCallback(GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, UIntPtr contentlen, IntPtr payload)
4949
{
50-
string decodedContent = Utf8Marshaler.FromNative(content, contentlen);
50+
string decodedContent = Utf8Marshaler.FromNative(content, (uint)contentlen);
5151

5252
string prefix;
5353

0 commit comments

Comments
 (0)