Skip to content

hhourani27/git-repo-generator

Repository files navigation

git-repo-generator

A CLI tool to generate Git repositories with specific configuration and commit histories, to quickly test your Git tools and workflows.

Quick Start

npx git-repo-generator

will generate in the current directory a Git repository with

  • A main branch
  • A test.txt file in the working directory
  • 3 commits
1--2--3  main

Options

npx git-repo-generator --dir repo-test --commits 5
Option Description
-d
--dir
Directory of Git repository (default: . current directory )
-c
--commits
Number of commits (default: 3)
Ignored if --file is provided (see below)
-f
--file
Configuration file (see below)
-h
--help
Display command doc

Configuration file

You can provide a YAML file that describes your Git repo configuration and history

npx git-repo-generator -d repo-test -f git.yaml

Simple configuration file

log:
  - init
  - create file test.txt
  - commit
  - branch develop
  - checkout develop
  - create file test2.txt
  - commit
  - checkout main
  - merge develop
  - tag v1.0

will generate the following Git repository

  --2--    < develop
 /     \
1-------3  < main < v1.0

More complex configuration file

log:
  - init:
      defaultBranch: main
  - create file:
      file: test.txt
      content: line 1
  - commit:
      message: first commit
      author: user1
      email: user1@example.com
  - branch develop
  - checkout develop
  - change content:
      file: test.txt
      content: |
        line 1
        line 2
  - commit
  - checkout main
  - merge:
      theirs: develop
      message: merge commit
  - tag:
      name: v1.0
      annotated: true

conf:
  author: user
  email: user@example.com

Log commands

Command Expressions Notes
Init repository
- init
- init:
   defaultBranch: master
If omitted:
- defaultBranch = "main"
Commit
- commit
- commit:
   message: first commit
   author: user1
   email: user1@ex.com
Equivalent of git add -a & git commit (stage all changes in the working dir before committing).

If omitted:
- message = "commit <#>"
- author = conf.author ?? "user-test"
- email = conf.email ?? "user-test@example.com"
Create branch
- branch develop
Checkout
- checkout develop
Merge
- merge develop
- merge:
   theirs: develop
   message: my merge commit
   author: user1
   email: user1@ex.com
If omitted:
- message = "merge branch <theirs>"
- author = conf.author ?? "user-test"
- email = conf.email ?? "user-test@example.com"

Merges never fast-forward.

Merge conflicts are auto-resolved cleanly by favoring the "theirs" branch.
Tag
- tag v1.0
- tag:
   name: v1.0
   annotated: true
   message: new tag
   author: user1
   email: user1@ex.com
By default, creates a lightweight tag, unless annotated: true

If omitted:
- annotated = false
- message = "create tag <name>"
- author = conf.author ?? "user-test"
- email = conf.email ?? "user-test@example.com"
Create file
- create file src/test.txt
- create file:
   file: test.txt
   content: file content
- create file:
   file: test.txt
   content: |
    line 1
    line 2
If omitted:
- content = <file name>
Change content
- change content:
   file: test.txt
   content: new file content

Configurations

conf:
  author: user # Default commit author name
  email: user@example.com # Default commit author email

License

MIT

Acknowledgements

  • isomorphic-git: for working with Git repositories (Great project. Check it out!)

About

A CLI tool to generate Git repositories

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published