2
2
import git
3
3
import pathlib
4
4
import os
5
+ import random
5
6
6
7
from git_dummy .settings import settings
7
8
@@ -22,17 +23,39 @@ def main(
22
23
settings .commits ,
23
24
help = "The number of commits to generate" ,
24
25
),
26
+ branches : int = typer .Option (
27
+ settings .branches ,
28
+ help = "The number of branches to generate" ,
29
+ ),
25
30
):
26
31
settings .name = name
27
32
settings .git_dir = os .path .join (os .path .expanduser (git_dir ), name )
28
33
settings .commits = commits
34
+ settings .branches = branches
29
35
30
36
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" )
36
59
37
60
38
61
if __name__ == "__main__" :
0 commit comments