Skip to content

Commit

Permalink
Additional push command
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed May 20, 2023
1 parent 68b12a2 commit 4c0290c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions internal/git/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import (
"time"

"github.com/aceberg/git-syr/internal/check"
"github.com/aceberg/git-syr/internal/models"
)

// Push - executes
// git add -A
// git commit -m `date`
// git push
// in repo
func Push(path string) {
func Push(repo models.Repo) {

currentTime := time.Now()
timeString := string(currentTime.Format("2006-01-02 15:04:05"))

gitDir := "--git-dir=" + path + "/.git"
gitTree := "--work-tree=" + path
gitDir := "--git-dir=" + repo.Path + "/.git"
gitTree := "--work-tree=" + repo.Path

cmd := exec.Command("git", gitDir, gitTree, "add", "-A")
out1, err := cmd.CombinedOutput()
Expand All @@ -29,9 +30,13 @@ func Push(path string) {
out2, err := cmd.CombinedOutput()
check.IfError(err)

cmd = exec.Command("git", gitDir, gitTree, "push")
if repo.AddPush != "" {
cmd = exec.Command("git", gitDir, gitTree, "push", repo.AddPush)
} else {
cmd = exec.Command("git", gitDir, gitTree, "push")
}
out3, err := cmd.CombinedOutput()
check.IfError(err)

log.Println("INFO: Push repo", path, "\n", string(out1), "\n", string(out2), "\n", string(out3))
log.Println("INFO: Push repo", repo.Path, "\n", string(out1), "\n", string(out2), "\n", string(out3))
}
2 changes: 1 addition & 1 deletion internal/sync/sync-repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func syncRepo(repo models.Repo, quit chan bool) {
git.Pull(repo.Path)
}
if repo.Push == "yes" && git.CheckIfPush(repo.Path) {
git.Push(repo.Path)
git.Push(repo)
}
lastDate = time.Now()
}
Expand Down

0 comments on commit 4c0290c

Please sign in to comment.