You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ly...@apache.org on 2024/08/27 08:30:48 UTC
(incubator-devlake) branch release-v1.0 updated: fix(gitextractor): support empty repos (#7963) (#7964)
This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a commit to branch release-v1.0
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/release-v1.0 by this push:
new cc7250067 fix(gitextractor): support empty repos (#7963) (#7964)
cc7250067 is described below
commit cc7250067c714b266b231c77f5d6bea65c4b5d52
Author: github-actions[bot] <41...@users.noreply.github.com>
AuthorDate: Tue Aug 27 16:30:43 2024 +0800
fix(gitextractor): support empty repos (#7963) (#7964)
* fix(gitextractor): support empty repos
* fix(gitextractor): tiny fix
Co-authored-by: Lynwee <15...@qq.com>
---
.../plugins/gitextractor/parser/clone_gitcli.go | 35 ++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/backend/plugins/gitextractor/parser/clone_gitcli.go b/backend/plugins/gitextractor/parser/clone_gitcli.go
index 6dbf5481a..adeceb9e3 100644
--- a/backend/plugins/gitextractor/parser/clone_gitcli.go
+++ b/backend/plugins/gitextractor/parser/clone_gitcli.go
@@ -258,7 +258,7 @@ func (g *GitcliCloner) doubleClone() errors.Error {
return err
}
g.localDir = backup
- // step 2: perform shallow clone aginst the intermediary dir
+ // step 2: perform shallow clone against the intermediary dir
backup = g.remoteUrl
g.remoteUrl = fmt.Sprintf("file://%s", intermediaryDir) // the file:// prefix is required for shallow clone to work
if err := g.shallowClone(); err != nil {
@@ -274,10 +274,30 @@ func (g *GitcliCloner) gitClone(args ...string) errors.Error {
}
func (g *GitcliCloner) gitFetch(args ...string) errors.Error {
+ empty, err := g.repoIsEmpty(args...)
+ if err != nil {
+ g.logger.Error(err, "repo is empty")
+ return err
+ }
+ if empty {
+ g.logger.Info("repo is empty, doesn't need to fetch")
+ return nil
+ }
args = append(args, g.syncArgs...)
return g.git(g.syncEnvs, g.localDir, "fetch", args...)
}
+func (g *GitcliCloner) repoIsEmpty(args ...string) (bool, errors.Error) {
+ // try to run command: git log
+ // if repo is empty, it will return an error
+ err := g.git(g.syncEnvs, g.localDir, "log")
+ if err != nil {
+ g.logger.Warn(err, "git log failed")
+ return true, nil
+ }
+ return false, nil
+}
+
func (g *GitcliCloner) gitCmd(gitcmd string, args ...string) errors.Error {
return g.git(nil, g.localDir, gitcmd, args...)
}
@@ -294,15 +314,26 @@ func (g *GitcliCloner) git(env []string, dir string, gitcmd string, args ...stri
func (g *GitcliCloner) execCommand(cmd *exec.Cmd) errors.Error {
output, err := cmd.CombinedOutput()
if err != nil {
+ g.logger.Debug("err: %v, output: %s", err, string(output))
outputString := string(output)
if strings.Contains(outputString, "fatal: error processing shallow info: 4") ||
strings.Contains(outputString, "fatal: the remote end hung up unexpectedly") {
return ErrNoData
}
- return errors.Default.New(fmt.Sprintf("git cmd %v in %s failed: %s", sanitizeArgs(cmd.Args), cmd.Dir, outputString))
+ return errors.Default.New(fmt.Sprintf("git cmd %v in %s failed: %s", sanitizeArgs(cmd.Args), cmd.Dir, generateErrMsg(output, err)))
}
return nil
}
+func generateErrMsg(output []byte, err error) string {
+ errMsg := strings.TrimSpace(string(output))
+ if errMsg == "" {
+ errMsg = err.Error()
+ }
+ if errMsg == "" {
+ errMsg = "unknown error"
+ }
+ return errMsg
+}
func sanitizeArgs(args []string) []string {
var ret []string