diff --git a/checkout-go/action.yml b/checkout-go/action.yml index 1d4eaf3..dba0582 100644 --- a/checkout-go/action.yml +++ b/checkout-go/action.yml @@ -26,6 +26,10 @@ inputs: description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.' required: false default: 1 + clean: + description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching' + required: false + default: true runs: using: 'go' diff --git a/checkout-go/main.go b/checkout-go/main.go index 148f986..e78a5bc 100644 --- a/checkout-go/main.go +++ b/checkout-go/main.go @@ -16,8 +16,11 @@ type Config struct { ServerURL string CheckoutType CheckoutType FetchDepth string + Clean bool } +// todo lfs + type CheckoutType string const ( @@ -30,6 +33,14 @@ func getConfig() Config { if fetchDepth == "" || fetchDepth == "0" { fetchDepth = "1" } + + clean := os.Getenv("INPUT_CLEAN") + cleanBool := true + + if clean == "0" || clean == "false" || clean == "f" { + cleanBool = false + } + return Config{ Repository: os.Getenv("INPUT_REPOSITORY"), Ref: os.Getenv("INPUT_REF"), @@ -38,6 +49,7 @@ func getConfig() Config { ServerURL: os.Getenv("INPUT_SERVERURL"), CheckoutType: CheckoutType(os.Getenv("INPUT_CHECKOUTTYPE")), FetchDepth: fetchDepth, + Clean: cleanBool, } } @@ -57,6 +69,15 @@ func main() { log.Fatal("field serverURL is required") } + if cfg.Clean { + if _, err := os.Stat(cfg.Path); err == nil { + run("git", "-C", cfg.Path, "clean", "-ffdx") + run("git", "-C", cfg.Path, "reset", "--hard", "HEAD") + } else { + log.Println(fmt.Sprintf("not path-%s directory for cleaning", cfg.Path)) + } + } + cloneURL := cfg.CheckoutType.GenerateCloneURL(cfg) fmt.Println("Cloning", cloneURL, "into", cfg.Path) @@ -70,6 +91,7 @@ func main() { } func run(name string, args ...string) { + fmt.Println("git command: ", name, strings.Join(args, " ")) cmd := exec.Command(name, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr