diff --git a/cmd/scan.go b/cmd/scan.go index d4bbb25e..e2cc1f6e 100644 --- a/cmd/scan.go +++ b/cmd/scan.go @@ -124,6 +124,9 @@ func checkExitCode(exitCode int, resultsDir string, options *core.QodanaOptions) } else if exitCode == platform.QodanaTimeoutExitCodePlaceholder { platform.ErrorMessage("Qodana analysis reached timeout %s", options.GetAnalysisTimeout()) os.Exit(options.AnalysisTimeoutExitCode) + } else if exitCode == platform.QodanaEmptyChangesetExitCodePlaceholder { + platform.ErrorMessage("Nothing to analyse. Exiting with %s", platform.QodanaSuccessExitCode) + os.Exit(platform.QodanaSuccessExitCode) } else if exitCode != platform.QodanaSuccessExitCode && exitCode != platform.QodanaFailThresholdExitCode { platform.ErrorMessage("Qodana exited with code %d", exitCode) platform.WarningMessage("Check ./logs/ in the results directory for more information") diff --git a/core/system.go b/core/system.go index 996714c1..61fb19dc 100644 --- a/core/system.go +++ b/core/system.go @@ -316,7 +316,19 @@ func runScopeScript(ctx context.Context, options *QodanaOptions, startHash strin } } - scopeFile, err := writeChangesFile(options, startHash, end) + if startHash == "" || end == "" { + log.Fatal("No commits given. Consider passing --commit or --diff-start and --diff-end (optional) with the range of commits to analyze.") + } + changedFiles, err := platform.GitChangedFiles(options.ProjectDir, startHash, end, options.LogDirPath()) + if err != nil { + log.Fatal(err) + } + if len(changedFiles.Files) == 0 { + log.Warnf("Nothing to compare between %s and %s", startHash, end) + return platform.QodanaEmptyChangesetExitCodePlaceholder + } + + scopeFile, err := writeChangesFile(options, changedFiles) if err != nil { log.Fatal("Failed to prepare diff run ", err) } @@ -415,18 +427,7 @@ func runScopeScript(ctx context.Context, options *QodanaOptions, startHash strin } // writeChangesFile creates a temp file containing the changes between diffStart and diffEnd -func writeChangesFile(options *QodanaOptions, start string, end string) (string, error) { - if start == "" || end == "" { - return "", fmt.Errorf("no commits given") - } - changedFiles, err := platform.GitChangedFiles(options.ProjectDir, start, end, options.LogDirPath()) - if err != nil { - return "", err - } - - if len(changedFiles.Files) == 0 { - return "", fmt.Errorf("nothing to compare between %s and %s", start, end) - } +func writeChangesFile(options *QodanaOptions, changedFiles platform.ChangedFiles) (string, error) { file, err := os.CreateTemp("", "diff-scope.txt") if err != nil { return "", err diff --git a/platform/cmd.go b/platform/cmd.go index e2adfff7..23fcafd6 100644 --- a/platform/cmd.go +++ b/platform/cmd.go @@ -42,8 +42,11 @@ const ( // QodanaEapLicenseExpiredExitCode reports an expired license. QodanaEapLicenseExpiredExitCode = 7 // QodanaTimeoutExitCodePlaceholder is not a real exit code (it is not obtained from IDE process! and not returned from CLI) - QodanaTimeoutExitCodePlaceholder = 1000 // Placeholder used to identify the case when the analysis reached timeout + QodanaTimeoutExitCodePlaceholder = 1000 + // QodanaEmptyChangesetExitCodePlaceholder is not a real exit code (it is not obtained from IDE process! and not returned from CLI) + // Placeholder used to identify the case when the changeset for scoped analysis is empty + QodanaEmptyChangesetExitCodePlaceholder = 2000 ) // RunCmd executes subprocess with forwarding of signals, and returns its exit code.