MCPcopy
hub / github.com/jesseduffield/lazygit / CreateRepoHistory

Method CreateRepoHistory

pkg/integration/components/shell.go:284–345  ·  view source on GitHub ↗

This creates a repo history of commits It uses a branching strategy where each feature branch is directly branched off of the master branch Only to be used in demos

()

Source from the content-addressed store, hash-verified

282// of the master branch
283// Only to be used in demos
284func (self *Shell) CreateRepoHistory() *Shell {
285 authors := []string{"Yang Wen-li", "Siegfried Kircheis", "Paul Oberstein", "Oscar Reuenthal", "Fredrica Greenhill"}
286
287 numAuthors := 5
288 numBranches := 10
289 numInitialCommits := 20
290 maxCommitsPerBranch := 5
291 // Each commit will happen on a separate day
292 repoStartDaysAgo := 100
293
294 totalCommits := 0
295
296 // Generate commits
297 for i := range numInitialCommits {
298 author := authors[i%numAuthors]
299 commitMessage := RandomCommitMessages[totalCommits%len(RandomCommitMessages)]
300
301 self.SetAuthor(author, "")
302 self.EmptyCommitDaysAgo(commitMessage, repoStartDaysAgo-totalCommits)
303 totalCommits++
304 }
305
306 // Generate branches and merges
307 for i := range numBranches {
308 // We'll have one author creating all the commits in the branch
309 author := authors[i%numAuthors]
310 branchName := RandomBranchNames[i%len(RandomBranchNames)]
311
312 // Choose a random commit within the last 20 commits on the master branch
313 lastMasterCommit := totalCommits - 1
314 commitOffset := rand.Intn(min(lastMasterCommit, 5)) + 1
315
316 // Create the feature branch and checkout the chosen commit
317 self.NewBranchFrom(branchName, fmt.Sprintf("master~%d", commitOffset))
318
319 numCommitsInBranch := rand.Intn(maxCommitsPerBranch) + 1
320 for range numCommitsInBranch {
321 commitMessage := RandomCommitMessages[totalCommits%len(RandomCommitMessages)]
322
323 self.SetAuthor(author, "")
324 self.EmptyCommitDaysAgo(commitMessage, repoStartDaysAgo-totalCommits)
325 totalCommits++
326 }
327
328 self.Checkout("master")
329
330 prevCommitterDate := os.Getenv("GIT_COMMITTER_DATE")
331 prevAuthorDate := os.Getenv("GIT_AUTHOR_DATE")
332
333 commitDate := time.Now().Add(time.Duration(totalCommits-repoStartDaysAgo) * time.Hour * 24)
334 os.Setenv("GIT_COMMITTER_DATE", commitDate.Format(time.RFC3339))
335 os.Setenv("GIT_AUTHOR_DATE", commitDate.Format(time.RFC3339))
336
337 // Merge branch into master
338 self.RunCommand([]string{"git", "merge", "--no-ff", branchName, "-m", fmt.Sprintf("Merge %s into master", branchName)})
339
340 os.Setenv("GIT_COMMITTER_DATE", prevCommitterDate)
341 os.Setenv("GIT_AUTHOR_DATE", prevAuthorDate)

Callers 2

commit_graph.goFile · 0.80

Calls 8

SetAuthorMethod · 0.95
EmptyCommitDaysAgoMethod · 0.95
NewBranchFromMethod · 0.95
CheckoutMethod · 0.95
RunCommandMethod · 0.95
GetenvMethod · 0.80
SprintfMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected