# [PATCH] git-commit: filter out log message lines only when editor was run.

2 messages from 2006-06-23 to 2006-06-24. Participants: Yann Dirson, Junio C Hamano.
Thread: https://gitlist.dev/t/4642

## Yann Dirson, 2006-06-23 22:04

Subject: [PATCH] git-commit: filter out log message lines only when editor was run.
Message-ID: <20060623220405.1915.28636.stgit@gandelf.nowhere.earth>
URL: https://gitlist.dev/e/20060623220405.1915.28636.stgit%40gandelf.nowhere.earth

```

The current behaviour strips out lines starting with a # even when fed
through stdin or -m.  This is particularly bad when importing history from
another SCM (tailor 0.9.23 uses git-commit).  In the best cases all lines
are stripped and the commit fails with a confusing "empty log message"
error, but in many cases the commit is done, with loss of information.

Note that it is quite peculiar to just have "#" handled as a leading
comment char here.  One commonly meet CVS: or CG: or STG: as prefixes, and
using GIT: would be more robust as well as consistent with other commit
tools.  However, that would break any tool relying on the # (if any).

Signed-off-by: Yann Dirson <ydirson@altern.org>
---

 git-commit.sh |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/git-commit.sh b/git-commit.sh
index 6dd04fd..aa3b1ea 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -691,13 +691,18 @@ t)
 	fi
 esac
 
-sed -e '
-    /^diff --git a\/.*/{
-	s///
-	q
-    }
-    /^#/d
-' "$GIT_DIR"/COMMIT_EDITMSG |
+if test -z "$no_edit"
+then
+    sed -e '
+        /^diff --git a\/.*/{
+	    s///
+	    q
+	}
+	/^#/d
+    ' "$GIT_DIR"/COMMIT_EDITMSG
+else
+    cat "$GIT_DIR"/COMMIT_EDITMSG
+fi |
 git-stripspace >"$GIT_DIR"/COMMIT_MSG
 
 if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |

```

## Junio C Hamano, 2006-06-24 00:21

Subject: Re: [PATCH] git-commit: filter out log message lines only when editor was run.
Message-ID: <7vveqr769z.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vveqr769z.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20060623220405.1915.28636.stgit@gandelf.nowhere.earth>

```
Yann Dirson <ydirson@altern.org> writes:

> The current behaviour strips out lines starting with a # even when fed
> through stdin or -m.  This is particularly bad when importing history from
> another SCM (tailor 0.9.23 uses git-commit).  In the best cases all lines
> are stripped and the commit fails with a confusing "empty log message"
> error, but in many cases the commit is done, with loss of information.

I agree with this in principle but we would need to make sure
that our own scripts do not expect that the message is cleaned
up when feeding a commit log message via stdin, -m or -F, and if
they do fix them before applying this patch.
 

```
