|
1 |
| -using System.IO; |
| 1 | +using System; |
| 2 | +using System.IO; |
2 | 3 | using System.Linq;
|
3 | 4 | using System.Text;
|
4 | 5 | using LibGit2Sharp.Tests.TestHelpers;
|
@@ -388,5 +389,71 @@ public void ComparingTwoNullTreesReturnsAnEmptyTreeChanges()
|
388 | 389 | Assert.Equal(0, changes.Count());
|
389 | 390 | }
|
390 | 391 | }
|
| 392 | + |
| 393 | + [Fact] |
| 394 | + public void ComparingReliesOnProvidedConfigEntriesIfAny() |
| 395 | + { |
| 396 | + TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath); |
| 397 | + |
| 398 | + const string file = "1/branch_file.txt"; |
| 399 | + |
| 400 | + using (var repo = new Repository(path.DirectoryPath)) |
| 401 | + { |
| 402 | + TreeEntry entry = repo.Head[file]; |
| 403 | + Assert.Equal(Mode.ExecutableFile, entry.Mode); |
| 404 | + |
| 405 | + // Recreate the file in the workdir without the executable bit |
| 406 | + string fullpath = Path.Combine(repo.Info.WorkingDirectory, file); |
| 407 | + File.Delete(fullpath); |
| 408 | + File.WriteAllBytes(fullpath, ((Blob)(entry.Target)).Content); |
| 409 | + |
| 410 | + // Unset the local core.filemode, if any. |
| 411 | + repo.Config.Unset("core.filemode", ConfigurationLevel.Local); |
| 412 | + } |
| 413 | + |
| 414 | + SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); |
| 415 | + |
| 416 | + var options = BuildFakeSystemConfigFilemodeOption(scd, true); |
| 417 | + |
| 418 | + using (var repo = new Repository(path.DirectoryPath, options)) |
| 419 | + { |
| 420 | + TreeChanges changes = repo.Diff.Compare(new []{ file }); |
| 421 | + |
| 422 | + Assert.Equal(1, changes.Count()); |
| 423 | + |
| 424 | + var change = changes.Modified.Single(); |
| 425 | + Assert.Equal(Mode.ExecutableFile, change.OldMode); |
| 426 | + Assert.Equal(Mode.NonExecutableFile, change.Mode); |
| 427 | + } |
| 428 | + |
| 429 | + options = BuildFakeSystemConfigFilemodeOption(scd, false); |
| 430 | + |
| 431 | + using (var repo = new Repository(path.DirectoryPath, options)) |
| 432 | + { |
| 433 | + TreeChanges changes = repo.Diff.Compare(new[] { file }); |
| 434 | + |
| 435 | + Assert.Equal(0, changes.Count()); |
| 436 | + } |
| 437 | + } |
| 438 | + |
| 439 | + private RepositoryOptions BuildFakeSystemConfigFilemodeOption( |
| 440 | + SelfCleaningDirectory scd, |
| 441 | + bool value) |
| 442 | + { |
| 443 | + Directory.CreateDirectory(scd.DirectoryPath); |
| 444 | + |
| 445 | + var options = new RepositoryOptions |
| 446 | + { |
| 447 | + SystemConfigurationLocation = Path.Combine( |
| 448 | + scd.RootedDirectoryPath, "fake-system.config") |
| 449 | + }; |
| 450 | + |
| 451 | + StringBuilder sb = new StringBuilder() |
| 452 | + .AppendFormat("[core]{0}", Environment.NewLine) |
| 453 | + .AppendFormat("filemode = {1}{0}", Environment.NewLine, value); |
| 454 | + File.WriteAllText(options.SystemConfigurationLocation, sb.ToString()); |
| 455 | + |
| 456 | + return options; |
| 457 | + } |
391 | 458 | }
|
392 | 459 | }
|
0 commit comments