feat(new-repo): add --empty flag for bare GitHub repo creation

- Add --empty flag (auto_init=False) so remote-only migrations avoid root commit conflicts

- Reject combining --empty with --template

- Add test_empty_argument unit test and document --empty in README.md
This commit is contained in:
kiskaadee committed 2026-11-26 09:50:50 -05:00
1 parent f2613b0b3a
commit 6f9f07bb15
3 files changed
+24 -5

No files matched your search

+1
View File
@@ -44,6 +44,7 @@ Options:
-t, --template Optional GitHub template repository ('[owner/]template-name')
-M, --no-mirror Disable automatic homelab pull mirroring to Gitea
--no-clone Skip cloning the repository locally after creation
--empty Create an empty GitHub repository with auto_init=False (no initial commit)
--as PERSONA Persona / login identity to provision as (e.g. anneux)
-h, --help Show help message and exit
```
+13 -5
View File
@@ -1086,6 +1086,12 @@ def parse_args() -> argparse.Namespace:
default=False,
help="Skip cloning the repository locally after creation",
)
parser.add_argument(
"--empty",
action="store_true",
default=False,
help="Create an empty GitHub repository with auto_init=False (no initial README or license commit)",
)
parser.add_argument(
"--as",
dest="as_persona",
@@ -1240,19 +1246,21 @@ def main() -> None:
print(f" Mode: Greenfield creation at '{target_dir}'")
# 2. Provision GitHub Primary Repository
if args.empty and args.template:
print("❌ Error: --empty cannot be combined with --template.", file=sys.stderr)
sys.exit(1)
github_html_url: str
github_ssh_url: str
try:
if is_existing_git:
if is_existing_git or args.empty:
print(
"🏗️ Creating empty primary repository on GitHub (preserving local history)..."
"🏗️ Creating empty primary repository on GitHub (auto_init=False)..."
)
res = github_client.create_repo(
res = github_client.create_empty_repo(
name=repo_name,
private=is_private,
description=args.description,
auto_init=False,
license_template="",
org=target_org,
)
elif args.template:
+10
View File
@@ -43,9 +43,19 @@ class TestArgParsing(unittest.TestCase):
self.assertIsNone(args.template)
self.assertFalse(args.no_mirror)
self.assertFalse(args.no_clone)
self.assertFalse(args.empty)
self.assertIsNone(args.as_persona)
self.assertIsNone(args.gitea_mirror)
def test_empty_argument(self) -> None:
import sys
sys.argv = ["new-repo", "sample-project", "--empty", "--no-mirror", "--no-clone"]
args = parse_args()
self.assertTrue(args.empty)
self.assertTrue(args.no_mirror)
self.assertTrue(args.no_clone)
def test_as_persona_argument(self) -> None:
import sys