[Go to site: main page, start]

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hooks

git-gamble provides his own custom git hooks to enhance the development workflow

These hooks can be used to perform specific actions before and after gambling

Before Gambling (pre-gamble)

The pre-gamble hook is executed before the actual gambling process begins

Sometimes, you want to have certain things imperatively done before gambling on the tests

What if something irrelevant was just missing and that forgetting this was not worth starting again ?

Examples :

  • Formatting
  • Linting

After Gambling (post-gamble)

The post-gamble hook is triggered after the gambling result is known

Sometimes, you want to do actions after the gamble only in some situations

Examples :

  • Wrong gamble (pass fail or fail pass)
    • Suggest to take a break
  • Good gamble (pass pass or fail fail)
    • Congratulate
  • Failing tests (fail fail)
    • Remember to not push on the main branch
  • Passing tests (pass pass)

See more usable examples

If you have more ideas, please share them by opening an issue

Hook Execution and Configuration

Custom hooks are called with arguments :

  • pre-gamble <GAMBLED>
    • pre-gamble hook is executed with one argument <GAMBLED>
  • post-gamble <GAMBLED> <ACTUAL>
    • post-gamble hook is executed with two arguments <GAMBLED> and <ACTUAL>

Where :

  • <GAMBLED> is pass or fail
  • <ACTUAL> is pass or fail

Custom hooks of git-gamble are like any other client-side git hooks :

  • a hook is a file (pre-gamble or post-gamble)

  • a hook must be in the $GIT_DIR/hooks/ folder

    • or in the folder configured by git config core.hooksPath
  • a hook must be executable

    • to make it executable, execute the following command

       chmod +x .git/hooks/*-gamble
      
  • will not be executed if any of these options are used :

    • --no-verify
    • --dry-run

Hooks Execution Lifecycle

The following diagram shows when custom hooks are executed in relation to standard git hooks

Textual description of the hooks execution lifecycle
  1. User executes the command git-gamble --pass OR git-gamble --fail
  2. git-gamble executes the hook pre-gamble pass OR pre-gamble fail
  3. git-gamble executes the command git add --all
  4. git-gamble executes the command exec $GAMBLE_TEST_COMMAND
  5. When gamble success
    1. git-gamble executes the command git commit
    2. git executes the hook pre-commit
    3. git executes the hook prepare-commit-msg $GIT_DIR/COMMIT_EDITMSG message
    4. git executes the hook commit-msg $GIT_DIR/COMMIT_EDITMSG
    5. git executes the hook post-commit
    6. When gambling fail after another gamble fail
      1. git executes the hook post-rewrite amend
    7. git-gamble executes the hook post-gamble pass pass OR post-gamble fail pass depending on what the user gambled
  6. When gamble error
    1. git-gamble executes the command git reset --hard
    2. git-gamble executes the hook post-gamble pass fail OR post-gamble fail fail depending on what the user gambled