Skip to main content

git-smudge

A powerful filter driver for Git which can automatically apply local changes to the working tree of a repository.

Installing

Run

$ pip3 install git-smudge

If you're using bash, run:

$ git smudge comp

This will set up tab completion for git smudge

Setting up a filter

The first step is to run:

$ git smudge init

This will do three things:

  • It will create .git/git-smudge.toml, and pre-populate it with comments explaining how to define filters. For more information on the TOML format, see the TOML site.

  • It will run git config filter.git-smudge 'python3 -m git_smudge.runfilter'. This tells git how to run our filters.

  • It will add * filter=git-smudge to .git/info/attributes which tells git to have git-smudge handle filtering for all files. Only files which match filters in git-smudge.toml are actually updated, however.

You can run git smudge edit to edit the configuration file, or you can just open it in your normal editor.

Once you have your configuration set up, run:

$ git smudge apply

This will read git-smudge.toml and apply any filters defined there to the files in your working tree. If you had already defined filters previously, it will reverse those changes (using a saved copy of the old configuration). If there are any errors, git smudge apply will try to undo any changes and get back to the previous working state.

If you want to undo all changes, as if a blank configuration were applied, run:

$ git smudge clean

To see what changes have been applied to files, run:

$ git smudge diff

If you change the configuration and you want to preview what changes will be applied, run:

$ git smudge diff --preview

Plugins

git smudge supports defining custom filters by specifying a path to a Python script. This script should subclass GitFilter (which is pre-defined when executing the script). A class which is named XYZFilter would define a filter named XYZ or xyz (filter names are case-insensitive).

The filter class has two methods, clean and smudge. Both methods take a single parameter, content, which is used to manage the content of the file. This object has an attribute path, which is an instance of pathlib.Path, and methods get_text(), set_text(), get_binary(), and set_binary(). Most filters will be working with text, but the data can be converted to and from binary as needed.

When running git smudge apply, the contents of the plugin script is saved to the working configuration so that the exact code can be run to reverse those changes even if the code changes.

Metadata

Release files for git-smudge 0.0.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for git-smudge 0.0.21
File Size Uploaded
git_smudge-0.0.21.tar.gz 26.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for git-smudge 0.0.21
File Interpreter ABI Platform
git_smudge-0.0.21-py3-none-any.whl Python 3 none any Details

Total release size: 52.8 kB

Release files / git_smudge-0.0.21.tar.gz

Download URL git_smudge-0.0.21.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b6b9652b1e7a161108678c0bda543c78afa16b2ff14d956d089caab6bcb686e5
BLAKE2b-256 checksum
How to use checksums
35bfe9a806a4697b7da943a329a52121d7048670ecc8a2af3666032096e01242
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.12

Release files / git_smudge-0.0.21-py3-none-any.whl

Download URL git_smudge-0.0.21-py3-none-any.whl
Size 26.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6971ff23ddb393a03ce0ae8bd26acf4bf98a4ff247b9a41f60c9362a8cff541
BLAKE2b-256 checksum
How to use checksums
3c4165473acdfc90651b8d5f42fc4a9a134c3a28ed50e86813bb1ef500c912e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.0.21 This release

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page