diff --git a/cmd/root.go b/cmd/root.go index 3f0b233..e645b7c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -22,7 +22,6 @@ var rootCmd = &cobra.Command{ by dynamically mounting them using a git-volume.yaml manifest. "Keep code in Git, mount environments as volumes."`, - SilenceErrors: true, } // Execute adds all child commands to the root command and sets flags appropriately. diff --git a/cmd/sync.go b/cmd/sync.go index 24978e9..d55ef3d 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -9,7 +9,7 @@ import ( ) var ( - dryRun bool + syncDryRun bool relativeLinks bool ) @@ -34,7 +34,7 @@ it looks for it in the main Git worktree (inheritance).`, } return gv.Sync(gitvolume.SyncOptions{ - DryRun: dryRun, + DryRun: syncDryRun, RelativeLinks: relativeLinks, }) }, @@ -42,6 +42,6 @@ it looks for it in the main Git worktree (inheritance).`, func init() { rootCmd.AddCommand(syncCmd) - syncCmd.Flags().BoolVar(&dryRun, "dry-run", false, "show what would be done without making changes") + syncCmd.Flags().BoolVar(&syncDryRun, "dry-run", false, "show what would be done without making changes") syncCmd.Flags().BoolVar(&relativeLinks, "relative", false, "create relative symlinks instead of absolute") } diff --git a/cmd/unsync.go b/cmd/unsync.go index a735616..8a17cd9 100644 --- a/cmd/unsync.go +++ b/cmd/unsync.go @@ -8,6 +8,9 @@ import ( "github.com/spf13/cobra" ) +// unsyncDryRun is the local flag for the unsync command +var unsyncDryRun bool + // unsyncCmd represents the unsync command var unsyncCmd = &cobra.Command{ Use: "unsync", @@ -29,12 +32,12 @@ to the source before deleting. If changed, it skips deletion to prevent data los } return gv.Unsync(gitvolume.UnsyncOptions{ - DryRun: dryRun, + DryRun: unsyncDryRun, }) }, } func init() { rootCmd.AddCommand(unsyncCmd) - unsyncCmd.Flags().BoolVar(&dryRun, "dry-run", false, "show what would be done without making changes") + unsyncCmd.Flags().BoolVar(&unsyncDryRun, "dry-run", false, "show what would be done without making changes") } diff --git a/gv b/gv deleted file mode 100755 index 20703f2..0000000 Binary files a/gv and /dev/null differ diff --git a/test/integration.sh b/test/integration.sh index 220e3b3..d5bf224 100755 --- a/test/integration.sh +++ b/test/integration.sh @@ -384,6 +384,68 @@ fi # Clean up for next tests rm -rf copied_dir +# ----------------------------------------------------------------------------- +# Test: Error Visibility (Bad Flag) +# ----------------------------------------------------------------------------- +log "TEST" "Testing Error Visibility (Bad Flag)..." + +# Capture stdout and stderr +if OUTPUT=$("$GV_BIN" sync --unknown-flag 2>&1); then + fail "Command should have failed but succeeded" +else + # Command failed as expected, check output for error message + if grep -q "unknown flag: --unknown-flag" <<< "$OUTPUT"; then + pass "Error message visible on stderr/stdout" + else + fail "Error message NOT found in output" + echo "Output: $OUTPUT" + fi +fi + +# ----------------------------------------------------------------------------- +# Test: Sync Dry Run Isolation +# ----------------------------------------------------------------------------- +log "TEST" "Testing Sync Dry Run..." + +# Set up a volume to sync +echo "DATA" > source.txt +cat > git-volume.yaml </dev/null 2>&1 +git commit -m "init" >/dev/null 2>&1 + +# Run sync with dry-run +"$GV_BIN" sync --dry-run >/dev/null + +if [[ ! -f "target.txt" ]]; then + pass "sync --dry-run did not create file" +else + fail "sync --dry-run CREATED file (meant to be dry run)" +fi + +# ----------------------------------------------------------------------------- +# Test: Unsync Dry Run Isolation +# ----------------------------------------------------------------------------- +log "TEST" "Testing Unsync Dry Run..." + +# Actually sync first +"$GV_BIN" sync >/dev/null +if [[ ! -f "target.txt" ]]; then + fail "Setup failed: sync did not create file" +fi + +# Run unsync with dry-run +"$GV_BIN" unsync --dry-run >/dev/null + +if [[ -f "target.txt" ]]; then + pass "unsync --dry-run did not remove file" +else + fail "unsync --dry-run REMOVED file (meant to be dry run)" +fi + # ----------------------------------------------------------------------------- # Summary # -----------------------------------------------------------------------------