Skip to main content

A command line utility to list and merge gitlab merge requests while maintaining linear history

Project description

git-mr-linear

A command line utility to list and merge GitLab pull requests while maintaining linear history.

To maintain linear history, a pull request branch is rebased on top of its base, before merging. This creates a linear history like in this diagram:

linear_history

Further Reading & Context

Usage

Installing

Python3.6 or above is required. You can install this package by running the following command:

pip3 install git-mr-linear

To upgrade to the latest version:

pip3 install --upgrade git-mr-linear

How To Use

Get help: git mr -h

The first time you run this script, you will be asked to authenticate with Gitlab.

List Command

List all open pull requests: git mr list, or list only yours with git mr list --mine

   #  Title                                                         Branch
----  ------------------------------------------------------------  -------------------------------
5811  Fix various bugs with video player                            fix/kevin-video-player-bugs
5812  Fix highlight being stuck when gallery frame is deactivated   fix/kevin-highlightable-view
...

Merge Command

Merge a pull request: git mr merge NUMBER

image

Squash Command

Squash a pull request: git mr squash NUMBER

The squash command collapses all commits from the pull branch into a single commit and puts that commit straight onto the base branch without doing an explicit merge.

Here's what the history looks like when you use squash vs merge.

image

Repo configuration

Add a .linmergerc config file to the repo root directory to customize behaviour to your teams preference.

Below are all the options

[merge]
# Commit message format vars: TITLE, NUMBER, AUTHOR_NAME, AUTHOR_USERNAME
merge_msg_format = Merge: {TITLE} (#{NUMBER})
# Enable single-commit pulls to be squashed instead of merging, even when explicitly using the merge command
always_squash_single_commit_pulls = True

[squash]
squash_msg_format = {TITLE} (#{NUMBER})
# Enable usage of the `git mr squash` command
squash_cmd_enabled = True

Troubleshooting

  • You see "git: mr is not a git command"
    1. Run sudo pip3 install git-mr-linear and see if you receive a yellow warning message indicating ..../Library/Caches/pip is not writable by the current user. This indicates the installation has not completed successfully due to incorrect write permissions
    2. Run sudo -H pip3 install git-mr-linear
    3. If the error still persists, make sure you have write access to ~/Library/Python/3.X/bin. Run sudo -H pip3 install git-mr-linear again if you changed any write permissions

Development

This section explains how to setup the dev environment and update the package

Environment setup

python3 -m pip install virtualenv
python3 virtualenv venv
source venv/bin/activate
pip install -r requirements.txt

Running Locally

With the environment setup through the previous step, you can run git mr using your local code by running the git-mr.py script in the root directory of this repo.

python3 ~/path/to/your/local/checkout/git-mr.py

Updating the package

Make sure to bump the version number with updates according to PEP 440

Publish and Install from TestPyPi

Before publishing for real, you can test a package by publishing it to TestPyPi

Publishing:

source venv/bin/activate
rm -rf dist
rm -rf build
python -m build
twine upload --repository testpypi dist/*

Installing:

python3 -m pip install --index-url https://test.pypi.org/simple/ git-mr-linear

Publish

source venv/bin/activate
rm -rf dist
rm -rf build
python -m build
twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git-mr-linear-0.0.3a0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

git_mr_linear-0.0.3a0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file git-mr-linear-0.0.3a0.tar.gz.

File metadata

  • Download URL: git-mr-linear-0.0.3a0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for git-mr-linear-0.0.3a0.tar.gz
Algorithm Hash digest
SHA256 dfbe9c740a3e0d0595e9dbaf9448930a1d46828eaaf8293c78fe0c43cd672d48
MD5 6bc59f5c5d919e77c7641a23e4904a05
BLAKE2b-256 2f3ecc2a7c661c319d170fbe3989f34eb2c278aa23a41e11e2f535e7292f0050

See more details on using hashes here.

File details

Details for the file git_mr_linear-0.0.3a0-py3-none-any.whl.

File metadata

File hashes

Hashes for git_mr_linear-0.0.3a0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9cddfc4859c77d7523af535d712f64625bfd3cbd9e2ccf06bb2d2826d141e3f
MD5 147475e8b7d731f3737dd7f8d5cf78f3
BLAKE2b-256 9003cee9195dba6e46c5e2a17e2234882b2bf703a1ce9abacae32a2954131df0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page