Skip to content

Commit 3da8182

Browse files
committed
feat(cli): add --force flag to skip git repo root check
Adds --force flag to init command that allows initialization in directories that aren't git repository roots. Useful for edge cases or non-git projects. Also adds integration test to verify the flag works correctly.
1 parent 7d6a11f commit 3da8182

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

.github/workflows/integration-test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,31 @@ jobs:
381381
echo "✅ init correctly refuses to remove last platform"
382382
rm -rf "$INIT_DIR"
383383
384+
- name: "Test: init --force skips git repo check"
385+
shell: bash
386+
run: |
387+
INIT_DIR=$(mktemp -d)
388+
cd "$INIT_DIR"
389+
# Do NOT run git init - this is intentionally not a git repo
390+
391+
# Without --force, should fail
392+
if $GITHUB_WORKSPACE/tests/${{ matrix.binary }} init --current-platform-only 2>&1; then
393+
echo "ERROR: init should fail without --force in non-git directory"
394+
exit 1
395+
fi
396+
397+
# With --force, should succeed
398+
$GITHUB_WORKSPACE/tests/${{ matrix.binary }} init --current-platform-only --force
399+
400+
# Verify files were created
401+
if [ ! -f ".rnr/config.yaml" ]; then
402+
echo "ERROR: .rnr/config.yaml not created with --force"
403+
exit 1
404+
fi
405+
406+
echo "✅ init --force correctly skips git repo check"
407+
rm -rf "$INIT_DIR"
408+
384409
# ==================== Error Cases ====================
385410

386411
- name: "Test: nonexistent task (should fail)"

src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ pub struct InitArgs {
5151
/// Show currently configured platforms
5252
#[arg(long)]
5353
pub show_platforms: bool,
54+
55+
/// Skip git repository root check
56+
#[arg(long)]
57+
pub force: bool,
5458
}

src/commands/init.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ pub fn run(args: &InitArgs) -> Result<()> {
3838
return Ok(());
3939
}
4040

41-
// Error if not at git repo root
42-
if !is_git_repo_root()? {
41+
// Error if not at git repo root (unless --force is used)
42+
if !args.force && !is_git_repo_root()? {
4343
bail!(
4444
"This directory does not appear to be a git repository root.\n\
45-
rnr must be initialized at the root of a git repository.\n\
46-
Please run 'rnr init' from the directory containing your .git folder."
45+
rnr is typically initialized at the root of a git repository.\n\
46+
Use --force to initialize anyway, or run from the directory containing your .git folder."
4747
);
4848
}
4949

0 commit comments

Comments
 (0)