forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFetchHeadFixture.cs
More file actions
134 lines (123 loc) · 5.25 KB
/
FetchHeadFixture.cs
File metadata and controls
134 lines (123 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using LibGit2Sharp.Tests.TestHelpers;
using System;
using System.IO;
using System.Linq;
using Xunit;
using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
public class FetchHeadFixture : BaseFixture
{
[Fact]
public void FetchHeadIsEmptyByDefault()
{
var scd = BuildSelfCleaningDirectory();
using (var repo = Repository.Init(scd.RootedDirectoryPath))
{
Assert.Equal(0, repo.Network.FetchHeads.Count());
}
}
private class FetchHeadExpected
{
public String Name { get; set; }
public String RemoteName { get; set; }
public String Url { get; set; }
public string TargetSha { get; set; }
public bool ForMerge { get; set; }
}
[Theory]
[InlineData("git://github.com/libgit2/TestGitRepository.git")]
public void CanIterateFetchHead(string url)
{
var scd = BuildSelfCleaningDirectory();
using (var repo = Repository.Clone(url, scd.RootedDirectoryPath))
{
repo.Reset(ResetOptions.Hard, "HEAD~2");
// Create a file, stage it, and commit it.
String filename = "b.txt";
String fullPath = Path.Combine(repo.Info.WorkingDirectory, filename);
File.WriteAllText(fullPath, "");
repo.Index.Stage(filename);
repo.Commit("comment", Constants.Signature, Constants.Signature);
// Issue the fetch.
repo.Fetch("origin");
// Retrieve the fetch heads and verify the expected result.
var expected = new[] {
new FetchHeadExpected
{
Name = "FETCH_HEAD[0]",
RemoteName = "refs/heads/master",
Url = "git://github.com/libgit2/TestGitRepository.git",
TargetSha = "49322bb17d3acc9146f98c97d078513228bbf3c0",
ForMerge = true,
},
new FetchHeadExpected
{
Name = "FETCH_HEAD[1]",
RemoteName = "refs/heads/first-merge",
Url = "git://github.com/libgit2/TestGitRepository.git",
TargetSha = "0966a434eb1a025db6b71485ab63a3bfbea520b6",
ForMerge = false,
},
new FetchHeadExpected
{
Name = "FETCH_HEAD[2]",
RemoteName = "refs/heads/no-parent",
Url = "git://github.com/libgit2/TestGitRepository.git",
TargetSha = "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1",
ForMerge = false,
},
new FetchHeadExpected
{
Name = "FETCH_HEAD[3]",
RemoteName = "refs/tags/annotated_tag",
Url = "git://github.com/libgit2/TestGitRepository.git",
TargetSha = "d96c4e80345534eccee5ac7b07fc7603b56124cb",
ForMerge = false,
},
new FetchHeadExpected
{
Name = "FETCH_HEAD[4]",
RemoteName = "refs/tags/blob",
Url = "git://github.com/libgit2/TestGitRepository.git",
TargetSha = "55a1a760df4b86a02094a904dfa511deb5655905",
ForMerge = false,
},
new FetchHeadExpected
{
Name = "FETCH_HEAD[5]",
RemoteName = "refs/tags/commit_tree",
Url = "git://github.com/libgit2/TestGitRepository.git",
TargetSha = "8f50ba15d49353813cc6e20298002c0d17b0a9ee",
ForMerge = false,
},
new FetchHeadExpected
{
Name = "FETCH_HEAD[6]",
RemoteName = "refs/tags/nearly-dangling",
Url = "git://github.com/libgit2/TestGitRepository.git",
TargetSha = "6e0c7bdb9b4ed93212491ee778ca1c65047cab4e",
ForMerge = false,
},
};
VerifyFetchHead(repo.Network.FetchHeads.ToArray(), expected);
}
}
private static void VerifyFetchHead(FetchHead[] actual, FetchHeadExpected[] expected)
{
Assert.NotNull(actual);
Assert.NotNull(expected);
Assert.Equal(actual.Count(), expected.Count());
int i = 0;
foreach (FetchHead fetchHead in actual)
{
Assert.Equal(fetchHead.CanonicalName, expected[i].Name);
Assert.Equal(fetchHead.RemoteCanonicalName, expected[i].RemoteName);
Assert.Equal(fetchHead.Url, expected[i].Url);
Assert.Equal(fetchHead.Target.Sha, expected[i].TargetSha);
Assert.Equal(fetchHead.ForMerge, expected[i].ForMerge);
i++;
}
}
}
}