java 执行git命令

java 执行git命令 是通过

Runtime.getRuntime().exec();

以git clone为例

public String cloneTFSCode(String path,String branch){
    String result="";
    try {
        // 替换为你的TFS代码仓库URL和本地目录
        String tfsRepoUrl = "repoURL";
        String localPath = path+"\\CODE";

        // 构建Git克隆命令,每个命令中间都以,分割
        String[] cmd = new String[]{"git", "clone","-b",branch, tfsRepoUrl, localPath};

        // 执行命令
        Process process = Runtime.getRuntime().exec(cmd);

        // 读取命令行输出
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String s = null;
        while ((s = stdInput.readLine()) != null) {
            System.out.println(s);
        }

        // 等待命令执行完成
        process.waitFor();
        System.out.println("Git clone branch "+branch+" completed.");
        result = "SUCCESS";
    } catch (IOException | InterruptedException e) {
        result = "ERROR";
        e.printStackTrace();
    }
    return result;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值