Skip to content

Latest commit

 

History

History
407 lines (303 loc) · 11 KB

mit.md

File metadata and controls

407 lines (303 loc) · 11 KB

Authors

This is the git mit part of the tool.

Setup

In order to get started with this tool you'll need a git repository

git init .

You'll need to install the hooks into this repository

git mit-install

Configuring

For this example we'll be using the same configuration as you can generate from the example command.

You can see this configuration yourself by running

git-mit-config mit example
[ae]
name = "Anyone Else"
email = "[email protected]"

[bt]
name = "Billie Thompson"
email = "[email protected]"
signingkey = "0A46826A"

[se]
name = "Someone Else"
email = "[email protected]"

You can use yaml too

---
ae:
  name: Anyone Else
  email: [email protected]
bt:
  name: Billie Thompson
  email: [email protected]
  signingkey: 0A46826A
se:
  name: Someone Else
  email: [email protected]

To make keeping this file up-to-date easier there's some commands to adding and removing users to your git repository, that can then be output into a more permanent configuration file.

You can quickly add a new author by running

git mit-config mit set jd "Jane Doe" "[email protected]"

Over override an existing user temporarily

git mit-config mit set se "Someone Else" "[email protected]"

You can use these straight away, you don't have to update your authors file.

git mit jd

However, if you want to make it more permanent, you can output the configuration with these added authors by running the generate command

git mit-config mit generate
[ae]
name = "Anyone Else"
email = "[email protected]"

[bt]
name = "Billie Thompson"
email = "[email protected]"
signingkey = "0A46826A"

[jd]
name = "Jane Doe"
email = "[email protected]"

[se]
name = "Someone Else"
email = "[email protected]"

To get a summary of the authors that are configured run

git mit-config mit available
╭─────────┬─────────────────┬────────────────────┬─────────────╮
│ Initial ┆ Name            ┆ Email              ┆ Signing Key │
╞═════════╪═════════════════╪════════════════════╪═════════════╡
│ ae      ┆ Anyone Else     ┆ [email protected] ┆ None        │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ bt      ┆ Billie Thompson ┆ [email protected] ┆ 0A46826A    │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ jd      ┆ Jane Doe        ┆ [email protected]     ┆ None        │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ se      ┆ Someone Else    ┆ [email protected]     ┆ None        │
╰─────────┴─────────────────┴────────────────────┴─────────────╯

Running the command

We can then use this by passing -c to the git-mit command.

git mit -c "../git-mit.toml" ae bt se

It's exactly the same for a YAML configuration

git mit -c "git-mit.yml" ae bt se

Or you can use the environment variables

export GIT_MIT_AUTHORS_CONFIG="../git-mit.toml"
git mit -c "$HOME/git-mit.toml" ae bt se

Or just put it at the default location

git mit ae bt se

Then next when you make a commit the Co-authored-by trailers will be set of the author initials you selected.

echo "# Hello, world!" > README.md

git add .
git commit --message="Initial Commit" --quiet
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q
author: [Anyone Else [email protected]] signed-by: [] 
---
Initial Commit

Co-authored-by: Billie Thompson <[email protected]>
Co-authored-by: Someone Else <[email protected]>

You don't need to constantly pass the config everywhere though, you can set an environment variable.

export GIT_MIT_AUTHORS_CONFIG="$HOME/git-mit.toml"
git mit se ae

So next time we commit

echo "Lorem Ipsum" >> README.md

git commit --all --message="Second Commit" --quiet
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q

The author configuration will be updated like this

author: [Someone Else [email protected]] signed-by: [] 
---
Second Commit

Co-authored-by: Anyone Else <[email protected]>

If for some reason you've already added the author we won't duplicate it

echo "Lorem Ipsum" >> README.md

git commit --all --message="Second Commit

Co-authored-by: Anyone Else <[email protected]>
" --quiet
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q

The author configuration will be updated like this

author: [Someone Else [email protected]] signed-by: [] 
---
Second Commit

Co-authored-by: Anyone Else <[email protected]>

Rebases

It might be preferable not to do this on rebase, you can disable this happening on rebase by running

git mit-config mit set-non-clean-behaviour no-change
git mit-config mit non-clean-behaviour

To get the current behaviour run

no-change

lets say we have two diverging branches

echo "Lorem Ipsum" >> new-so-no-conflicts.md
git switch -c rebase-demo-branch
git switch -
git commit --all --message="Diverging commit" --quiet
git switch -

Now you can rebase changes without adding any additional trailers

git mit bt se
echo "Lorem Ipsum" >> README.md

git commit --all --message="Rebase behaviour
" --quiet
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q
author: [Billie Thompson [email protected]] signed-by: [] 
---
Rebase behaviour

Co-authored-by: Someone Else <[email protected]>

Then if you rebase the commit stays the same

git mit bt ae
git rebase --reset-author-date "-"
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q
author: [Billie Thompson [email protected]] signed-by: [] 
---
Rebase behaviour

Co-authored-by: Someone Else <[email protected]>

The default setting is to modify the co-authored by.

git mit-config mit set-non-clean-behaviour add-to
git mit-config mit non-clean-behaviour
add-to

Now you can rebase changes without adding any additional trailers

git mit bt ae
git rebase --reset-author-date "-"
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q
author: [Billie Thompson [email protected]] signed-by: [] 
---
Rebase behaviour

Co-authored-by: Someone Else <[email protected]>
Co-authored-by: Anyone Else <[email protected]>

Signed Commits

The command also works with signed commits

The bt user has a valid gpg key.

git mit bt
echo "Delores Et" >> README.md

git commit --all --gpg-sign --message="Third Commit" --quiet
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q
author: [Billie Thompson [email protected]] signed-by: [Billie Thompson <[email protected]>] 
---
Third Commit

Errors

If your authors file is broken like the one below (or for any other reason)

Hello, I am a broken file

You'll get an error when you run the command

git mit -c "broken.toml" ae bt se
Error: mit_commit_message_lints::mit::lib::authors::serialise_authors_error

  × could not parse author configuration
   ╭────
 1 │ Hello, I am a broken file
   · ▲    ▲
   · │    ╰── invalid in toml: 
   · ╰── invalid in yaml: 
   ╰────
  help: `git mit-config mit example` can show you an example of what it should
        look like, or you can generate one using `git mit-config mit generate`
        after setting up some authors with `git mit-config mit set`

Same applies for git mit-config mit generate

git mit-config mit generate -c "broken.toml"
Error: mit_commit_message_lints::mit::lib::authors::serialise_authors_error

  × could not parse author configuration
   ╭────
 1 │ Hello, I am a broken file
   · ▲    ▲
   · │    ╰── invalid in toml: 
   · ╰── invalid in yaml: 
   ╰────
  help: `git mit-config mit example` can show you an example of what it should
        look like, or you can generate one using `git mit-config mit generate`
        after setting up some authors with `git mit-config mit set`