Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
.PHONY: lint

lint:
golangci-lint run

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}
15 changes: 8 additions & 7 deletions common/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package common

import (
"bytes"
"fmt"
"os"
"os/exec"
"sort"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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, "=")
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
},
Expand Down