tj.git-extras/tests/git-scp.bats
AJ Côté 5a14757944
feat(scp): add verbose, interactive, and dry-run flags (#1261)
* feat(scp): add -v/--verbose and -i/--interactive flags

git scp/git rscp printed a diff via plain `git diff`/`git diff --stat`
with no `--no-pager` and no TTY check, blocking on the user's pager.
Add -v/--verbose to print the diff via --no-pager before syncing, and
-i/--interactive to also prompt for confirmation before the real
push/copy. Both apply to git scp and git rscp, and must precede
<remote>.

Updates man/git-scp.md and Commands.md.

* feat(scp): add -n/--dry-run flag

Add -n/--dry-run to preview a sync without changing anything: rsync
runs with -n, and git add --force / ssh ... rm are skipped outright.
Implies --verbose, since confirming or previewing with nothing shown
is useless.

Also restructures scp_and_stage's push/delete blocks from `&&`-chains
into if/then, needed to branch on dry-run, which incidentally fixes a
latent bug where a non-TTY COLOR_RESET could silently skip the real
rsync/git add/ssh rm calls.

Updates man/git-scp.md and Commands.md.

* test(scp): add coverage for -n/--dry-run and -i/--interactive abort

git-scp had no test coverage at all. Cover the two paths that need no
real remote destination: dry-run must preview without touching the
index, working tree, or remote path, and declining the interactive
confirmation must abort before anything syncs.

* feat(scp): Code review

* feat(scp): Code review
2026-07-14 19:43:00 +08:00

47 lines
968 B
Bash

# shellcheck shell=bash
source "$BATS_TEST_DIRNAME/test_util.sh"
setup_file() {
test_util.setup_file
}
setup() {
test_util.cd_test
test_util.git_init
printf '%s\n' 'hello' > tracked.txt
git add tracked.txt
git commit -m 'Initial commit'
# never created: neither test below should ever touch it
git remote add fake "$BATS_TEST_TMPDIR/never-created"
printf '%s\n' 'world' >> tracked.txt
}
@test "dry-run previews the sync without changing anything" {
run git scp -n fake
assert_success
assert_line -p 'tracked.txt'
assert_line -p 'DRY RUN'
run git status --short
assert_line -p 'M tracked.txt'
run test -e "$BATS_TEST_TMPDIR/never-created"
assert_failure
}
@test "interactive mode aborts without syncing when declined" {
run bash -c 'echo n | git scp -i fake'
assert_success
assert_line -p 'Aborted, nothing synced.'
run git status --short
assert_line -p 'M tracked.txt'
run test -e "$BATS_TEST_TMPDIR/never-created"
assert_failure
}