@matheusbsbs / matheus-bagliano / commits / db137fe91e
Fork 0

read-tree: Fix regression with creation of a new index file.

Reading the index into an empty file has been broken by 5a56da58060e50980fab0f4c38203a25440d1530, since it causes the existing index to always be loaded first, and dies if it's an empty file: $ GIT_INDEX_FILE=`mktemp` git read-tree master fatal: index file smaller than expected It breaks for instance committing from git.el. This patch reverts to the previous behavior of only loading the index when merging it. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alexandre Julliard committed Aug 17, 2009 at 17:35 UTC db137fe91ea4afda7a2073364c610fe61dc769b8
2 files changed +31 -4
builtin-read-tree.c
+6 -4
@@ -113,13 +113,15 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
113 argc = parse_options(argc, argv, unused_prefix, read_tree_options,
114 read_tree_usage, 0);
115
116 - if (read_cache_unmerged() && (opts.prefix || opts.merge))
117 - die("You need to resolve your current index first");
118 -
116 prefix_set = opts.prefix ? 1 : 0;
117 if (1 < opts.merge + opts.reset + prefix_set)
118 die("Which one? -m, --reset, or --prefix?");
122 - stage = opts.merge = (opts.reset || opts.merge || prefix_set);
119 +
120 + if (opts.reset || opts.merge || opts.prefix) {
121 + if (read_cache_unmerged() && (opts.prefix || opts.merge))
122 + die("You need to resolve your current index first");
123 + stage = opts.merge = 1;
124 + }
125
126 for (i = 0; i < argc; i++) {
127 const char *arg = argv[i];
t/t1009-read-tree-new-index.sh new
+25
@@ -0,0 +1,25 @@
1 +#!/bin/sh
2 +
3 +test_description='test read-tree into a fresh index file'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 + echo one >a &&
9 + git add a &&
10 + git commit -m initial
11 +'
12 +
13 +test_expect_success 'non-existent index file' '
14 + rm -f new-index &&
15 + GIT_INDEX_FILE=new-index git read-tree master
16 +'
17 +
18 +test_expect_success 'empty index file' '
19 + rm -f new-index &&
20 + > new-index &&
21 + GIT_INDEX_FILE=new-index git read-tree master
22 +'
23 +
24 +test_done
25 +