resolve_gitlink_packed_ref(): fix mismerge
2c5c66b (Merge branch 'jp/get-ref-dir-unsorted', 2011-10-10) merged a topic that forked from the mainline before a new helper function get_packed_refs() refactored code to read packed-refs file. The merge made the call to the helper function with an incorrect argument. The parameter to the function has to be a path to the submodule. Fix the mismerge. Helped-by: Mark Levedahl <mlevedahl@gmail.com> Helped-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Oct 17, 2011 at 11:43 UTC
e5fa45c159241b609bce40fa7a8687796e4b941d
2 files changed
+30
-1
refs.c
+11
-1
@@ -393,12 +393,22 @@ static struct ref_array *get_loose_refs(const char *submodule)
393
#define MAXDEPTH 5
394
#define MAXREFLEN (1024)
395
396
+/*
397
+ * Called by resolve_gitlink_ref_recursive() after it failed to read
398
+ * from "name", which is "module/.git/<refname>". Find <refname> in
399
+ * the packed-refs file for the submodule.
400
+ */
401
static int resolve_gitlink_packed_ref(char *name, int pathlen, const char *refname, unsigned char *result)
402
{
403
int retval = -1;
404
struct ref_entry *ref;
400
- struct ref_array *array = get_packed_refs(name);
405
+ struct ref_array *array;
406
407
+ /* being defensive: resolve_gitlink_ref() did this for us */
408
+ if (pathlen < 6 || memcmp(name + pathlen - 6, "/.git/", 6))
409
+ die("Oops");
410
+ name[pathlen - 6] = '\0'; /* make it path to the submodule */
411
+ array = get_packed_refs(name);
412
ref = search_ref_array(array, refname);
413
if (ref != NULL) {
414
memcpy(result, ref->sha1, 20);
t/t3000-ls-files-others.sh
+19
@@ -65,4 +65,23 @@ test_expect_success '--no-empty-directory hides empty directory' '
65
test_cmp expected3 output
66
'
67
68
+test_expect_success SYMLINKS 'ls-files --others with symlinked submodule' '
69
+ git init super &&
70
+ git init sub &&
71
+ (
72
+ cd sub &&
73
+ >a &&
74
+ git add a &&
75
+ git commit -m sub &&
76
+ git pack-refs --all
77
+ ) &&
78
+ (
79
+ cd super &&
80
+ "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" ../sub sub
81
+ git ls-files --others --exclude-standard >../actual
82
+ ) &&
83
+ echo sub/ >expect &&
84
+ test_cmp expect actual
85
+'
86
+
87
test_done