From 7f64d79bbe3fb5a2149fadfe026d788e5f3bca68 Mon Sep 17 00:00:00 2001 From: Zac Date: Tue, 28 Aug 2018 10:46:48 -0700 Subject: [PATCH] Updated main to add the env var and send a post request --- cmd/git-sync/main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/git-sync/main.go b/cmd/git-sync/main.go index 789befa..403c5fb 100644 --- a/cmd/git-sync/main.go +++ b/cmd/git-sync/main.go @@ -33,6 +33,7 @@ import ( "strconv" "strings" "time" + "http" "github.com/thockin/glogr" "github.com/thockin/logr" @@ -61,6 +62,8 @@ var flMaxSyncFailures = flag.Int("max-sync-failures", envInt("GIT_SYNC_MAX_SYNC_ "the number of consecutive failures allowed before aborting (the first pull must succeed, -1 disables aborting for any number of failures 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") +var flSymlinkUpdatePostUrl = flag.String("symlink-update-post-url", envString("GIT_SYNC_SYMLINK_UPDATE_POST_URL", ""), + "a command to run when the symlink is updated") var flUsername = flag.String("username", envString("GIT_SYNC_USERNAME", ""), "the username to use") @@ -289,6 +292,15 @@ func updateSymlink(ctx context.Context, gitRoot, link, newDir string) error { log.V(1).Infof("pruned old worktrees") } + + // If there is a symlink update callback, call it + if len(*flSymlinkUpdateCallback) > 0 { + // Send the post request + resp, err := http.NewRequest("POST", url, nil) + if err != nil { + return fmt.Errorf("error sending symlink update callback post request: %v", err) + } + } return nil }