summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a44c426)
raw | patch | inline | side by side (parent: a44c426)
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | |
Fri, 29 Jun 2007 17:32:46 +0000 (18:32 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 1 Jul 2007 20:26:05 +0000 (13:26 -0700) |
When a merge left unmerged entries, git add failed to pick up the
file mode from the index, when core.filemode == 0. If more than one
unmerged entry is there, the order of stage preference is 2, 1, 3.
Noticed by Johannes Sixt.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
file mode from the index, when core.filemode == 0. If more than one
unmerged entry is there, the order of stage preference is 2, 1, 3.
Noticed by Johannes Sixt.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache.c | patch | blob | history | |
t/t3700-add.sh | patch | blob | history |
diff --git a/read-cache.c b/read-cache.c
index 4362b11f475748e89e9deaf6257fb0c411948105..a363f312c7f70d2a087dc16ebfe0969a03c1be42 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
return 0;
}
+static int compare_name(struct cache_entry *ce, const char *path, int namelen)
+{
+ return namelen != ce_namelen(ce) || memcmp(path, ce->name, namelen);
+}
+
+static int index_name_pos_also_unmerged(struct index_state *istate,
+ const char *path, int namelen)
+{
+ int pos = index_name_pos(istate, path, namelen);
+ struct cache_entry *ce;
+
+ if (pos >= 0)
+ return pos;
+
+ /* maybe unmerged? */
+ pos = -1 - pos;
+ if (pos >= istate->cache_nr ||
+ compare_name((ce = istate->cache[pos]), path, namelen))
+ return -1;
+
+ /* order of preference: stage 2, 1, 3 */
+ if (ce_stage(ce) == 1 && pos + 1 < istate->cache_nr &&
+ ce_stage((ce = istate->cache[pos + 1])) == 2 &&
+ !compare_name(ce, path, namelen))
+ pos++;
+ return pos;
+}
+
int add_file_to_index(struct index_state *istate, const char *path, int verbose)
{
int size, namelen;
@@ -380,7 +408,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose)
* from it, otherwise assume unexecutable regular file.
*/
struct cache_entry *ent;
- int pos = index_name_pos(istate, path, namelen);
+ int pos = index_name_pos_also_unmerged(istate, path, namelen);
ent = (0 <= pos) ? istate->cache[pos] : NULL;
ce->ce_mode = ce_mode_from_stat(ent, st.st_mode);
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index ad8cc7d4ae88e2066d2f51b6a6a5a192780d5e9a..0d80c6aeadf30b0d4a9f9e8dc79f37d99e4b6068 100755 (executable)
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
git add 1/2/a 1/3/b 1/2/c
'
+test_expect_success 'git add and filemode=0 with unmerged entries' '
+ echo 1 > stage1 &&
+ echo 2 > stage2 &&
+ echo 3 > stage3 &&
+ for s in 1 2 3
+ do
+ echo "100755 $(git hash-object -w stage$s) $s file"
+ done | git update-index --index-info &&
+ git config core.filemode 0 &&
+ echo new > file &&
+ git add file &&
+ git ls-files --stage | grep "^100755 .* 0 file$"
+'
+
+test_expect_success 'git add and filemode=0 prefers stage 2 over stage 1' '
+ git rm --cached -f file &&
+ (
+ echo "100644 $(git hash-object -w stage1) 1 file"
+ echo "100755 $(git hash-object -w stage2) 2 file"
+ ) | git update-index --index-info &&
+ git config core.filemode 0 &&
+ echo new > file &&
+ git add file &&
+ git ls-files --stage | grep "^100755 .* 0 file$"
+'
+
test_done