Skip to content

feat: support cloning empty repositories#74

Merged
avihut merged 2 commits intodevelopfrom
daft-72/clone-empty
Jan 24, 2026
Merged

feat: support cloning empty repositories#74
avihut merged 2 commits intodevelopfrom
daft-72/clone-empty

Conversation

@avihut
Copy link
Owner

@avihut avihut commented Jan 24, 2026

Summary

  • Add support for git-worktree-clone to handle empty GitHub repositories (repos with no commits)
  • Previously, cloning an empty repo would fail when trying to query the remote's default branch
  • The command now uses init.defaultBranch config (or "master" fallback) when cloning empty repos

Changes

  • Add is_remote_empty() function to detect repos with no refs
  • Add resolve_initial_branch() to lib.rs for shared branch resolution
  • Update clone.rs to use orphan worktree for empty repos
  • Skip fetch/upstream setup for empty repos (no remote refs exist)
  • Add proper error message for --all-branches with empty repos
  • Add 5 integration tests for empty repo scenarios

Test plan

  • Run cargo test - all unit tests pass
  • Run cargo clippy -- -D warnings - no warnings
  • Run cargo fmt -- --check - formatting correct
  • Run just test-integration-clone - all new empty repo tests pass:
    • test_clone_empty_repo - Basic empty repo cloning
    • test_clone_empty_repo_with_branch - Empty repo with --branch flag
    • test_clone_empty_repo_no_checkout - Empty repo with --no-checkout
    • test_clone_empty_repo_all_branches_fails - Verifies --all-branches fails gracefully
    • test_clone_empty_repo_first_commit - Verifies first commit works

Fixes #72

🤖 Generated with Claude Code

Add support for git-worktree-clone to handle empty GitHub repositories
(repos with no commits). Previously, cloning an empty repo would fail
when trying to query the remote's default branch.

Changes:
- Add is_remote_empty() function to detect repos with no refs
- Add resolve_initial_branch() to lib.rs for shared branch resolution
- Update clone.rs to use orphan worktree for empty repos
- Skip fetch/upstream setup for empty repos (no remote refs exist)
- Add proper error for --all-branches with empty repos
- Add 5 integration tests for empty repo scenarios

The command now uses init.defaultBranch config (or "master" fallback)
when cloning empty repos, allowing users to start working immediately.

Fixes #72

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@avihut avihut self-assigned this Jan 24, 2026
@avihut avihut linked an issue Jan 24, 2026 that may be closed by this pull request
@avihut avihut added this to the v1.0.0 milestone Jan 24, 2026
Refactor the empty repository detection logic to be more robust:

- Try get_default_branch_remote first, only check is_remote_empty as fallback
- This ensures invalid URLs fail properly instead of being treated as empty repos
- Fix test_clone_invalid_url to use a local path that definitely fails
  (HTTP URLs may resolve to parking pages that git treats as empty repos)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@avihut avihut added the bug Something isn't working label Jan 24, 2026
@avihut avihut merged commit 93cca3b into develop Jan 24, 2026
4 checks passed
@avihut avihut deleted the daft-72/clone-empty branch January 24, 2026 09:16
avihut added a commit that referenced this pull request Jan 24, 2026
* feat: support cloning empty repositories

Add support for git-worktree-clone to handle empty GitHub repositories
(repos with no commits). Previously, cloning an empty repo would fail
when trying to query the remote's default branch.

Changes:
- Add is_remote_empty() function to detect repos with no refs
- Add resolve_initial_branch() to lib.rs for shared branch resolution
- Update clone.rs to use orphan worktree for empty repos
- Skip fetch/upstream setup for empty repos (no remote refs exist)
- Add proper error for --all-branches with empty repos
- Add 5 integration tests for empty repo scenarios

The command now uses init.defaultBranch config (or "master" fallback)
when cloning empty repos, allowing users to start working immediately.

Fixes #72

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: improve empty repo detection to handle invalid URLs

Refactor the empty repository detection logic to be more robust:

- Try get_default_branch_remote first, only check is_remote_empty as fallback
- This ensures invalid URLs fail properly instead of being treated as empty repos
- Fix test_clone_invalid_url to use a local path that definitely fails
  (HTTP URLs may resolve to parking pages that git treats as empty repos)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git-worktree-clone fails on empty GitHub repositories

1 participant