diff --git a/Makefile b/Makefile index 1ab51ac..6e059cb 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .PHONY: lint - + lint: golangci-lint run @@ -7,6 +7,7 @@ test: go test ./... install: - go install . + go build -o git-auto-sync . cd daemon && go build -o git-auto-sync-daemon . - cd daemon && mv git-auto-sync-daemon ${GOPATH}/bin/ + sudo mv git-auto-sync ${GOPATH} + cd daemon && sudo mv git-auto-sync-daemon ${GOPATH} diff --git a/common/commit.go b/common/commit.go index e6d4a30..6aa1b75 100644 --- a/common/commit.go +++ b/common/commit.go @@ -2,7 +2,6 @@ package common import ( "bytes" - "fmt" "os" "os/exec" "sort" @@ -63,6 +62,13 @@ func commit(repoConfig RepoConfig) error { sort.Strings(commitMsg) msg := strings.Join(commitMsg, "\n") + rawConfig, err := repo.Storer.Config() + autoSyncSection := rawConfig.Raw.Section("auto-sync") + header := autoSyncSection.Options.Get("header") + if header == "" { // Concerning that an explicit "" is getting overridden... + header = "Git Auto Sync" + } + msg = header+"\n"+msg if !hasChanges { return nil @@ -93,10 +99,6 @@ func GitCommand(repoConfig RepoConfig, args []string) (bytes.Buffer, error) { statusCmd.Env = toEnvString(repoConfig) err := statusCmd.Run() - if hasEnvVariable(os.Environ(), "SSH_AUTH_SOCK") && !hasEnvVariable(repoConfig.Env, "SSH_AUTH_SOCK") { - fmt.Println("WARNING: SSH_AUTH_SOCK env variable isn't being passed") - } - if err != nil { fullCmd := "git " + strings.Join(args, " ") err := tracerr.Errorf("%w: Command: %s\nEnv: %s\nStdOut: %s\nStdErr: %s", err, fullCmd, statusCmd.Env, outb.String(), errb.String()) @@ -106,8 +108,7 @@ func GitCommand(repoConfig RepoConfig, args []string) (bytes.Buffer, error) { } func toEnvString(repoConfig RepoConfig) []string { - vals := repoConfig.Env - vals = append(vals, repoConfig.Env...) + vals := append([]string(nil), repoConfig.Env...) for _, s := range os.Environ() { parts := strings.Split(s, "=") diff --git a/main.go b/main.go index 11ef3f1..874139f 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,13 @@ func main() { Name: "watch", Aliases: []string{"monitor", "w", "m"}, Usage: "Monitor a folder for changes", + Flags: []cli.Flag{ + &cli.StringSliceFlag{ + Name: "env", + Aliases: []string{"e"}, + Usage: "Env variables to pass", + }, + }, Action: func(ctx *cli.Context) error { repoPath, err := os.Getwd() if err != nil { @@ -40,6 +47,7 @@ func main() { if err != nil { return tracerr.Wrap(err) } + cfg.Env = append(cfg.Env, ctx.StringSlice("env")...) return common.WatchForChanges(cfg) },