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

git-apply working on an index with smudged entries

From
Christian Halstrick <christian.halstrick@gmail.com>
Date
Dec 14, 2018, 10:15 UTC
Message-ID
<CAENte7hRCk+3E+C4LYOjTzQKdqE1wN1=HX7YkR72H+HD-=mj5g@mail.gmail.com>

I see that when I call "git apply --3way ..." on an index which was previously created by JGit and which contains smudged entries the command fails with message "error: foo.txt: does not match index". If I do a "git status" afterwards and then the same "git apply --3way ..." it succeeds. Looks like "git status" corrected the index in a way so "git apply" can accept it.

Question:
- is this because the index which jgit created is so corrupt that only
special commands
like "git status" can repair it?
- or is "git apply" not trying hard enough to consume a index with
smudged entries
Here is the trace of a script from Thomas which shows the effect:
> git --version
git version 2.19.1
> jgit --version
jgit version 5.2.0-SNAPSHOT
> git init
Initialized empty Git repository in /Users/d032780/tmp/a/.git/
> echo "foo" > foo.txt
> git add foo.txt
> git commit -m "Initial commit"
[master (root-commit) ff6c56c] Initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 foo.txt
> echo "bar" >> foo.txt
> git add foo.txt
> git commit -m "Second commit"
[master 2191919] Second commit
 1 file changed, 1 insertion(+)
> echo "baz" >> foo.txt
> git add foo.txt
> git commit -m "Third commit"
[master d863c4a] Third commit
 1 file changed, 1 insertion(+)
> git diff HEAD^1..HEAD foo.txt > ../foo.patch
> jgit reset --hard HEAD~
> git apply --3way ../foo.patch
error: foo.txt: does not match index
> git ls-files -sv --debug
H 100644 3bd1f0e29744a1f32b08d5650e62e2e62afb177c 0 foo.txt
  ctime: 0:0
  mtime: 1544782273:0
  dev: 0 ino: 0
  uid: 0 gid: 0
  size: 0 flags: 0
> git status

On branch master Untracked files: ...

> git ls-files -sv --debug
H 100644 3bd1f0e29744a1f32b08d5650e62e2e62afb177c 0 foo.txt
  ctime: 1544782273:797529188
  mtime: 1544782273:796936707
  dev: 16777220 ino: 64184423
  uid: 503 gid: 20
  size: 8 flags: 0
> git apply --3way ../foo.patch
> cat foo.txt

foo bar baz

>
Next: Junio C Hamano
Message 1 of 2 in “git-apply working on an index with smudged entries”
  1. Christian HalstrickDec 14, 2018
  2. Junio C HamanoDec 15, 2018

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.