git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* buggy smudge/clean of empty files
@ 2025-05-22 19:01 Joey Hess
  2025-05-22 22:15 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Joey Hess @ 2025-05-22 19:01 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 1118 bytes --]

git seems to be buggy in its handling of empty files when smudge/clean filters
are used.

I've attached a script setup_smudge_clean.sh, which configures a git
repository to use a very simple smudge and clean filter pair for all
files. The clean filter prepends a line "hi" to the file content, and the
smudge filter removes the line. There is nothing very special about this
smudge/clean, it's just a simple one for the sake of an example.

Here's the bug:

# git init repo
# cd repo
# sh ~/setup_smudge_clean.sh
# echo foo > foofile
# git add foofile
# git diff
# touch emptyfile
# git add emptyfile
# git commit -m added
# git status
On branch master
nothing to commit, working tree clean
# git diff
diff --git a/emptyfile b/emptyfile
--- a/emptyfile
+++ b/emptyfile
@@ -1 +0,0 @@
-hi

emptyfile is unchanged, as git status shows, so why is git diff displaying
a change?

It seems that git diff runs the clean filter (GIT_TRACE shows it does),
but it must ignore its output when the file is empty, and always use an empty
file as the current content for the diff. Which differs from what was staged.

-- 
see shy jo

[-- Attachment #2: setup_smudge_clean.sh --]
[-- Type: application/x-sh, Size: 321 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-22 22:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-22 19:01 buggy smudge/clean of empty files Joey Hess
2025-05-22 22:15 ` Jeff King
2025-05-22 22:26   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).