@matheusbsbs / matheus-bagliano / commits / 2d35d556e2
Fork 0

Ignore .gitattributes in bare repositories

Attributes can be specified at three different places: the internal table of default values, the file $GIT_DIR/info/attributes and files named .gitattributes in the work tree. Since bare repositories don't have a work tree, git should ignore any .gitattributes files there. This patch makes git do that, so the only way left for a user to specify attributes in a bare repository is the file info/attributes (in addition to changing the defaults and recompiling). In addition, git-check-attr is now allowed to run without a work tree. Like any user of the code in attr.c, it ignores the .gitattributes files when run in a bare repository. It can still read from info/attributes. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jun 8, 2008 at 17:16 UTC 2d35d556e27cd3e7f3d2eea04a7f0d7ee8513f8e
3 files changed +61 -22
attr.c
+25 -21
@@ -438,11 +438,13 @@ static void bootstrap_attr_stack(void)
438 elem->prev = attr_stack;
439 attr_stack = elem;
440
441 - elem = read_attr(GITATTRIBUTES_FILE, 1);
442 - elem->origin = strdup("");
443 - elem->prev = attr_stack;
444 - attr_stack = elem;
445 - debug_push(elem);
441 + if (!is_bare_repository()) {
442 + elem = read_attr(GITATTRIBUTES_FILE, 1);
443 + elem->origin = strdup("");
444 + elem->prev = attr_stack;
445 + attr_stack = elem;
446 + debug_push(elem);
447 + }
448
449 elem = read_attr_from_file(git_path(INFOATTRIBUTES_FILE), 1);
450 if (!elem)
@@ -501,22 +503,24 @@ static void prepare_attr_stack(const char *path, int dirlen)
503 /*
504 * Read from parent directories and push them down
505 */
504 - while (1) {
505 - char *cp;
506 -
507 - len = strlen(attr_stack->origin);
508 - if (dirlen <= len)
509 - break;
510 - memcpy(pathbuf, path, dirlen);
511 - memcpy(pathbuf + dirlen, "/", 2);
512 - cp = strchr(pathbuf + len + 1, '/');
513 - strcpy(cp + 1, GITATTRIBUTES_FILE);
514 - elem = read_attr(pathbuf, 0);
515 - *cp = '\0';
516 - elem->origin = strdup(pathbuf);
517 - elem->prev = attr_stack;
518 - attr_stack = elem;
519 - debug_push(elem);
506 + if (!is_bare_repository()) {
507 + while (1) {
508 + char *cp;
509 +
510 + len = strlen(attr_stack->origin);
511 + if (dirlen <= len)
512 + break;
513 + memcpy(pathbuf, path, dirlen);
514 + memcpy(pathbuf + dirlen, "/", 2);
515 + cp = strchr(pathbuf + len + 1, '/');
516 + strcpy(cp + 1, GITATTRIBUTES_FILE);
517 + elem = read_attr(pathbuf, 0);
518 + *cp = '\0';
519 + elem->origin = strdup(pathbuf);
520 + elem->prev = attr_stack;
521 + attr_stack = elem;
522 + debug_push(elem);
523 + }
524 }
525
526 /*
git.c
+1 -1
@@ -286,7 +286,7 @@ static void handle_internal_command(int argc, const char **argv)
286 { "checkout-index", cmd_checkout_index,
287 RUN_SETUP | NEED_WORK_TREE},
288 { "check-ref-format", cmd_check_ref_format },
289 - { "check-attr", cmd_check_attr, RUN_SETUP | NEED_WORK_TREE },
289 + { "check-attr", cmd_check_attr, RUN_SETUP },
290 { "cherry", cmd_cherry, RUN_SETUP },
291 { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE },
292 { "clone", cmd_clone },
t/t0003-attributes.sh
+35
@@ -54,4 +54,39 @@ test_expect_success 'root subdir attribute test' '
54
55 '
56
57 +test_expect_success 'setup bare' '
58 +
59 + git clone --bare . bare.git &&
60 + cd bare.git
61 +
62 +'
63 +
64 +test_expect_success 'bare repository: check that .gitattribute is ignored' '
65 +
66 + (
67 + echo "f test=f"
68 + echo "a/i test=a/i"
69 + ) >.gitattributes &&
70 + attr_check f unspecified &&
71 + attr_check a/f unspecified &&
72 + attr_check a/c/f unspecified &&
73 + attr_check a/i unspecified &&
74 + attr_check subdir/a/i unspecified
75 +
76 +'
77 +
78 +test_expect_success 'bare repository: test info/attributes' '
79 +
80 + (
81 + echo "f test=f"
82 + echo "a/i test=a/i"
83 + ) >info/attributes &&
84 + attr_check f f &&
85 + attr_check a/f f &&
86 + attr_check a/c/f f &&
87 + attr_check a/i a/i &&
88 + attr_check subdir/a/i unspecified
89 +
90 +'
91 +
92 test_done