GithubHelp home page GithubHelp logo

idomoz / silent-committer Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 1.0 21 KB

Commits changes as original authors

License: MIT License

Xonsh 86.60% Shell 2.65% Python 10.75%
git commit git-commit authors xonsh python-script

silent-committer's Introduction

versions

silent-committer

Commits changes as original authors

What is this for?

Doing a styling refactor? Applying a lint rule? Upgrading all calls of a function to a new signature?
These tasks usually don't change the logic behind the code, and so we might want git blame to show the original author of the line before we made our cosmetic change.
Git has an option to specify a different author for the entire commit (--author) but that will use a single author for our entire changes.

That's where silent-committer comes in -
It analyses your uncommitted changes to find all the original authors, and then commits your changes in separate commits, each with a different author and only the code you changed of that author.

Installation

pip install silent_committer

Usage

cd <project_root>
silently-commit "<commit_msg>"

Example output of git log after running silently-commit "Update usage of foo.bar()":

commit 440b2aac9c9416c949c4727cd1e1ebba521e0b91 (HEAD -> master)
Author: John Doe <[email protected]>
Date:   Tue Aug 9 12:51:43 2022 +0200

    Update usage of foo.bar(); For user: John Doe <[email protected]>

commit 3e2ed2c0fda7c0419b13ebd80b9c68f28a007f1c
Author: Philip Jackson <[email protected]>
Date:   Tue Aug 9 12:51:43 2022 +0200

    Update usage of foo.bar(); For user: Philip Jackson <[email protected]>

commit 74ba0e526707f8aa0eb8c1fdca2938c1b2d44b9f
Author: Kate Cole <[email protected]>
Date:   Tue Aug 9 12:51:42 2022 +0200

    Update usage of foo.bar(); For user: Kate Cole <[email protected]>

commit 79d9fe1ee9176db71ccd3c96b3faa235ab055874
Author: William Calvert <[email protected]>
Date:   Tue Aug 9 12:51:42 2022 +0200

    Update usage of foo.bar(); For user: William Calvert <[email protected]>

How does this work?

Silent committer does the following steps:

  1. Unstages all changes.
  2. Runs git add -p and splits all hunks that are splittable.
  3. Parses the output of git add -p to get all hunks.
  4. Stashes all changes (to be able to run git blame).
  5. Finds the authors of all the changed lines using git blame -w.
  6. Calculates the author of each hunk (if there is only one author for the changed lines in the hunk it uses that author, otherwise it uses one of the authors of the changed lines that contibuted most to that hunk).
  7. For each author - it stages all of its hunks and creates a commit using the <commit_msg> passed as arg and appends the author details. For example if <commit_msg> is pep8 formatting then it will create a commit with the message pep8 formatting; For user: John Doe <[email protected]> for each author with the author being the original author while the committer still remains you.
  8. All line additions (new and not modified lines) will be commited with you as the author.

*** New files are not supported as this tool relies on unstaging all files, causing new files to become untracked and then it can’t know which of the untracked files you intend to commit, so please first commit all new files separately.

Disclaimer

In order to prevent code loss, it's best to first commit your changes and the run git reset --soft HEAD^ so that you could return to your changes using git reflog or alternitively stash your changes and run git stash apply to keep your changes in the stash if something goes wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.