only push if there are no changes

pull/27/head
Marcusk19 2 years ago
parent 03e893c3fb
commit cfb3f90fb1

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

Loading…
Cancel
Save