Skip to content

Commit

Permalink
获取当前 commit 的代码进行重写
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed May 11, 2024
1 parent 75686a6 commit 5389de8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
12 changes: 12 additions & 0 deletions package/GitCommand/GitCommand.Tests/GitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,17 @@ public void Push()
git.Push("origin", "master");
});
}

[ContractTestCase]
public void GetCurrentCommit()
{
"尝试获取当前的 commit 字符串,可以获取成功".Test(() =>
{
var git = new Git(new DirectoryInfo("."));
var currentCommit = git.GetCurrentCommit();
Assert.IsNotNull(currentCommit);
Assert.AreEqual(false, currentCommit.Contains('\n'));
});
}
}
}
15 changes: 2 additions & 13 deletions package/GitCommand/GitCommand/Git.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,8 @@ public string[] GetLogCommit()
/// <returns></returns>
public string GetCurrentCommit()
{
var file = Path.GetTempFileName();
Control($"rev-parse HEAD > \"{file}\"");
var commit = File.ReadAllText(file).Trim();
try
{
File.Delete(file);
}
catch
{
// 清掉失败?那啥也不用做
}

return commit;
var (success, output) = ExecuteCommand("rev-parse HEAD");
return output.Trim('\n');
}

/// <summary>
Expand Down

0 comments on commit 5389de8

Please sign in to comment.