X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=patchformatting.mdwn;h=40db0b79d4c4f7406ad89317ef52370320a95902;hb=940135105928a01528cbbe235f8723085286804e;hp=914371d4da071d916340c945304a26f02e06021c;hpb=b2e4da9e0c71a62f053aa9a8586089d77b24f4e9;p=notmuch-wiki diff --git a/patchformatting.mdwn b/patchformatting.mdwn index 914371d..40db0b7 100644 --- a/patchformatting.mdwn +++ b/patchformatting.mdwn @@ -25,13 +25,40 @@ working tree will follow. Enter your commit message in following format: - first commit line; one line description, up to 65 chars + first commit line; short one line description - After one empty line, a detailed description of your changes - the description most usually spans over multiple lines. + After one empty line, a detailed description of your changes + the description most usually spans over multiple lines. -The 65-character (limit) seems to be common among many projects so -that is good guideline to follow here too. +Wrap the lines to about __72__ characters or so. On an 80 column terminal, +if we subtract 4 columns for the indent on the left and 4 more for +symmetry on the right, we’re left with __72__ columns. + +Regarding the commit message body contents, +Carl [has stated](http://article.gmane.org/gmane.mail.notmuch.general/504): + +> The single line summary is good about saying *what* the commit does, +> but I always want to see at least one sentence about the *why* as well. + +### Activating default pre-commit hook + +Git provides a default pre-commit hook which, when activated, checks +(at least) for whitespace errors (trailing whitespace and space before +tab). It is better to notice this kind of "errors" early than have +patch reviewers to mention about those. + +The hook, when activated, is named as .git/hooks/pre-commit and it +has execute permissions set on. By default, when git tree is cloned +your hooks dir may have default, inactive pre-commit hook available +as: + +1. .git/hooks/pre-commit without execute permission set + +2. .git/hooks/pre-commit.sample usually with execute permission set + +In case of 2, enter `cp .git/hooks/pre-commit.sample .git/hooks/pre-commit`. +And, now enter `chmod a+x .git/hooks/pre-commit` in case it does not +have execute permission set. ## Remember: one patch per email @@ -56,37 +83,68 @@ that your patch achieves what it is meant it to. If you've made just one commit (containing just one bugfix or new feature) you can run - git format-patch HEAD^ + git format-patch HEAD^ This outputs something like - 0001-one-line-description.patch + 0001-one-line-description.patch This is the file name of your patch with content: - From <-40-character-sha1-hexadecimal-string-> Day Mon DD HH:MM:SS YYYY - From: user.name - Date: Day, DD Mon YYYY HH:MM:SS TZOFF - Subject: [PATCH] first commit line; one line description, up to 65 chars + From <-40-character-sha1-hexadecimal-string-> Day Mon DD HH:MM:SS YYYY + From: user.name + Date: Day, DD Mon YYYY HH:MM:SS TZOFF + Subject: [PATCH] first commit line; one line description, up to 65 chars - after one empty line, a detailed description of your patch - the description most usually spans over multiple lines. - --- - - nn files changed, nn insertions(+) nn deletions(-) + after one empty line, a detailed description of your patch + the description most usually spans over multiple lines. + --- + + nn files changed, nn insertions(+) nn deletions(-) - diff --git a/<1st filename> b/<1st filename> - ... + diff --git a/<1st filename> b/<1st filename> + ... If you have committed more patches, and want to prepare all of those you can check with `git log` a 40-char commit-sha1 of the last commit *since* you want to generate patch files. When you enter - git format-patch + git format-patch every commit *after* that commit-sha1 will be used to generate patch files... +### Test-applying your patches + +Sometimes you may face a situation with your patches that you are unsure +whether those patches apply to the origin. Such a cases might be: + +* You've taken your patches from a branch that has some other commits on top of origin. + +* You have edited the commit message, comments below commit message or the patch content itself in the patch files generated. + +To verify that your patches will apply on top of pristine origin you can +test-apply your patch files on origin/master: + +* Simple case -- no other changes on top of origin/master + + git reset --hard origin/master + git pull + git am 00* + +* A case where working tree is dirty + + git log -1 --format=%H > head_commit + git stash save + git reset --hard origin/master + git pull + git am 00* + : + git reset --hard `cat head_commit` + git stash apply + rm head_commit + git stash drop + ## Sending patches ### Using git send-email @@ -95,7 +153,7 @@ patch files... If you try to execute `git send-email` and you get - git: 'send-email' is not a git command. See 'git --help'. + git: 'send-email' is not a git command. See 'git --help'. Then you're using git installation where send-email command is distributed in separate package. In Debian/Ububtu/RedHat/Fedora the package is named @@ -109,7 +167,7 @@ work properly). Check through `git-send-email` manual page and play with it. In case of one-file you might want to use - git send-email --annotate 0001-* + git send-email --annotate 0001-* (other options omitted) to add a 'discussion' part into your email. The `git am` tool which is eventually used to submit the patch