#git-history #git #history #clean #git-commit #linting #lint

app clean_git_history

A Git history linter to ensure it stays clean for those who prefer rebasing and fast-forwarding compared to merge and squash commits

5 releases (1 stable)

1.0.0 Feb 26, 2025
0.2.0 Oct 18, 2024
0.1.2 Oct 22, 2021
0.1.1 Aug 26, 2021
0.1.0 Aug 10, 2021

#295 in Development tools

Download history 13/week @ 2024-11-20 3/week @ 2024-12-04 9/week @ 2024-12-11 10/week @ 2025-02-12 156/week @ 2025-02-26 3/week @ 2025-03-05

169 downloads per month

AGPL-3.0

40KB
649 lines

Clean Git History

crates.io Conventional Commits License

A Git history linter to ensure it stays clean for those who prefer a linear history without merge commits.

Content

Usage

Clean Git History checks the commits from the current HEAD(inclusively) till a provided Git reference(exclusively). This reference can be a branch, commit or tag, just provide it as the final argument.

e.g.

clean_git_history "origin/main"
clean_git_history "v0.2.0"
clean_git_history "bac789b4cc5fce9a26d6805c5da4bf17241523f1"

Git Environment Variables

When looking for a repository the Git environment variables are respected. When ${GIT_DIR} is set, it takes precedence and Clean History begins searching for a repository in the directory specified in ${GIT_DIR}. When ${GIT_DIR} is not set, Clean History searches for a repository beginning in the current directory.

Logging

The crates pretty_env_logger and log are used to provide logging. The environment variable RUST_LOG can be used to set the logging level. See https://crates.io/crates/pretty_env_logger for more detailed documentation.

Examples

GitHub Actions

name: Git History

on: pull_request

jobs:
  clean:
    name: Clean
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code.
        uses: actions/checkout@4
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          fetch-depth: 0
      - name: Install Clean Git history.
        run: version="1.0.0" && wget -O - "https://github.com/DeveloperC286/clean_git_history/releases/download/v${version}/x86_64-unknown-linux-musl.gz" | gzip -d > /usr/bin/clean_git_history && chmod 755 /usr/bin/clean_git_history
      - name: Check clean Git history.
        run: clean-git-history "origin/${{ github.base_ref }}"

GitLab CI

clean-git-history-checking:
  stage: clean-git-history-checking
  image: rust
  before_script:
    - version="1.0.0" && wget -O - "https://github.com/DeveloperC286/clean_git_history/releases/download/v${version}/x86_64-unknown-linux-musl.gz" | gzip -d > /usr/bin/clean_git_history && chmod 755 /usr/bin/clean_git_history
  script:
    - clean_git_history "origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
  rules:
    - if: $CI_MERGE_REQUEST_ID

Git Hook

An example pre-push Git hook to check if the history of a project is clean before it is pushed to the remote server.

#!/usr/bin/env bash

set -o errexit
set -o pipefail

branch=$(git branch --show-current)
"${HOME}/.cargo/bin/clean_git_history" "origin/${branch}"

Installing

Binary

Statically linked compiled binaries are available for download. Visit the releases page at https://github.com/DeveloperC286/clean_git_history/releases to see all the releases, the release notes contains links to binary downloads for various architectures.

version="1.0.0" && wget -O - "https://github.com/DeveloperC286/clean_git_history/releases/download/v${version}/x86_64-unknown-linux-musl.gz" | gzip -d > /usr/bin/clean_git_history && chmod 755 /usr/bin/clean_git_history

Cargo

Cargo is the Rust package manager, the install sub-command pulls from crates.io and then compiles the binary locally, placing the compiled binary at ${HOME}/.cargo/bin/clean_git_history.

cargo install clean_git_history

By default it installs the latest version at the time of execution. You can specify a specific version to install using the --version argument. For certain environments such as CICD etc you may want to pin the version.

e.g.

cargo install clean_git_history --version "1.0.0"

See https://doc.rust-lang.org/cargo/commands/cargo-install.html#install-options for more detailed documentation.

Development

Setup

You need Earthly and Docker installed, Earthly handles all build and runtime dependencies.

Commands

Git History

earthly +check-clean-git-history

Conventional Commits

earthly +check-conventional-commits-linting

Formatting

Check
earthly +check-formatting

rust, python, shell and yaml

earthly +check-{language}-formatting
Fix
earthly +fix-formatting

rust, python, shell and yaml

earthly +fix-{language}-formatting

Linting

earthly +check-linting

rust, shell and github-actions-workflows

earthly +check-{language}-linting

Compiling

earthly +compile

Testing

earthly +end-to-end-test
earthly +static-binary-test
earthly +unit-test

Issues/Feature Requests

To report an issue or request a new feature use https://github.com/DeveloperC286/clean_git_history/issues.

Dependencies

~16MB
~338K SLoC