Helper scripts¶
This section contains scripts and snippets to help with the usage of REUSE. REUSE already has a lot of functionality builtin, but there are still cases where REUSE could use support from some external scripts. A typical example is adding SPDX headers based on the information in the version control system. This collection of scripts and snippets offers help for such situations.
Warning
These scripts help you run REUSE against your codebase. Automatically extracted information might not resemble the truth. The correctness of these scripts is not guaranteed. Use with caution and at your own risk.
Starting point of the codebase¶
The first code contribution can be a worthwhile date to include in the copyright annotation.
First commit¶
Git log can show summaries of all commits.
At the moment of writing git does not allow selecting just one commit, so head
is used to restrict the output.
$ git log --reverse --all | head -n 3
commit cdcea0887e0a85149f93e734b647301a16dd893e
Author: Carmen Bianca Bakker <carmenbianca@fsfe.org>
Date: Tue Oct 10 18:27:11 2017 +0200
Year of first commit¶
With a custom format just the year of the first commit can be displayed. This output is convenient for use in larger scripts.
$ git log --reverse --date="format:%Y" --format="format:%cd" | head -n 1
2017
Add headers¶
A common use-case is to add headers to existing, modified or newly written code.
Add headers to staged files based on git settings¶
This script helps you add your copyright headers right before committing the code you wrote.
The list of files staged in git can be retrieved using git diff --name-only --cached
, which is the basis to apply the reuse annotate
command to.
Git user and email address are available through git config --get user.name
and git config --get user.email
.
REUSE already sets the current year, so there is no need to set that explicitly.
These elements can be combined into a single command:
$ git diff --name-only --cached | xargs -I {} reuse annotate -c "$(git config --get user.name) <$(git config --get user.email)>" "{}"
Copyright
This page is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license. Examples, recipes, and other code in the documentation are additionally licensed under the Creative Commons Zero v1.0 Universal License.