[patch] Fix a corner case in git update-index --index-info
- From
Thomas Jarosch <thomas.jarosch@intra2net.com>
- Date
- Dec 13, 2008, 13:03 UTC
- Message-ID
- <200812131403.08740.thomas.jarosch@intra2net.com>
Fix a corner case in git update-index --index-info: If there are no input lines, it won't create an empty index.
Here's a short test for this: echo -n "" |GIT_INDEX_FILE=index.new git update-index --index-info -> The index "index.new" won't get created
It failed for me while I was using git filter-branch as described in the man page:
git filter-branch --index-filter \
´git ls-files -s | sed "s-\t-&newsubdir/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE´ HEADThe conversion aborted because the first commit was empty. (created by cvs2svn)
Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
diff --git a/builtin-update-index.c b/builtin-update-index.c index 65d5775..998a48e 100644 --- a/builtin-update-index.c +++ b/builtin-update-index.c @@ -299,6 +299,7 @@ static void read_index_info(int line_termination) { struct strbuf buf = STRBUF_INIT; struct strbuf uq = STRBUF_INIT; + int found_something = 0; while (strbuf_getline(&buf, stdin, line_termination) != EOF) { char *ptr, *tab; @@ -308,6 +309,8 @@ static void read_index_info(int line_termination) unsigned long ul; int stage; + found_something = 1; + /* This reads lines formatted in one of three formats: * * (1) mode SP sha1 TAB path @@ -383,6 +386,11 @@ static void read_index_info(int line_termination) bad_line: die("malformed index info %s", buf.buf); } + + /* Force creation of empty index - needed by git filter-branch */ + if (!found_something) + active_cache_changed = 1; + strbuf_release(&buf); strbuf_release(&uq); }