1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| func Clone(ctx *gin.Context) { url := "http://git.shinyinfo.com.cn/zousu/devops.git" dir := "/home/yyg/workspace/gogit/devops" username := "yongga@mail.com" password := "passwd"
buf := bytes.NewBufferString("")
r, err := git.PlainClone(dir, false, &git.CloneOptions{ URL: url, Auth: &githttp.BasicAuth{ Username: username, Password: password, }, Progress: buf, })
if err != nil { log.Println(err) ctx.String(http.StatusInternalServerError, err.Error()) return } ref, err := r.Head() if err != nil { log.Println(err) ctx.String(http.StatusInternalServerError, err.Error()) ctx.AbortWithError(http.StatusInternalServerError, err) } commit, err := r.CommitObject(ref.Hash()) if err != nil { log.Println(err) ctx.String(http.StatusInternalServerError, err.Error()) return } fmt.Println("last commit", commit) ctx.String(http.StatusOK, buf.String()) }
|