Skip to content

Commit 37015c1

Browse files
feat: consider git urls as source
1 parent 592c70f commit 37015c1

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

internal/commands/scan.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3826,13 +3826,18 @@ func validateGitCommitHistoryContext(cmd *cobra.Command) bool {
38263826
return true
38273827
}
38283828

3829-
// hasGitRepository checks if the source directory contains a Git repository
3829+
// hasGitRepository checks if the source directory contains a Git repository or is a Git URL
38303830
func hasGitRepository(source string) bool {
38313831
if source == "" {
38323832
return false
38333833
}
38343834

38353835
sourceTrimmed := strings.TrimSpace(source)
3836+
3837+
if util.IsGitURL(sourceTrimmed) {
3838+
return true
3839+
}
3840+
38363841
info, err := os.Stat(sourceTrimmed)
38373842
if err != nil || !info.IsDir() {
38383843
return false

internal/commands/scan_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4793,6 +4793,56 @@ func TestGetGitCommitHistoryValue(t *testing.T) {
47934793
expectedValue: "false",
47944794
expectWarnings: "",
47954795
},
4796+
{
4797+
name: "Flag true with HTTPS GitHub URL - returns true",
4798+
flagValue: "true",
4799+
scanTypes: "scs",
4800+
scsEngines: "secret-detection",
4801+
source: "https://github.com/user/repo.git",
4802+
ffEnabled: true,
4803+
expectedValue: "true",
4804+
expectWarnings: "",
4805+
},
4806+
{
4807+
name: "Flag true with HTTPS GitLab URL - returns true",
4808+
flagValue: "true",
4809+
scanTypes: "scs",
4810+
scsEngines: "secret-detection",
4811+
source: "https://gitlab.com/user/repo.git",
4812+
ffEnabled: true,
4813+
expectedValue: "true",
4814+
expectWarnings: "",
4815+
},
4816+
{
4817+
name: "Flag true with SSH git@ format URL - returns true",
4818+
flagValue: "true",
4819+
scanTypes: "scs",
4820+
scsEngines: "secret-detection",
4821+
source: "[email protected]:user/repo.git",
4822+
ffEnabled: true,
4823+
expectedValue: "true",
4824+
expectWarnings: "",
4825+
},
4826+
{
4827+
name: "Flag true with SSH protocol URL - returns true",
4828+
flagValue: "true",
4829+
scanTypes: "scs",
4830+
scsEngines: "secret-detection",
4831+
source: "ssh://[email protected]/user/repo.git",
4832+
ffEnabled: true,
4833+
expectedValue: "true",
4834+
expectWarnings: "",
4835+
},
4836+
{
4837+
name: "Flag false with git URL - returns false",
4838+
flagValue: "false",
4839+
scanTypes: "scs",
4840+
scsEngines: "secret-detection",
4841+
source: "https://github.com/user/repo.git",
4842+
ffEnabled: true,
4843+
expectedValue: "false",
4844+
expectWarnings: "",
4845+
},
47964846
}
47974847

47984848
for _, tt := range tests {

0 commit comments

Comments
 (0)