mirror of
https://github.com/taigrr/gitomatic.git
synced 2026-04-02 03:09:10 -07:00
Added -pull and -push flags
This commit is contained in:
16
README.md
16
README.md
@@ -50,10 +50,20 @@ gitomatic -privkey ~/.ssh/id_rsa <path>
|
|||||||
gitomatic -username "someone" -password "mypass" <path>
|
gitomatic -username "someone" -password "mypass" <path>
|
||||||
```
|
```
|
||||||
|
|
||||||
Other parameters:
|
If you want to pull new changes but don't create commits (or vice versa):
|
||||||
|
|
||||||
|
```
|
||||||
|
gitomatic -pull=true -push=false <path>
|
||||||
|
```
|
||||||
|
|
||||||
|
You can control how often gitomatic checks for changes:
|
||||||
|
|
||||||
```
|
```
|
||||||
gitomatic -interval 30m <path>
|
gitomatic -interval 30m <path>
|
||||||
gitomatic -author "John Doe" <path>
|
```
|
||||||
gitomatic -email "some@mail.tld" <path>
|
|
||||||
|
Change the commit author's name and email:
|
||||||
|
|
||||||
|
```
|
||||||
|
gitomatic -author "John Doe" -email "some@mail.tld" <path>
|
||||||
```
|
```
|
||||||
|
|||||||
114
main.go
114
main.go
@@ -16,6 +16,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
pull = flag.Bool("pull", true, "automatically pull changes")
|
||||||
|
push = flag.Bool("push", true, "automatically push changes")
|
||||||
author = flag.String("author", "gitomatic", "author name for git commits")
|
author = flag.String("author", "gitomatic", "author name for git commits")
|
||||||
email = flag.String("email", "gitomatic@fribbledom.com", "email address for git commits")
|
email = flag.String("email", "gitomatic@fribbledom.com", "email address for git commits")
|
||||||
interval = flag.String("interval", "1m", "how often to check for changes")
|
interval = flag.String("interval", "1m", "how often to check for changes")
|
||||||
@@ -137,65 +139,69 @@ func main() {
|
|||||||
fatal("cannot access repository: %s\n", err)
|
fatal("cannot access repository: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gitPull(r, w, auth)
|
if *pull {
|
||||||
if err != nil {
|
err = gitPull(r, w, auth)
|
||||||
fatal("cannot pull from repository: %s\n", err)
|
if err != nil {
|
||||||
}
|
fatal("cannot pull from repository: %s\n", err)
|
||||||
|
|
||||||
status, err := w.Status()
|
|
||||||
if err != nil {
|
|
||||||
fatal("cannot retrieve git status: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
changes := 0
|
|
||||||
msg := ""
|
|
||||||
for path, s := range status {
|
|
||||||
switch s.Worktree {
|
|
||||||
case git.Untracked:
|
|
||||||
log.Printf("New file detected: %s\n", path)
|
|
||||||
err := gitAdd(w, path)
|
|
||||||
if err != nil {
|
|
||||||
fatal("cannot add file: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg += fmt.Sprintf("Add %s.\n", path)
|
|
||||||
changes++
|
|
||||||
|
|
||||||
case git.Modified:
|
|
||||||
log.Printf("Modified file detected: %s\n", path)
|
|
||||||
err := gitAdd(w, path)
|
|
||||||
if err != nil {
|
|
||||||
fatal("cannot add file: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg += fmt.Sprintf("Update %s.\n", path)
|
|
||||||
changes++
|
|
||||||
|
|
||||||
case git.Deleted:
|
|
||||||
log.Printf("Deleted file detected: %s\n", path)
|
|
||||||
err := gitRemove(w, path)
|
|
||||||
if err != nil {
|
|
||||||
fatal("cannot remove file: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg += fmt.Sprintf("Remove %s.\n", path)
|
|
||||||
changes++
|
|
||||||
|
|
||||||
default:
|
|
||||||
log.Printf("%s %s %s\n", string(s.Worktree), string(s.Staging), path)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if changes == 0 {
|
if *push {
|
||||||
log.Println("No changes detected.")
|
status, err := w.Status()
|
||||||
} else {
|
|
||||||
err = gitCommit(w, msg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal("cannot commit: %s\n", err)
|
fatal("cannot retrieve git status: %s\n", err)
|
||||||
}
|
}
|
||||||
err = gitPush(r, auth)
|
|
||||||
if err != nil {
|
changes := 0
|
||||||
fatal("cannot push: %s\n", err)
|
msg := ""
|
||||||
|
for path, s := range status {
|
||||||
|
switch s.Worktree {
|
||||||
|
case git.Untracked:
|
||||||
|
log.Printf("New file detected: %s\n", path)
|
||||||
|
err := gitAdd(w, path)
|
||||||
|
if err != nil {
|
||||||
|
fatal("cannot add file: %s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg += fmt.Sprintf("Add %s.\n", path)
|
||||||
|
changes++
|
||||||
|
|
||||||
|
case git.Modified:
|
||||||
|
log.Printf("Modified file detected: %s\n", path)
|
||||||
|
err := gitAdd(w, path)
|
||||||
|
if err != nil {
|
||||||
|
fatal("cannot add file: %s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg += fmt.Sprintf("Update %s.\n", path)
|
||||||
|
changes++
|
||||||
|
|
||||||
|
case git.Deleted:
|
||||||
|
log.Printf("Deleted file detected: %s\n", path)
|
||||||
|
err := gitRemove(w, path)
|
||||||
|
if err != nil {
|
||||||
|
fatal("cannot remove file: %s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg += fmt.Sprintf("Remove %s.\n", path)
|
||||||
|
changes++
|
||||||
|
|
||||||
|
default:
|
||||||
|
log.Printf("%s %s %s\n", string(s.Worktree), string(s.Staging), path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if changes == 0 {
|
||||||
|
log.Println("No changes detected.")
|
||||||
|
} else {
|
||||||
|
err = gitCommit(w, msg)
|
||||||
|
if err != nil {
|
||||||
|
fatal("cannot commit: %s\n", err)
|
||||||
|
}
|
||||||
|
err = gitPush(r, auth)
|
||||||
|
if err != nil {
|
||||||
|
fatal("cannot push: %s\n", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user