diff --git a/README.md b/README.md index 2d288b4..be44a1b 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ docker run -d \ | GIT_SYNC_ONE_TIME | `--one-time` | exit after the first sync | false | | GIT_SYNC_MAX_SYNC_FAILURES | `--max-sync-failures` | the number of consecutive failures allowed before aborting (the first sync must succeed, -1 will retry forever after the initial sync) | 0 | | GIT_SYNC_PERMISSIONS | `--change-permissions` | the file permissions to apply to the checked-out files (0 will not change permissions at all) | 0 | +| GIT_SYNC_HOOK_COMMAND | `--sync-hook-command` | the command executed after cloning the new hash of repote repository | "" | | GIT_SYNC_WEBHOOK_URL | `--webhook-url` | the URL for a webook notification when syncs complete | "" | | GIT_SYNC_WEBHOOK_METHOD | `--webhook-method` | the HTTP method for the webhook | "POST" | | GIT_SYNC_WEBHOOK_SUCCESS_STATUS | `--webhook-success-status` | the HTTP status code indicating a successful webhook (-1 disables success checks to make webhooks fire-and-forget) | 200 | diff --git a/cmd/git-sync/main.go b/cmd/git-sync/main.go index 68e5567..7bd3e90 100644 --- a/cmd/git-sync/main.go +++ b/cmd/git-sync/main.go @@ -70,6 +70,8 @@ var flMaxSyncFailures = flag.Int("max-sync-failures", envInt("GIT_SYNC_MAX_SYNC_ "the number of consecutive failures allowed before aborting (the first sync must succeed, -1 will retry forever after the initial sync)") var flChmod = flag.Int("change-permissions", envInt("GIT_SYNC_PERMISSIONS", 0), "the file permissions to apply to the checked-out files (0 will not change permissions at all)") +var flSyncHookCommand = flag.String("sync-hook-command", envString("GIT_SYNC_HOOK_COMMAND", ""), + "the command executed after cloning the new hash of repote repository") var flWebhookURL = flag.String("webhook-url", envString("GIT_SYNC_WEBHOOK_URL", ""), "the URL for a webook notification when syncs complete (default is no webook)") @@ -653,6 +655,23 @@ func addWorktreeAndSwap(ctx context.Context, gitRoot, dest, branch, rev string, } } + // Execute the command, if requested. + if *flSyncHookCommand != "" { + log.V(0).Info("executing command for git sync hooks", "command", *flSyncHookCommand) + splitData := strings.Fields(*flSyncHookCommand) + cmd := splitData[0] + args := []string{} + if len(splitData) > 1 { + for _, v := range splitData[1:] { + args = append(args, v) + } + } + _, err = runCommand(ctx, worktreePath, cmd, args...) + if err != nil { + return err + } + } + // Flip the symlink. oldWorktree, err := updateSymlink(ctx, gitRoot, dest, worktreePath) if err != nil {