-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,10 +50,20 @@ gitomatic -privkey ~/.ssh/id_rsa <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 -author "John Doe" <path> | ||
gitomatic -email "[email protected]" <path> | ||
``` | ||
|
||
Change the commit author's name and email: | ||
|
||
``` | ||
gitomatic -author "John Doe" -email "[email protected]" <path> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ import ( | |
) | ||
|
||
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") | ||
email = flag.String("email", "[email protected]", "email address for git commits") | ||
interval = flag.String("interval", "1m", "how often to check for changes") | ||
|
@@ -137,65 +139,69 @@ func main() { | |
fatal("cannot access repository: %s\n", err) | ||
} | ||
|
||
err = gitPull(r, w, auth) | ||
if err != nil { | ||
fatal("cannot pull from repository: %s\n", err) | ||
if *pull { | ||
err = gitPull(r, w, auth) | ||
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) | ||
} | ||
if *push { | ||
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) | ||
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) | ||
} | ||
} | ||
|
||
msg += fmt.Sprintf("Add %s.\n", path) | ||
changes++ | ||
|
||
case git.Modified: | ||
log.Printf("Modified file detected: %s\n", path) | ||
err := gitAdd(w, path) | ||
if changes == 0 { | ||
log.Println("No changes detected.") | ||
} else { | ||
err = gitCommit(w, msg) | ||
if err != nil { | ||
fatal("cannot add file: %s\n", err) | ||
fatal("cannot commit: %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) | ||
err = gitPush(r, auth) | ||
if err != nil { | ||
fatal("cannot remove file: %s\n", err) | ||
fatal("cannot push: %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) | ||
} | ||
} | ||
|
||
|