git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* git-apply working on an index with smudged entries
@ 2018-12-14 10:15 Christian Halstrick
  2018-12-15  0:40 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Halstrick @ 2018-12-14 10:15 UTC (permalink / raw)
  To: Git; +Cc: thomas.wolf

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
>

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

* Re: git-apply working on an index with smudged entries
  2018-12-14 10:15 git-apply working on an index with smudged entries Christian Halstrick
@ 2018-12-15  0:40 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2018-12-15  0:40 UTC (permalink / raw)
  To: Christian Halstrick; +Cc: Git, thomas.wolf

Christian Halstrick <christian.halstrick@gmail.com> writes:

> Question:
> - is this because the index which jgit created is so corrupt that only
> special commands
> like "git status" can repair it?

No.

> - or is "git apply" not trying hard enough to consume a index with
> smudged entries

No.

Lower level "plumbing" commands like "git apply" want to see the
cached stat information in the index refreshed before they are
called, instead of having to refresh the index themselves before
starting to work, for performance reasons.  Higher level "Porcelain"
commands like "git status" on the other hand refreshes the index
before they start to work.

What you are seeing is a combination of

 * JGit not running its equivalent of "git update-index --refresh"
   before finishing and leaving the index file for you to look at.

 * "git status" running an equivalent of "git update-index --refresh"
   internally.

 * "git apply" not running "update-index --refresh" itself and
   instead expecting somebody else to have done so in the sequence
   of commands that it is a part of.

The latter two is working perfectly as designed.

I do not know what JGit wanted to do to leave the index in that
state, so I cannot judge if that is a reasonable thing to do or JGit
needs tobe fixed.


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

end of thread, other threads:[~2018-12-15  0:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-14 10:15 git-apply working on an index with smudged entries Christian Halstrick
2018-12-15  0:40 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).