Skip to content

Commit

Permalink
[fix] fix build version not auto detect
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnkwlp committed Dec 6, 2021
1 parent 1c0b0dd commit 699b5ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Git-CI-Tools/CommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,23 @@ public VersionNextCommandResult VersionNext(VersionNextCommandOptions options)

// nextVersion = VersionGenerater.Next(nextVersion, prerelease: options.PrereleaseVer ?? "", build: options.BuildVer ?? "");

if (options.AutoDetectBuildVer && string.IsNullOrEmpty(options.BuildVer))
if (options.AutoDetectBuildVer && options.BuildVer == null)
{
var latestCommit = resolverVersionResult.Commits.FirstOrDefault();
if (latestCommit != null)
{
nextVersion = VersionGenerater.Next(nextVersion, build: latestCommit.Sha.Substring(0, 8));
}
else
{
// use current commit
var commit = git.Commits[0];
nextVersion = VersionGenerater.Next(nextVersion, build: commit.Sha[..8]);
}
}
else
{
nextVersion = VersionGenerater.Next(nextVersion, build: options.BuildVer ?? "");
nextVersion = VersionGenerater.Next(nextVersion, build: options.BuildVer);
}

if (options.AutoDetect)
Expand Down
2 changes: 2 additions & 0 deletions Git-CI-Tools/GitContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class GitContext
public string Project => _repository.Info.WorkingDirectory; //new DirectoryInfo(_path).Parent.FullName;
public string Git => _path;

public IReadOnlyList<GitCommit> Commits => GetCommits();

public GitContext(string path)
{
if (string.IsNullOrWhiteSpace(path))
Expand Down

0 comments on commit 699b5ab

Please sign in to comment.