Skip to content

Commit 2ad2c39

Browse files
committed
Move Push related tests to a separate file
1 parent c742c00 commit 2ad2c39

File tree

3 files changed

+56
-45
lines changed

3 files changed

+56
-45
lines changed

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,51 +50,6 @@ private void AssertLocalClone(string path)
5050
}
5151
}
5252

53-
[Fact]
54-
public void CanLocallyCloneAndCommitAndPush()
55-
{
56-
var scd = BuildSelfCleaningDirectory();
57-
using (var originalRepo = new Repository(CloneBareTestRepo()))
58-
using (Repository clonedRepo = Repository.Clone(originalRepo.Info.Path, scd.RootedDirectoryPath))
59-
{
60-
Remote remote = clonedRepo.Network.Remotes["origin"];
61-
62-
// Compare before
63-
Assert.Equal(originalRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier,
64-
clonedRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier);
65-
Assert.Equal(clonedRepo.Network.ListReferences(remote).Single(r => r.CanonicalName == "refs/heads/master"),
66-
clonedRepo.Refs.Head.ResolveToDirectReference());
67-
68-
// Change local state (commit)
69-
const string relativeFilepath = "new_file.txt";
70-
string filePath = Path.Combine(clonedRepo.Info.WorkingDirectory, relativeFilepath);
71-
File.WriteAllText(filePath, "__content__");
72-
clonedRepo.Index.Stage(relativeFilepath);
73-
clonedRepo.Commit("__commit_message__", DummySignature, DummySignature);
74-
75-
// Assert local state has changed
76-
Assert.NotEqual(originalRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier,
77-
clonedRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier);
78-
Assert.NotEqual(clonedRepo.Network.ListReferences(remote).Single(r => r.CanonicalName == "refs/heads/master"),
79-
clonedRepo.Refs.Head.ResolveToDirectReference());
80-
81-
// Push the change upstream (remote state is supposed to change)
82-
clonedRepo.Network.Push(remote, "HEAD", @"refs/heads/master", OnPushStatusError);
83-
84-
// Assert that both local and remote repos are in sync
85-
Assert.Equal(originalRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier,
86-
clonedRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier);
87-
Assert.Equal(clonedRepo.Network.ListReferences(remote).Single(r => r.CanonicalName == "refs/heads/master"),
88-
clonedRepo.Refs.Head.ResolveToDirectReference());
89-
}
90-
}
91-
92-
private void OnPushStatusError(PushStatusError pushStatusErrors)
93-
{
94-
Assert.True(false, string.Format("Failed to update reference '{0}': {1}",
95-
pushStatusErrors.Reference, pushStatusErrors.Message));
96-
}
97-
9853
[Fact]
9954
public void CanCloneALocalRepositoryFromALocalUri()
10055
{

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<ItemGroup>
6161
<Compile Include="CheckoutFixture.cs" />
6262
<Compile Include="RemoteFixture.cs" />
63+
<Compile Include="PushFixture.cs" />
6364
<Compile Include="StageFixture.cs" />
6465
<Compile Include="StashFixture.cs" />
6566
<Compile Include="CloneFixture.cs" />

LibGit2Sharp.Tests/PushFixture.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.IO;
2+
using System.Linq;
3+
using LibGit2Sharp.Tests.TestHelpers;
4+
using Xunit;
5+
6+
namespace LibGit2Sharp.Tests
7+
{
8+
public class PushFixture : BaseFixture
9+
{
10+
private void OnPushStatusError(PushStatusError pushStatusErrors)
11+
{
12+
Assert.True(false, string.Format("Failed to update reference '{0}': {1}",
13+
pushStatusErrors.Reference, pushStatusErrors.Message));
14+
}
15+
16+
[Fact]
17+
public void CanLocallyCloneAndCommitAndPush()
18+
{
19+
var scd = BuildSelfCleaningDirectory();
20+
using (var originalRepo = new Repository(CloneBareTestRepo()))
21+
using (Repository clonedRepo = Repository.Clone(originalRepo.Info.Path, scd.RootedDirectoryPath))
22+
{
23+
Remote remote = clonedRepo.Network.Remotes["origin"];
24+
25+
// Compare before
26+
Assert.Equal(originalRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier,
27+
clonedRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier);
28+
Assert.Equal(clonedRepo.Network.ListReferences(remote).Single(r => r.CanonicalName == "refs/heads/master"),
29+
clonedRepo.Refs.Head.ResolveToDirectReference());
30+
31+
// Change local state (commit)
32+
const string relativeFilepath = "new_file.txt";
33+
string filePath = Path.Combine(clonedRepo.Info.WorkingDirectory, relativeFilepath);
34+
File.WriteAllText(filePath, "__content__");
35+
clonedRepo.Index.Stage(relativeFilepath);
36+
clonedRepo.Commit("__commit_message__", DummySignature, DummySignature);
37+
38+
// Assert local state has changed
39+
Assert.NotEqual(originalRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier,
40+
clonedRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier);
41+
Assert.NotEqual(clonedRepo.Network.ListReferences(remote).Single(r => r.CanonicalName == "refs/heads/master"),
42+
clonedRepo.Refs.Head.ResolveToDirectReference());
43+
44+
// Push the change upstream (remote state is supposed to change)
45+
clonedRepo.Network.Push(remote, "HEAD", @"refs/heads/master", OnPushStatusError);
46+
47+
// Assert that both local and remote repos are in sync
48+
Assert.Equal(originalRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier,
49+
clonedRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier);
50+
Assert.Equal(clonedRepo.Network.ListReferences(remote).Single(r => r.CanonicalName == "refs/heads/master"),
51+
clonedRepo.Refs.Head.ResolveToDirectReference());
52+
}
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)