From 9a84b9016eaf3a79e7fc30146c9405a541a5da15 Mon Sep 17 00:00:00 2001 From: lindexi Date: Sat, 11 May 2024 16:25:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E6=94=AF=E6=8C=81=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/GitCommand/GitCommand.Tests/GitTest.cs | 14 ++++++++++++++ package/GitCommand/GitCommand/Git.cs | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/package/GitCommand/GitCommand.Tests/GitTest.cs b/package/GitCommand/GitCommand.Tests/GitTest.cs index f20b8c0..51adc5c 100644 --- a/package/GitCommand/GitCommand.Tests/GitTest.cs +++ b/package/GitCommand/GitCommand.Tests/GitTest.cs @@ -16,6 +16,20 @@ public void GetCurrentBranch() { var git = new Git(new DirectoryInfo(".")); var currentBranch = git.GetCurrentBranch(); + Assert.IsNotNull(currentBranch); + Assert.AreEqual(false, currentBranch.Contains('\n')); + }); + } + +#if DEBUG + [ContractTestCase] // 这条有负面效果,不要加入到通用测试里面 +#endif + public void Push() + { + "推送给定仓库,可以推送成功".Test(() => + { + var git = new Git(new DirectoryInfo(".")); + git.Push("origin", "master"); }); } } diff --git a/package/GitCommand/GitCommand/Git.cs b/package/GitCommand/GitCommand/Git.cs index a5cf490..230ede7 100644 --- a/package/GitCommand/GitCommand/Git.cs +++ b/package/GitCommand/GitCommand/Git.cs @@ -394,7 +394,9 @@ public void Commit(string message) /// 是否需要强行推送,加上 -f 命令 public string Push(string repository, string branchOrTag, bool force = false) { - return Control($"push \"{repository}\" \"{branchOrTag}\" {(force ? "-f" : "")}"); + var args = $"push \"{repository}\" \"{branchOrTag}\" {(force ? "-f" : "")}"; + var (success, output) = ExecuteCommand(args); + return output; } ///