Java实现git相关操作(登录,克隆)

该博客介绍了如何使用Java实现Git的相关操作,包括通过JGit库进行git clone操作,以及实现GitLab的登录认证流程,涉及OAuth授权、获取access_token、用户信息处理等步骤。
摘要由CSDN通过智能技术生成

import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
/**
 * @ClassName JGitUtil
 * @Description git命令操作工具
 * @Version 1.0
 **/
@Slf4j
@Component
public class JGitUtil {
    /**
     * @Description git clone操作
     * @Param [url, localPath]
     **/
    public  boolean cloneRepository(String url,String localPath)
    {
        File cloneFile = new File(localPath);
        try{
            log.info("git clone开始执行......");
            Git repository = Git.cloneRepository().setURI(url).setBranch("master").setDirectory(cloneFile).call();
            repository.getRepository().close();
            log.info("git clone 执行完成......");
            return true;
        }catch(Exception e)
        {
            log.error("git clone 执行失败,请检查",e.getMessage());
            e.printStackTrace();
            return false;
        }
    }
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

import com.alibaba.fastjson.JSONObject;
import com.ljqc.license.entity.pg.SysAccountEntity;
import com.ljqc.license.service.ISysAccountService;
import com.ljqc.license.utils.AccountUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
impo

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值