Skip to content

Commit 4f8825b

Browse files
verified that repository detection works (#5)
1 parent 6efe157 commit 4f8825b

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using FluentAssertions;
5+
using Incrementalist.Git;
6+
using Incrementalist.Tests.Helpers;
7+
using Xunit;
8+
9+
namespace Incrementalist.Tests.Git
10+
{
11+
public class GitRepositoryDetectionSpecs : IDisposable
12+
{
13+
public GitRepositoryDetectionSpecs()
14+
{
15+
Repository = new DisposableRepository();
16+
}
17+
18+
public DisposableRepository Repository { get; }
19+
20+
[Fact(DisplayName = "GitRunner should detect repository correctly")]
21+
public void Should_detect_Repository()
22+
{
23+
var results = GitRunner.FindRepository(Repository.BasePath);
24+
results.foundRepo.Should().BeTrue();
25+
26+
// note: due to what I believe is native interop here, the Repository.Info.WorkingDirectory
27+
// string appears to have an extra null terminator at the end
28+
results.repo.Info.WorkingDirectory.Should().Contain(Repository.BasePath.Trim());
29+
}
30+
31+
public void Dispose()
32+
{
33+
Repository?.Dispose();
34+
}
35+
}
36+
}

src/Incrementalist/Git/GitRunner.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public sealed class GitRunner
1515
/// Find the repository and the full path of the base directory.
1616
/// </summary>
1717
/// <param name="targetDirectory">Optional. The directory to search inside of. Defaults to <see cref="Directory.GetCurrentDirectory"/> otherwise.</param>
18-
/// <returns>A tuple containing the repository, the base directory (parent directory of the .git folder,) and a boolean flag indicating whether or not
18+
/// <returns>A tuple containing the repository and a boolean flag indicating whether or not
1919
/// the search was successful.</returns>
20-
public (Repository repo, string baseDirectory, bool foundRepo) FindRepository(string targetDirectory = null)
20+
public static (Repository repo, bool foundRepo) FindRepository(string targetDirectory = null)
2121
{
2222
var repoPath = Repository.Discover(targetDirectory ?? Directory.GetCurrentDirectory());
2323
if (string.IsNullOrEmpty(repoPath))
24-
return (null, null, false);
24+
return (null, false);
2525

26-
return (new Repository(repoPath), Directory.GetParent(repoPath).Parent.FullName, true);
26+
return (new Repository(repoPath), true);
2727
}
2828
}
2929
}

0 commit comments

Comments
 (0)