Skip to main content

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

Project description

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.

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_smudge-0.0.21.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_smudge-0.0.21-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file git_smudge-0.0.21.tar.gz.

File metadata

  • Download URL: git_smudge-0.0.21.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.12

File hashes

Hashes for git_smudge-0.0.21.tar.gz
Algorithm Hash digest
SHA256 b6b9652b1e7a161108678c0bda543c78afa16b2ff14d956d089caab6bcb686e5
MD5 4c971e3d900359bc47f605367ec744e0
BLAKE2b-256 35bfe9a806a4697b7da943a329a52121d7048670ecc8a2af3666032096e01242

See more details on using hashes here.

File details

Details for the file git_smudge-0.0.21-py3-none-any.whl.

File metadata

  • Download URL: git_smudge-0.0.21-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.12

File hashes

Hashes for git_smudge-0.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 a6971ff23ddb393a03ce0ae8bd26acf4bf98a4ff247b9a41f60c9362a8cff541
MD5 04cfa716366032dbf203e6eb547e30d7
BLAKE2b-256 3c4165473acdfc90651b8d5f42fc4a9a134c3a28ed50e86813bb1ef500c912e3

See more details on using hashes here.

Supported by

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