22import git
33import pathlib
44import os
5+ import random
56
67from 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
3861if __name__ == "__main__" :
0 commit comments