Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust object format interface #28469

Merged
merged 16 commits into from
Dec 17, 2023
8 changes: 8 additions & 0 deletions modules/git/object_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ var sha1Pattern = regexp.MustCompile(`^[0-9a-f]{4,40}$`)

const Sha1ObjectFormatName = "sha1"
lunny marked this conversation as resolved.
Show resolved Hide resolved

func IsValidObjectFormat(name string) bool {
switch name {
lunny marked this conversation as resolved.
Show resolved Hide resolved
case Sha1ObjectFormatName:
return true
}
return false
}

type ObjectFormat interface {
String() string

Expand Down
3 changes: 3 additions & 0 deletions modules/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ func InitRepository(ctx context.Context, repoPath string, bare bool, objectForma
if objectFormatName == "" {
objectFormatName = Sha1ObjectFormatName
}
if !IsValidObjectFormat(objectFormatName) {
return fmt.Errorf("invalid object format: %s", objectFormatName)
}
cmd.AddOptionValues("--object-format", objectFormatName)
}
if bare {
Expand Down
Loading