c# - 将分支名称获取到代码中

标签 c# git visual-studio

我对将分支名称作为字符串传递给我的代码有疑问。

所以我们使用的是 git 存储库,分支号也指的是放置构建的暂存环境。意思是,如果我的分支是 001,我的 url 是 001.test.myapplication.com。

我正在编写在分支的暂存环境中执行的自动化测试。我的问题是,是否可以将分支编号传递给我的代码,以便我可以将其作为我要测试的 URL 的一部分?

我正在使用 visual studio 2017、selenium 和 specflow。

最佳答案

我实际上找到了一个完美的解决方案。分享出来,以后有需要的人也可以用。

ProcessStartInfo startInfo = new ProcessStartInfo("git.exe");

startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = "dir Here";
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.Arguments = "rev-parse --abbrev-ref HEAD";

Process process = new Process();
process.StartInfo = startInfo;
process.Start();

string branchname = process.StandardOutput.ReadLine();

关于c# - 将分支名称获取到代码中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48421697/

相关文章:

c# - 从 C# 代码更改内容占位符中的 href 链接

windows - 在 Windows 上使用 Git

javascript - ReactDOM - 元素类型无效 : expected a string (for built-in components) or a class/function (for composite components) but got: undefined

c# - 将 git 上的所有提交返回到尚未 merge 的主分支的最简单方法是什么?

c# - C# 编译器是否为引用类型(如果未指定)或 CLR 提供默认构造函数?

c# - 未分配的局部变量是否保证 CS0165 C# 编译器错误?

c# - 使用 Worksheet.Range.Autofilter(Field,Criteria,Operator) 按特定颜色索引/RGB 过滤范围

git - 压缩提交会对可 merge 性产生影响吗?

pull 时git merge 问题

visual-studio - Visual Studio 2015 更新 3 : "This project uses SQL Server Express LocalDB. Microsoft recommends that you use SQL Server Express with IIS"