only push on changes (#27)

Only push if there are no changes for sync command
pull/28/head
Marcus Kok 2 years ago committed by GitHub
parent 7d4634ff92
commit 86d93daa0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -18,8 +18,8 @@ dotctl init
dotctl add ~/.config/nvim
# create symlinks
dotctl link
# sync changes
dotctl sync -r <your-git-repo>
# sync
dotctl sync -r <remote-repo>
```
## Development

@ -108,6 +108,9 @@ func runSyncCommand(cmd *cobra.Command, args []string) {
passwordVal, err := password.Run()
CheckIfError(err)
fmt.Println("Pulling from remote")
err = w.Pull(&git.PullOptions{
RemoteName: "origin",
Auth: &http.BasicAuth {
@ -122,6 +125,14 @@ func runSyncCommand(cmd *cobra.Command, args []string) {
fmt.Fprintf(cmd.OutOrStdout(), "successfully pulled from %s", origin)
}
status, err := w.Status()
if err != nil {
log.Fatalln("Error getting status", err)
}
if !status.IsClean() {
fmt.Println("Changes detected, committing and pushing...")
err = gitAddFiles(w, FileSystem)
if err != nil {
log.Fatalf("Could not add files: %s\n", err)
@ -157,6 +168,7 @@ func runSyncCommand(cmd *cobra.Command, args []string) {
},
})
CheckIfError(err)
viper.WriteConfig()
}
viper.WriteConfig()
}

Loading…
Cancel
Save