Skip to content

Commit

Permalink
尝试支持推送的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed May 11, 2024
1 parent 7246390 commit 9a84b90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions package/GitCommand/GitCommand.Tests/GitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
}
}
Expand Down
4 changes: 3 additions & 1 deletion package/GitCommand/GitCommand/Git.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ public void Commit(string message)
/// <param name="force">是否需要强行推送,加上 -f 命令</param>
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;
}

/// <summary>
Expand Down

0 comments on commit 9a84b90

Please sign in to comment.