From ec8ab9dfeeb64540a735f1eac68c5109a804766f Mon Sep 17 00:00:00 2001 From: Marcus Kok Date: Thu, 25 Apr 2024 17:07:58 -0400 Subject: [PATCH] add confirmation on sync before pushing changes --- cmd/sync.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cmd/sync.go b/cmd/sync.go index d5d02b8..d7c956a 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -132,11 +132,24 @@ func runSyncCommand(cmd *cobra.Command, args []string) { } if !status.IsClean() { - fmt.Println("Changes detected, committing and pushing...") + fmt.Println("Changes detected, do you want to push them?") + confirm := promptui.Prompt { + Label: "commit and push changes", + IsConfirm: true, + } + + _, err := confirm.Run() + if err != nil { + fmt.Println("Will not push changes") + return + } + + fmt.Println("Pushing changes...") err = gitAddFiles(w, FileSystem) if err != nil { log.Fatalf("Could not add files: %s\n", err) + return } commitMessage := "backup " + time.Now().String() @@ -172,8 +185,12 @@ func runSyncCommand(cmd *cobra.Command, args []string) { } // a pull deletes the dotctl config from the filesystem, need to recreate it + rewriteConfig() +} + +func rewriteConfig() { fs := UseFilesystem() - err = fs.MkdirAll(path.Join(DotfilePath, "dotctl"), 0755) + err := fs.MkdirAll(path.Join(DotfilePath, "dotctl"), 0755) if err != nil { log.Fatalf("Unable to create dotfile structure: %s", error.Error(err)) }