feat: support cloning empty repositories#74
Merged
Conversation
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>
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
git-worktree-cloneto handle empty GitHub repositories (repos with no commits)init.defaultBranchconfig (or "master" fallback) when cloning empty reposChanges
is_remote_empty()function to detect repos with no refsresolve_initial_branch()to lib.rs for shared branch resolution--all-brancheswith empty reposTest plan
cargo test- all unit tests passcargo clippy -- -D warnings- no warningscargo fmt -- --check- formatting correctjust test-integration-clone- all new empty repo tests pass:test_clone_empty_repo- Basic empty repo cloningtest_clone_empty_repo_with_branch- Empty repo with--branchflagtest_clone_empty_repo_no_checkout- Empty repo with--no-checkouttest_clone_empty_repo_all_branches_fails- Verifies--all-branchesfails gracefullytest_clone_empty_repo_first_commit- Verifies first commit worksFixes #72
🤖 Generated with Claude Code