Skip to content

Commit

Permalink
Merge pull request #574 from dotnet/fix573
Browse files Browse the repository at this point in the history
Produce absolute path per api doc when reading version file
  • Loading branch information
AArnott authored Mar 29, 2021
2 parents d7059f7 + 88be817 commit 8411716
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/NerdBank.GitVersioning.Tests/VersionFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,15 @@ VersionOptions GetOption(string path)
}
}

[Fact]
public void GetVersion_ProducesAbsolutePath()
{
this.InitializeSourceControl();
this.WriteVersionFile();
Assert.NotNull(this.Context.VersionFile.GetVersion(out string actualDirectory));
Assert.True(Path.IsPathRooted(actualDirectory));
}

private void AssertPathHasVersion(string committish, string absolutePath, VersionOptions expected)
{
var actual = this.GetVersionOptions(absolutePath, committish);
Expand Down
6 changes: 4 additions & 2 deletions src/NerdBank.GitVersioning/LibGit2/LibGit2VersionFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ internal LibGit2VersionFile(LibGit2Context context)

if (result is object)
{
actualDirectory = searchDirectory;
IBelongToARepository commitAsRepoMember = commit;
actualDirectory = Path.Combine(commitAsRepoMember.Repository.Info.WorkingDirectory, searchDirectory);
return result;
}
}
Expand Down Expand Up @@ -125,7 +126,8 @@ internal LibGit2VersionFile(LibGit2Context context)
}
else if (result is object)
{
actualDirectory = searchDirectory;
IBelongToARepository commitAsRepoMember = commit;
actualDirectory = Path.Combine(commitAsRepoMember.Repository.Info.WorkingDirectory, searchDirectory);
return result;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/NerdBank.GitVersioning/Managed/ManagedVersionFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public ManagedVersionFile(GitContext context)
if (result is object)
{
finalResult = result;
actualDirectory = searchDirectory;
actualDirectory = Path.Combine(this.Context.WorkingTreePath, searchDirectory);
}
}

Expand Down Expand Up @@ -158,7 +158,7 @@ public ManagedVersionFile(GitContext context)

if (result is object)
{
actualDirectory = searchDirectory;
actualDirectory = Path.Combine(this.Context.WorkingTreePath, searchDirectory);
finalResult = result;
}
}
Expand Down

0 comments on commit 8411716

Please sign in to comment.