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

update-index --index-info producing spurious submodule commits

From
GTGreg Troxel <gdt@ir.bbn.com>
Date
Aug 18, 2011, 21:53 UTC
Message-ID
<rmivctuv12s.fsf@fnord.ir.bbn.com>

For reasons too complicated to go into, I have a repository B which has essentially been cloned from A, and there has been vast amounts of work on B (thousands of commits, many branches). These changes have not been merged back to A. I want to merge them back, but there's a directory foo that has changes in B that I can't release.

So, I ran filter-branch with an index filter
  found the merge base with A
  removed foo
  did ls-tree on foo from merge base
    and updated the index

The theory is to make each commit in B look like no changes to anything under foo, and otherwise the same.

After doing this, Richard noticed that the root tree of commits had a foo object, but that it was labeled a commit instead of a tree (but in fact it is a tree). He noticed because diffs looked like submodules.

I was able to produce a minimal test case, output below, script attached. The below output is with 1.7.5.4 on NetBSD/i386 (and /amd64). 1.7.6 (ubuntu/amd64) has the same problem.

So:
  Am I using "git update-index --index-info" wrong?
  Or is there a bug?

Thanks, Greg

Notice that "cat-file -p HEAD:" shows a tree before, and a commit afterwards:

+ git init
Initialized empty Git repository in /usr/home/gdt/GIT_TEST/.git/
+ mkdir foo
+ touch foo/bar
+ git add foo
+ git commit -minitial content
[master (root-commit) 6755919] initial content
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 foo/bar
+ git cat-file -p HEAD
tree 72d67e6de0599f72f1265c925316f91f78395787
author Greg Troxel <gdt@ir.bbn.com> 1313703545 -0400
committer Greg Troxel <gdt@ir.bbn.com> 1313703545 -0400
initial content
+ git cat-file -p HEAD:
040000 tree d87cbcba0e2ede0752bdafc5938da35546803ba5	foo
+ git rm -r foo
rm 'foo/bar'
+ git ls-tree HEAD foo
040000 tree d87cbcba0e2ede0752bdafc5938da35546803ba5	foo
+ git ls-tree HEAD foo
+ git update-index --index-info
+ git diff --staged
diff --git a/foo b/foo
new file mode 160000
index 0000000..d87cbcb
--- /dev/null
+++ b/foo
@@ -0,0 +1 @@
+Subproject commit d87cbcba0e2ede0752bdafc5938da35546803ba5
diff --git a/foo/bar b/foo/bar
deleted file mode 100644
index e69de29..0000000
+ git commit -mmunged foo
[master 3348447] munged foo
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 160000 foo
 delete mode 100644 foo/bar
+ git cat-file -p HEAD
tree 04fbd499dbd01afb3241d7f0af8171fde008bfe3
parent 6755919e289665ec46d270672d29b594f992fa03
author Greg Troxel <gdt@ir.bbn.com> 1313703545 -0400
committer Greg Troxel <gdt@ir.bbn.com> 1313703545 -0400

munged foo
+ git cat-file -p HEAD:
160000 commit d87cbcba0e2ede0752bdafc5938da35546803ba5	foo




#!/bin/sh

if [ -d .git ]; then
   echo "existing .git"
   exit 1
fi

set -x

git init
mkdir foo
touch foo/bar
git add foo
git commit -m'initial content'
git cat-file -p HEAD
git cat-file -p HEAD:
git rm -r foo
git ls-tree HEAD foo
git ls-tree HEAD foo | git update-index --index-info
git diff --staged
git commit -m'munged foo'
git cat-file -p HEAD
git cat-file -p HEAD:
Next: Junio C Hamano
Message 1 of 7 in “update-index --index-info producing spurious submodule commits”
  1. Greg TroxelAug 18, 2011
  2. Junio C HamanoAug 18, 2011
  3. Greg TroxelAug 19, 2011
  4. Junio C HamanoAug 19, 2011
  5. Greg TroxelAug 19, 2011
  6. Jonathan NiederAug 20, 2011
  7. Junio C HamanoAug 19, 2011

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.