|
|
@@ -1,8 +1,10 @@ |
|
|
|
package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"bufio" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"io" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
@@ -499,6 +501,45 @@ func downloadCode(repo *models.Repository, codePath string) error { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
configFile, err := os.OpenFile(codePath + "/.git/config", os.O_RDWR, 0666) |
|
|
|
if err != nil { |
|
|
|
log.Error("open file(%s) failed:%v", codePath + "/,git/config", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
defer configFile.Close() |
|
|
|
|
|
|
|
pos := int64(0) |
|
|
|
reader := bufio.NewReader(configFile) |
|
|
|
for { |
|
|
|
line, err := reader.ReadString('\n') |
|
|
|
if err != nil { |
|
|
|
if err == io.EOF { |
|
|
|
log.Error("not find the remote-url") |
|
|
|
return nil |
|
|
|
} else { |
|
|
|
log.Error("read error: %v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if strings.Contains(line, "url") && strings.Contains(line, ".git"){ |
|
|
|
originUrl := "\turl = " + repo.CloneLink().HTTPS + "\n" |
|
|
|
if len(line) > len(originUrl) { |
|
|
|
originUrl += strings.Repeat( " ", len(line) - len(originUrl)) |
|
|
|
} |
|
|
|
bytes := []byte(originUrl) |
|
|
|
_, err := configFile.WriteAt(bytes, pos) |
|
|
|
if err != nil { |
|
|
|
log.Error("WriteAt failed:%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
pos += int64(len(line)) |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|