Skip to content

Commit 5f47cb8

Browse files
Add --branches option to allow multiple branches
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent 47cd954 commit 5f47cb8

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

git_dummy/__main__.py

+28-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import git
33
import pathlib
44
import os
5+
import random
56

67
from git_dummy.settings import settings
78

@@ -22,17 +23,39 @@ def main(
2223
settings.commits,
2324
help="The number of commits to generate",
2425
),
26+
branches: int = typer.Option(
27+
settings.branches,
28+
help="The number of branches to generate",
29+
),
2530
):
2631
settings.name = name
2732
settings.git_dir = os.path.join(os.path.expanduser(git_dir), name)
2833
settings.commits = commits
34+
settings.branches = branches
2935

3036
repo = git.Repo.init(settings.git_dir)
31-
32-
for i in range(1, settings.commits + 1):
33-
open(os.path.join(settings.git_dir, str(i)), "a").close()
34-
repo.index.add([str(i)])
35-
repo.index.commit(f"Dummy commit #{i}")
37+
repo.config_writer().set_value("init", "defaultBranch", "main").release()
38+
39+
for c in range(1, settings.commits + 1):
40+
open(os.path.join(settings.git_dir, f"main.{c}"), "a").close()
41+
repo.index.add([f"main.{c}"])
42+
repo.index.commit(f"Dummy commit #{c} on main")
43+
44+
while settings.branches - 1 > 0:
45+
repo.git.checkout("main")
46+
r = random.choice(range(1, settings.commits))
47+
repo.git.checkout(f"HEAD~{r}")
48+
branch_name = f"branch{settings.branches - 1}"
49+
repo.create_head(branch_name)
50+
repo.git.checkout(branch_name)
51+
for d in range(settings.commits - r + 1, settings.commits + 1):
52+
open(os.path.join(settings.git_dir, f"{branch_name}.{d}"), "a").close()
53+
repo.index.add([f"{branch_name}.{d}"])
54+
repo.index.commit(f"Dummy commit #{d} on {branch_name}")
55+
56+
settings.branches -= 1
57+
58+
repo.git.checkout("main")
3659

3760

3861
if __name__ == "__main__":

git_dummy/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Settings(BaseSettings):
66
name = "dummy"
77
git_dir = pathlib.Path().cwd()
88
commits = 5
9+
branches = 1
910

1011
class Config:
1112
env_prefix = "git_dummy_"

0 commit comments

Comments
 (0)