threads / discuss / 40712

Strange diff-index output

Subject: Strange diff-index output

## tl;dr

4 messages between Nov 2, 2015 and Nov 4, 2015.

replies: 3people: 3as markdown or json

Ch'Gans· Nov 2, 2015, 23:59 UTC · lore
Hi there,

We're using a script to verify that what we are building is clean against our git repository, for this we're using "git rev-parse --short HEAD" to get the current hash and "git diff-index --quiet HEAD" to check for local modification. This script works fine on developer's machines, but doesn't on our CI system (Atlassian Bamboo/Stash).

HEAD points to refs/heads/FIX-XYZ and refs/heads/FIX-XYZ exists.

On our CI, the output of diff-index gives something like: :100644 100644 abcdef 000000 M file1

Our problem is very likely related with how Bamboo works and/or how we use it, but to investigate this issue further, I first would like to understand the meaning of the above output.

>From the man page of diff-index:
- 100644 is the mode of "src"
- 100644 is the mode of dst
- abcdef is the hash of src
- 000000 is the hash of dst
- M stands for "Modified"
- file1 is the filename being considered.
>From my understanding, src here means the file system and dst the git

object. So the above should mean "file1" is new and out of sync with the index, which doesn't make sense since "file1" is definitely in the repository. The weird stuff is that diff-index report the same problem on every single file no just a few!

Notes:
 - Something I've noticed with Bamboo is that the cloned repository
doesn't have any remotes. Although I'm not sure if it is relevant
here.
 - I have tried with "shallow copy" Bamboo option enabled or not and I
get the same problems
 - I have tried "git update-index", but still get the same results
 - git log still gives me the full log history (but no remote heads)
 - git status reports nothing else than a couple of generated files
 - git status HEAD reports that the working directory is clean
 - git diff-index --cached reports nothing

Does any of you have ever come across this kind of problem? Could anyone shed some light on what's going on with our clone? Any documentation point out or hints appreciated.

Thanks, Chris

David Turner· Nov 3, 2015, 00:27 UTC · re: Ch'Gans · lore

Re: Strange diff-index output

On Tue, 2015-11-03 at 12:59 +1300, Ch'Gans wrote:
Show 6 quoted lines
> Hi there,
> 
> We're using a script to verify that what we are building is clean
> against our git repository, for this we're using "git rev-parse
> --short HEAD" to get the current hash and "git diff-index --quiet
> HEAD" to check for local modification.
See this note from the git diff-index man page:
           Note
           As with other commands of this type, git diff-index does not
           actually look at the contents of the file at all. So maybe
           kernel/sched.c hasn’t actually changed, and it’s just that
you
           touched it. In either case, it’s a note that you need to git
           update-index it to make the index be in sync.

You can either add an update-index to your script, or use git status --porcelain.

Ch'Gans· Nov 3, 2015, 01:00 UTC · re: David Turner · lore

Re: Strange diff-index output

On 3 November 2015 at 13:27, David Turner <dturner@twopensource.com> wrote:
Show 19 quoted lines
> On Tue, 2015-11-03 at 12:59 +1300, Ch'Gans wrote:
>> Hi there,
>>
>> We're using a script to verify that what we are building is clean
>> against our git repository, for this we're using "git rev-parse
>> --short HEAD" to get the current hash and "git diff-index --quiet
>> HEAD" to check for local modification.
>
> See this note from the git diff-index man page:
>            Note
>            As with other commands of this type, git diff-index does not
>            actually look at the contents of the file at all. So maybe
>            kernel/sched.c hasn’t actually changed, and it’s just that
> you
>            touched it. In either case, it’s a note that you need to git
>            update-index it to make the index be in sync.
>
> You can either add an update-index to your script, or use git status
> --porcelain.
Hi David,

I first tried "git update-index" but it didn't work. However "git update-index --refresh" seems to fix our problem. I didn't get why "--refresh" is needed thought, I'm really not familiar with the caching aspect of git. Anyway, I think that this fix is what I need right now.

Thanks, Chris

Show 5 quoted lines
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jeff King· Nov 4, 2015, 06:38 UTC · re: Ch'Gans · lore

Re: Strange diff-index output

On Tue, Nov 03, 2015 at 02:00:33PM +1300, Ch'Gans wrote:
> I first tried "git update-index" but it didn't work. However "git
> update-index --refresh" seems to fix our problem.
> I didn't get why "--refresh" is needed thought, I'm really not
> familiar with the caching aspect of git.

It is because update-index is a general command for manipulating the index. For example, you can add, delete, or change entries without regard to what is in the working tree.

One of the manipulations is "refresh the index based on what is in the working tree", and that is spelled "--refresh". Most porcelain-level git commands (like "git diff") will do this for you automatically and transparently. But when using the scriptable plumbing (like diff-index), git gives you more control. This lets you do things more efficiently (e.g,. you might refresh once and then issue several low-level commands), at the cost of convenience.

You could also have used "git diff-index --cached HEAD", which instructs diff-index not to look at the working tree at all (so you would compare whatever is in the index, whether it is up to date with what is in the working tree or not). Depending on what you are trying to achieve, that might be fine (it's also more efficient in general, as it does not require an lstat() of every file in the working tree).

-Peff

← back to recent threads