Skip to content

Commit

Permalink
🐛 QD-10767 Update submodules when checkout performed in full history …
Browse files Browse the repository at this point in the history
…and scoped script (#519)
  • Loading branch information
MekhailS committed Feb 19, 2025
1 parent 6a32f49 commit 90f4baf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func runWithFullHistory(ctx context.Context, c corescan.Context, startHash strin
counter++

msg.WarningMessage("[%d/%d] Running analysis for revision %s", counter+1, allCommits, revision)
err = git.Checkout(c.ProjectDir(), revision, true, c.LogDir())
err = git.CheckoutAndUpdateSubmodule(c.ProjectDir(), revision, true, c.LogDir())
if err != nil {
log.Fatal(err)
}
Expand All @@ -244,7 +244,7 @@ func runWithFullHistory(ctx context.Context, c corescan.Context, startHash strin
contextForAnalysis := c.WithVcsEnvForFullHistoryAnalysisIteration(remoteUrl, branch, revision)
exitCode = runQodana(ctx, contextForAnalysis)
}
err = git.Checkout(c.ProjectDir(), branch, true, c.LogDir())
err = git.CheckoutAndUpdateSubmodule(c.ProjectDir(), branch, true, c.LogDir())
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -274,7 +274,7 @@ func runScopeScript(ctx context.Context, c corescan.Context, startHash string) i
}()

runFunc := func(hash string, c corescan.Context) (bool, int) {
e := git.Checkout(c.ProjectDir(), hash, true, c.LogDir())
e := git.CheckoutAndUpdateSubmodule(c.ProjectDir(), hash, true, c.LogDir())
if e != nil {
log.Fatalf("Cannot checkout commit %s: %v", hash, e)
}
Expand Down
25 changes: 23 additions & 2 deletions platform/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,18 @@ func ResetBack(cwd string, logdir string) error {
return err
}

// Checkout checks out the given commit / branch.
func Checkout(cwd string, where string, force bool, logdir string) error {
// See QD-10767 case for why update submodule is needed

Check notice on line 65 in platform/git/git.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'CheckoutAndUpdateSubmodule ...' (with an optional leading article)
func CheckoutAndUpdateSubmodule(cwd string, where string, force bool, logdir string) error {
err := checkout(cwd, where, force, logdir)
if err != nil {
return err
}
err = submoduleUpdate(cwd, force, logdir)
return err
}

// checkout checks out the given commit / branch.
func checkout(cwd string, where string, force bool, logdir string) error {
var err error
if !force {
_, _, err = gitRun(cwd, []string{"checkout", where}, logdir)
Expand All @@ -73,6 +83,17 @@ func Checkout(cwd string, where string, force bool, logdir string) error {
return err
}

// GitSubmoduleUpdate updates submodules according to current revision
func submoduleUpdate(cwd string, force bool, logdir string) error {
if !force {
_, _, err := gitRun(cwd, []string{"submodule", "update", "--init", "--recursive"}, logdir)
return err
} else {
_, _, err := gitRun(cwd, []string{"submodule", "update", "--init", "--recursive", "--force"}, logdir)
return err
}
}

// Clean cleans the git repository.
func Clean(cwd string, logdir string) error {
_, _, err := gitRun(cwd, []string{"clean", "-fdx"}, logdir)
Expand Down

0 comments on commit 90f4baf

Please sign in to comment.