Skip to content

Commit e5fa45c

Browse files
committed
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 <[email protected]> Helped-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 05f6edc commit e5fa45c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

refs.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,22 @@ static struct ref_array *get_loose_refs(const char *submodule)
393393
#define MAXDEPTH 5
394394
#define MAXREFLEN (1024)
395395

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+
*/
396401
static int resolve_gitlink_packed_ref(char *name, int pathlen, const char *refname, unsigned char *result)
397402
{
398403
int retval = -1;
399404
struct ref_entry *ref;
400-
struct ref_array *array = get_packed_refs(name);
405+
struct ref_array *array;
401406

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);
402412
ref = search_ref_array(array, refname);
403413
if (ref != NULL) {
404414
memcpy(result, ref->sha1, 20);

t/t3000-ls-files-others.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,23 @@ test_expect_success '--no-empty-directory hides empty directory' '
6565
test_cmp expected3 output
6666
'
6767

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+
6887
test_done

0 commit comments

Comments
 (0)