libgit2 / libgit2/libgit2sharp

Two conflicts instead of one for renamed file

Open
#1,931 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.5k
Forks
925
PR merge metrics
No merged PRs in 30d

Description

Reproduction steps
  1. Checkout commit https://github.com/ydanila/test_git from https://github.com/ydanila/test_git
  2. Renamed README.md to README2.md and commit (will be marked as renamed)
  3. Pull changes from 'main' using this code
public void Pull(string branch)
{
	using (var repo = new Repository(this.repoPath))
	{
		Configuration config = repo.Config;
		var mergeOptions = new MergeOptions
		{
			FailOnConflict = true,
			OnCheckoutProgress = OnCheckoutProgress
		};

		PullOptions options = new PullOptions
		{
			FetchOptions = new FetchOptions { CredentialsProvider = this.GetCredentialsProvider() },
			MergeOptions = mergeOptions
		};

		var trackingBranch = repo.Branches[branch];

		Signature buildSignature = config.BuildSignature(DateTimeOffset.Now);
		var mergeResult = Commands.Pull(repo, buildSignature, options);

		if (mergeResult.Status == MergeStatus.Conflicts)
		{
			repo.Merge(trackingBranch.TrackedBranch, buildSignature);
			ConflictCollection conflicts = repo.Index.Conflicts;
			var changes = new List<ContentChanges>();
			foreach (Conflict conflict in conflicts)
			{
				//	...
                        }
		}
	}
}
Expected behavior

As mergeOptions.FindRenames == true it returns one conflict which has Ancestor==Readme.md, Ours==Readme2.md and Theirs==null (file deleted)

Actual behavior

It returns two conflicts.
First:
2021-12-06 20_58_25-Window
Second:
2021-12-06 21_06_05-Aehnlich (Отладка) - Microsoft Visual Studio

Version of LibGit2Sharp (release number or SHA1)

Latest: 4daf6189b0e20f878348b262d1846eb25bc6d7f6

Operating system(s) tested; .NET runtime tested

Windows .Net Fw 4.7.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the conflict using the linked test_git repository and the Pull method with MergeOptions.FindRenames enabled. Start by examining Commands.Pull, repo.Merge, and repo.Index.Conflicts; done means the renamed-file case reports one conflict with the expected Ancestor, Ours, and Theirs values.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, git
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.