added flag setsafedirectory

This commit is contained in:
pasha1coil 2025-04-14 12:46:33 +03:00
parent 7e556b4206
commit 82ae0dba12
2 changed files with 38 additions and 22 deletions

@ -42,6 +42,10 @@ inputs:
description: 'off/on detail progress git command in clone and fetch'
required: false
default: false
setsafedirectory:
description: Add repository path as safe.directory for Git global config by running `git config --global --add safe.directory <path>`
required: false
default: true
runs:
using: 'go'

@ -9,17 +9,18 @@ import (
)
type Config struct {
Repository string
Ref string
Token string
Path string
ServerURL string
CheckoutType CheckoutType
FetchDepth string
Clean bool
LFS bool
FetchTags bool
Progress bool
Repository string
Ref string
Token string
Path string
ServerURL string
CheckoutType CheckoutType
FetchDepth string
Clean bool
LFS bool
FetchTags bool
Progress bool
SetSafeDirectory bool
}
// todo filter, sparse-checkout, sparse-checkout-cone-mode, fetch-tags, submodules, set-safe-directory
@ -62,18 +63,25 @@ func getConfig() Config {
progressBool = true
}
setSafeDirectory := os.Getenv("INPUT_SETSAFEDIRECTORY")
setSafeDirectoryBool := true
if setSafeDirectory == "0" || setSafeDirectory == "false" || setSafeDirectory == "f" {
setSafeDirectoryBool = false
}
return Config{
Repository: os.Getenv("INPUT_REPOSITORY"),
Ref: os.Getenv("INPUT_REF"),
Token: os.Getenv("INPUT_TOKEN"),
Path: os.Getenv("INPUT_PATH"),
ServerURL: os.Getenv("INPUT_SERVERURL"),
CheckoutType: CheckoutType(os.Getenv("INPUT_CHECKOUTTYPE")),
FetchDepth: fetchDepth,
Clean: cleanBool,
LFS: lfsBool,
FetchTags: fetchTagsBool,
Progress: progressBool,
Repository: os.Getenv("INPUT_REPOSITORY"),
Ref: os.Getenv("INPUT_REF"),
Token: os.Getenv("INPUT_TOKEN"),
Path: os.Getenv("INPUT_PATH"),
ServerURL: os.Getenv("INPUT_SERVERURL"),
CheckoutType: CheckoutType(os.Getenv("INPUT_CHECKOUTTYPE")),
FetchDepth: fetchDepth,
Clean: cleanBool,
LFS: lfsBool,
FetchTags: fetchTagsBool,
Progress: progressBool,
SetSafeDirectory: setSafeDirectoryBool,
}
}
@ -93,6 +101,10 @@ func main() {
log.Fatal("field serverURL is required")
}
if cfg.SetSafeDirectory {
run("git", "config", "--global", "--add", "safe.directory", cfg.Path)
}
if cfg.Clean {
if _, err := os.Stat(cfg.Path); err == nil {
run("git", "-C", cfg.Path, "clean", "-ffdx")