-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git: allow cloning commit shas not referenced by branch/tag
Signed-off-by: Justin Chadwell <[email protected]>
- Loading branch information
Showing
4 changed files
with
83 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package gitutil | ||
|
||
import "regexp" | ||
func IsCommitSHA(str string) bool { | ||
if len(str) != 40 { | ||
return false | ||
} | ||
|
||
var validHex = regexp.MustCompile(`^[a-f0-9]{40}$`) | ||
for _, ch := range str { | ||
if ch >= '0' && ch <= '9' { | ||
continue | ||
} | ||
if ch >= 'a' && ch <= 'f' { | ||
continue | ||
} | ||
return false | ||
} | ||
|
||
func IsCommitSHA(str string) bool { | ||
return validHex.MatchString(str) | ||
return true | ||
} |