@@ -7,19 +7,25 @@ load '../helpers/fixtures'
77
88# Path to enable_core.sh
99ENABLE_CORE=" ${BATS_TEST_DIRNAME} /../../lib/enable_core.sh"
10+ ORIGINAL_HOME=" $HOME "
1011
1112setup () {
1213 # Create temporary test directory
1314 TEST_DIR=" $( mktemp -d) "
1415 cd " $TEST_DIR "
1516
17+ # Isolate HOME so tests that write to ~/.ralph don't leak to real home dir
18+ export HOME=" $TEST_DIR /home"
19+ mkdir -p " $HOME "
20+
1621 # Source the library (disable set -e for testing)
1722 set +e
1823 source " $ENABLE_CORE "
1924 set -e
2025}
2126
2227teardown () {
28+ export HOME=" $ORIGINAL_HOME "
2329 if [[ -n " $TEST_DIR " ]] && [[ -d " $TEST_DIR " ]]; then
2430 cd /
2531 rm -rf " $TEST_DIR "
386392 content=$( cat test_file.txt)
387393 [[ " $content " == " original content" ]]
388394}
395+
396+ # =============================================================================
397+ # .GITIGNORE CREATION (Issue #174) (4 tests)
398+ # =============================================================================
399+
400+ @test " enable_ralph_in_directory creates .gitignore when template exists" {
401+ # HOME is already isolated to TEST_DIR/home by setup()
402+ mkdir -p " $HOME /.ralph/templates"
403+ cat > " $HOME /.ralph/templates/.gitignore" << 'EOF '
404+ .ralph/.call_count
405+ .ralph/.last_reset
406+ .ralph/status.json
407+ EOF
408+
409+ export ENABLE_FORCE=" false"
410+ export ENABLE_SKIP_TASKS=" true"
411+ export ENABLE_PROJECT_NAME=" test-project"
412+
413+ run enable_ralph_in_directory
414+
415+ assert_success
416+ [[ -f " .gitignore" ]]
417+ grep -q " .ralph/.call_count" .gitignore
418+ }
419+
420+ @test " enable_ralph_in_directory skips .gitignore when one exists and no force" {
421+ mkdir -p " $HOME /.ralph/templates"
422+ echo " .ralph/.call_count" > " $HOME /.ralph/templates/.gitignore"
423+
424+ # Pre-existing .gitignore
425+ echo " my-custom-ignore" > .gitignore
426+
427+ export ENABLE_FORCE=" false"
428+ export ENABLE_SKIP_TASKS=" true"
429+ export ENABLE_PROJECT_NAME=" test-project"
430+
431+ run enable_ralph_in_directory
432+
433+ assert_success
434+ # Should preserve existing .gitignore content
435+ grep -q " my-custom-ignore" .gitignore
436+ }
437+
438+ @test " enable_ralph_in_directory overwrites .gitignore with force" {
439+ mkdir -p " $HOME /.ralph/templates"
440+ echo " .ralph/.call_count" > " $HOME /.ralph/templates/.gitignore"
441+
442+ # Pre-existing .gitignore with different content
443+ echo " my-custom-ignore" > .gitignore
444+
445+ export ENABLE_FORCE=" true"
446+ export ENABLE_SKIP_TASKS=" true"
447+ export ENABLE_PROJECT_NAME=" test-project"
448+
449+ run enable_ralph_in_directory
450+
451+ assert_success
452+ # Should have template content, not old content
453+ grep -q " .ralph/.call_count" .gitignore
454+ ! grep -q " my-custom-ignore" .gitignore
455+ }
456+
457+ @test " enable_ralph_in_directory succeeds when templates dir exists but .gitignore is missing" {
458+ # Templates dir exists but no .gitignore template inside
459+ mkdir -p " $HOME /.ralph/templates"
460+
461+ export ENABLE_FORCE=" false"
462+ export ENABLE_SKIP_TASKS=" true"
463+ export ENABLE_PROJECT_NAME=" test-project"
464+
465+ run enable_ralph_in_directory
466+
467+ assert_success
468+ # .gitignore should not be created
469+ [[ ! -f " .gitignore" ]]
470+ }
0 commit comments