8000 Move Repository.Conflicts to Index.Conflicts · crashsplash/libgit2sharp@718a99e · GitHub
[go: up one dir, main page]

Skip to content

Commit 718a99e

Browse files
Saamannulltoken
authored andcommitted
Move Repository.Conflicts to Index.Conflicts
1 parent 95430a1 commit 718a99e

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

LibGit2Sharp.Tests/ConflictFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ public void CanClearConflictsByRemovingFromTheIndex(
6060
string fullpath = Path.Combine(repo.Info.WorkingDirectory, filename);
6161

6262
Assert.Equal(existsBeforeRemove, File.Exists(fullpath));
63-
Assert.NotNull(repo.Conflicts[filename]);
63+
Assert.NotNull(repo.Index.Conflicts[filename]);
6464

6565
repo.Index.Remove(filename, removeFromWorkdir);
6666

67-
Assert.Null(repo.Conflicts[filename]);
67+
Assert.Null(repo.Index.Conflicts[filename]);
6868
Assert.Equal(count - removedIndexEntries, repo.Index.Count);
6969
Assert.Equal(existsAfterRemove, File.Exists(fullpath));
7070
Assert.Equal(lastStatus, repo.Index.RetrieveStatus(filename));
@@ -76,7 +76,7 @@ public void CanRetrieveSingleConflictByPath(string filepath, string ancestorId,
7676
{
7777
using (var repo = new Repository(MergedTestRepoWorkingDirPath))
7878
{
79-
Conflict conflict = repo.Conflicts[filepath];
79+
Conflict conflict = repo.Index.Conflicts[filepath];
8080
Assert.NotNull(conflict);
8181

8282
ObjectId expectedAncestor = ancestorId != null ? new ObjectId(ancestorId) : null;
@@ -123,7 +123,7 @@ public void CanRetrieveAllConflicts()
123123
{
124124
using (var repo = new Repository(MergedTestRepoWorkingDirPath))
125125
{
126-
var expected = repo.Conflicts.Select(c => new[] { GetPath(c), GetId(c.Ancestor), GetId(c.Ours), GetId(c.Theirs) }).ToArray();
126+
var expected = repo.Index.Conflicts.Select(c => new[] { GetPath(c), GetId(c.Ancestor), GetId(c.Ours), GetId(c.Theirs) }).ToArray();
127127
Assert.Equal(expected, ConflictData);
128128
}
129129
}

LibGit2Sharp/Index.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Index : IEnumerable<IndexEntry>
2121
{
2222
private readonly IndexSafeHandle handle;
2323
private readonly Repository repo;
24+
private readonly ConflictCollection conflicts;
2425

2526
/// <summary>
2627
/// Needed for mocking purposes.
@@ -33,6 +34,8 @@ internal Index(Repository repo)
3334
this.repo = repo;
3435

3536
handle = Proxy.git_repository_index(repo.Handle);
37+
conflicts = new ConflictCollection(repo);
38+
3639
repo.RegisterForCleanup(handle);
3740
}
3841

@@ -42,6 +45,7 @@ internal Index(Repository repo, string indexPath)
4245

4346
handle = Proxy.git_index_open(indexPath);
4447
Proxy.git_repository_set_index(repo.Handle, handle);
48+
conflicts = new ConflictCollection(repo);
4549

4650
repo.RegisterForCleanup(handle);
4751
}
@@ -528,6 +532,17 @@ internal void Reset(TreeChanges changes)
528532
UpdatePhysicalIndex();
529533
}
530534

535+
/// <summary>
536+
/// Gets the conflicts that exist.
537+
/// </summary>
538+
public virtual ConflictCollection Conflicts
539+
{
540+
get
541+
{
542+
return conflicts;
543+
}
544+
}
545+
531546
private void ReplaceIndexEntryWith(TreeEntryChanges treeEntryChanges)
532547
{
533548
var indexEntry = new GitIndexEntry

LibGit2Sharp/Repository.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public class Repository : IRepository
2525
private readonly Lazy<Configuration> config;
2626
private readonly RepositorySafeHandle handle;
2727
private readonly Index index;
28-
private readonly ConflictCollection conflicts;
2928
private readonly ReferenceCollection refs;
3029
private readonly TagCollection tags;
3130
private readonly StashCollection stashes;
@@ -99,7 +98,6 @@ public Repository(string path, RepositoryOptions options = null)
9998
if (!isBare)
10099
{
101100
index = indexBuilder();
102-
conflicts = new ConflictCollection(this);
103101
}
104102

105103
commits = new CommitLog(this);
@@ -233,16 +231,12 @@ public Index Index
233231
/// <summary>
234232
/// Gets the conflicts that exist.
235233
/// </summary>
234+
[Obsolete("This property will be removed in the next release. Please use Index.Conflicts instead.")]
236235
public ConflictCollection Conflicts
237236
{
238237
get
239238
{
240-
if (isBare)
241-
{
242-
throw new BareRepositoryException("Conflicts are not available in a bare repository.");
243-
}
244-
245-
return conflicts;
239+
return Index.Conflicts;
246240
}
247241
}
248242

0 commit comments

Comments
 (0)
0