git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Quick question: end of lines

From
Junio C Hamano <junkio@cox.net>
Date
Mar 1, 2006, 09:01 UTC
Message-ID
<7vwtfelerx.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<46a038f90603010031g31f8bc33xd3f45f2e19950c78@mail.gmail.com>
"Martin Langhoff" <martin.langhoff@gmail.com> writes:
Show 11 quoted lines
> On 3/1/06, Emmanuel Guerin <emmanuel@guerin.fr.eu.org> wrote:
>> What I begin to realize is that the only possibility probably lies in
>> using a tool that converts the modified files "on the fly" before
>> commits. I just want to make sure that no other solution was found by
>> others facing a similar problem.
>
> Perhaps a pre-commit hook? Read the documentation (and search the list
> archives). I'm pretty sure you can do newline cleanup before commit or
> at least newline checks before commits.
>
> There's always the option of filing a bug in MS's bugzilla ;-)

You can use .git/hooks/pre-commit hook in the repository the editor that munges line-termination, to fix things up.

The hook is called with GIT_INDEX_FILE set to the appropriate index file, so you could "git-diff-index --cached --name-only HEAD" to obtain the list of files being committed, sanitize the working tree files and update-index them again before returning true from the hook.

This is a silly example to standardize on uppercase.
        git-diff-index --cached --name-only HEAD |
        xargs sh -c '
                while case "$#" in 0) break ;; esac
                do
                        perl -p -i -e "\$_ = uc(\$_)" "$1"
                        git-update-index "$1"
                        shift
                done
        ' dummy
        exit 0
Previous: Martin Langhoff
Message 6 of 6 in “Quick question: end of lines”
  1. Emmanuel GuerinFeb 28, 2006
  2. Johannes SchindelinFeb 28, 2006
  3. Martin LanghoffFeb 28, 2006
  4. Emmanuel GuerinMar 1, 2006
  5. Martin LanghoffMar 1, 2006
  6. Junio C HamanoMar 1, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.