diff --git a/README.md b/README.md index 012306c..c5adca3 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/new_repo.py b/new_repo.py index 345c5de..9c57661 100755 --- a/new_repo.py +++ b/new_repo.py @@ -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: diff --git a/test_new_repo.py b/test_new_repo.py index aa301eb..bd0dd16 100755 --- a/test_new_repo.py +++ b/test_new_repo.py @@ -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