mgit2.0.2
05 / 07

Exit codes and automation

Everything you need to know before a script decides something based on the result.

Exit codes

CodeMeaning
0every repository succeeded (or --allow-empty and nothing was found)
1a repository failed, or no repository was found
2the command line could not be parsed
127git could not be found or started
130interrupted with Ctrl+C (SIGINT / SIGTERM)
anything elsewhatever the first failing git command returned

How many repositories become one code

  1. By default the run finishes everything (--keep-going) instead of stopping at a failure.
  2. The overall exit code is the code of the first repository that failed, not the last.
  3. --fail-fast stops at the first failure, and the repositories it never reached are counted as skipped in the summary.
  4. Ctrl+C is not a repository failure: it stops the whole run at once and returns 130.

Compare --fail-fast with the default: mgit --fail-fast pull

Interrupting a run

Ctrl+C reaches the whole process group, which includes the git that mgit started. mgit treats that as "stop now": it does not move on to the next repository and it does not print a summary.

Start it, then press Ctrl+C: mgit pull

In a shell script

#!/usr/bin/env sh
set -eu

# fail when any repository has uncommitted work
if [ -n "$(mgit --quiet --color=never status --porcelain)" ]; then
  echo 'working trees are not clean' >&2
  exit 1
fi
# update everything, then pick the failures out
mgit pull 2> pull-errors.txt || {
  echo 'some repositories failed:' >&2
  grep '✗' pull-errors.txt >&2
}

In CI

- name: Update every checkout
  run: mgit --color=never --summary pull

- name: Fail when anything is dirty
  run: |
    test -z "$(mgit -q --color=never status --porcelain)"
CI logsA CI log is usually not a terminal, so colour is already off. Writing --color=never only makes that explicit.

Pipes and SIGPIPE

mgit --list | head -n 3 is safe: mgit restores the default SIGPIPE behaviour, so when the reader goes away it stops quietly instead of printing a panic into your log.

Try it against head: mgit --list | head -n 3