@@ -372,17 +372,6 @@ func main() {
372
372
}
373
373
}
374
374
375
- // Function to check if the commit is valid
376
- func isValidCommit (commit string ) bool {
377
- cmd := exec .Command ("git" , "cat-file" , "-t" , commit )
378
- output , err := cmd .Output ()
379
- if err != nil {
380
- return false
381
- }
382
-
383
- return strings .TrimSpace (string (output )) == "commit"
384
- }
385
-
386
375
func run (state overseer.State ) {
387
376
388
377
ctx , cancel := context .WithCancelCause (context .Background ())
@@ -423,9 +412,6 @@ func run(state overseer.State) {
423
412
// When setting a base commit, chunks must be scanned in order.
424
413
if * gitScanSinceCommit != "" {
425
414
* concurrency = 1
426
- if ! isValidCommit (* gitScanSinceCommit ) {
427
- logger .Info ("Warning: The provided commit hash appears to be invalid." )
428
- }
429
415
}
430
416
431
417
if * profile {
@@ -717,6 +703,13 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
717
703
var refs []sources.JobProgressRef
718
704
switch cmd {
719
705
case gitScan .FullCommand ():
706
+ // validate the commit for local repository only
707
+ if * gitScanSinceCommit != "" && strings .HasPrefix (* gitScanURI , "file" ) {
708
+ if ! isValidCommit (* gitScanURI , * gitScanSinceCommit ) {
709
+ ctx .Logger ().Info ("Warning: The provided commit hash appears to be invalid." )
710
+ }
711
+ }
712
+
720
713
gitCfg := sources.GitConfig {
721
714
URI : * gitScanURI ,
722
715
IncludePathsFile : * gitScanIncludePaths ,
@@ -1097,3 +1090,15 @@ func printAverageDetectorTime(e *engine.Engine) {
1097
1090
fmt .Fprintf (os .Stderr , "%s: %s\n " , detectorName , duration )
1098
1091
}
1099
1092
}
1093
+
1094
+ // Function to check if the commit is valid
1095
+ func isValidCommit (uri , commit string ) bool {
1096
+ // handle file:// urls
1097
+ repoPath , _ := strings .CutPrefix (uri , "file://" ) // remove the prefix to validate against the repo path
1098
+ output , err := exec .Command ("git" , "-C" , repoPath , "cat-file" , "-t" , commit ).Output ()
1099
+ if err != nil {
1100
+ return false
1101
+ }
1102
+
1103
+ return strings .TrimSpace (string (output )) == "commit"
1104
+ }
0 commit comments