Skip to content

Commit

Permalink
Merge branch 'rs/attr'
Browse files Browse the repository at this point in the history
* rs/attr:
  Ignore .gitattributes in bare repositories
  • Loading branch information
Junio C Hamano committed Jun 14, 2008
2 parents c8c6a2e + 2d35d55 commit b994ec1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
46 changes: 25 additions & 21 deletions attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,13 @@ static void bootstrap_attr_stack(void)
elem->prev = attr_stack;
attr_stack = elem;

elem = read_attr(GITATTRIBUTES_FILE, 1);
elem->origin = strdup("");
elem->prev = attr_stack;
attr_stack = elem;
debug_push(elem);
if (!is_bare_repository()) {
elem = read_attr(GITATTRIBUTES_FILE, 1);
elem->origin = strdup("");
elem->prev = attr_stack;
attr_stack = elem;
debug_push(elem);
}

elem = read_attr_from_file(git_path(INFOATTRIBUTES_FILE), 1);
if (!elem)
Expand Down Expand Up @@ -501,22 +503,24 @@ static void prepare_attr_stack(const char *path, int dirlen)
/*
* Read from parent directories and push them down
*/
while (1) {
char *cp;

len = strlen(attr_stack->origin);
if (dirlen <= len)
break;
memcpy(pathbuf, path, dirlen);
memcpy(pathbuf + dirlen, "/", 2);
cp = strchr(pathbuf + len + 1, '/');
strcpy(cp + 1, GITATTRIBUTES_FILE);
elem = read_attr(pathbuf, 0);
*cp = '\0';
elem->origin = strdup(pathbuf);
elem->prev = attr_stack;
attr_stack = elem;
debug_push(elem);
if (!is_bare_repository()) {
while (1) {
char *cp;

len = strlen(attr_stack->origin);
if (dirlen <= len)
break;
memcpy(pathbuf, path, dirlen);
memcpy(pathbuf + dirlen, "/", 2);
cp = strchr(pathbuf + len + 1, '/');
strcpy(cp + 1, GITATTRIBUTES_FILE);
elem = read_attr(pathbuf, 0);
*cp = '\0';
elem->origin = strdup(pathbuf);
elem->prev = attr_stack;
attr_stack = elem;
debug_push(elem);
}
}

/*
Expand Down
2 changes: 1 addition & 1 deletion git.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static void handle_internal_command(int argc, const char **argv)
{ "checkout-index", cmd_checkout_index,
RUN_SETUP | NEED_WORK_TREE},
{ "check-ref-format", cmd_check_ref_format },
{ "check-attr", cmd_check_attr, RUN_SETUP | NEED_WORK_TREE },
{ "check-attr", cmd_check_attr, RUN_SETUP },
{ "cherry", cmd_cherry, RUN_SETUP },
{ "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE },
{ "clone", cmd_clone },
Expand Down
35 changes: 35 additions & 0 deletions t/t0003-attributes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,39 @@ test_expect_success 'root subdir attribute test' '
'

test_expect_success 'setup bare' '
git clone --bare . bare.git &&
cd bare.git
'

test_expect_success 'bare repository: check that .gitattribute is ignored' '
(
echo "f test=f"
echo "a/i test=a/i"
) >.gitattributes &&
attr_check f unspecified &&
attr_check a/f unspecified &&
attr_check a/c/f unspecified &&
attr_check a/i unspecified &&
attr_check subdir/a/i unspecified
'

test_expect_success 'bare repository: test info/attributes' '
(
echo "f test=f"
echo "a/i test=a/i"
) >info/attributes &&
attr_check f f &&
attr_check a/f f &&
attr_check a/c/f f &&
attr_check a/i a/i &&
attr_check subdir/a/i unspecified
'

test_done

0 comments on commit b994ec1

Please sign in to comment.