8000 attr: Missing support for .gitattributes files with quoted patterns · Issue #5781 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content
attr: Missing support for .gitattributes files with quoted patterns #5781
Open
@beepboop271

Description

@beepboop271

From the git docs:

Leading and trailing whitespaces are ignored. Lines that begin with # are ignored. Patterns that begin with a double quote are quoted in C style. When the pattern matches the path in question, the attributes listed on the line are given to the path.

Looks like the change to add quoted patterns was made in git/git@860a74d

Reproduction steps

Make a new empty git repository with git init.
Create a .gitattributes file:

test file attr
"test" attr2
"test file" attr2

Create a program which tries to open the repository and read attributes:

#include <stdio.h>
#include "git2.h"

void attr_check(git_repository *repo, const char *path, const char *name) {
    const char *attr;
    git_attr_get(&attr, repo, 0, path, name);
    printf("%d\n", GIT_ATTR_IS_TRUE(attr));
}

int main() {
    git_libgit2_init();
    git_repository *repo;
    git_repository_open(&repo, ".");

    // should be false, true, true because 'test file attr'
    // assigns 'file' and 'attr' to 'test'
    attr_check(repo, "test file", "attr");
    attr_check(repo, "test", "attr");
    attr_check(repo, "test", "file");

    // should be true, false from the line '"test" attr2'
    // treating "test" as test in quotes and not literal "test"
    attr_check(repo, "test", "attr2");
    attr_check(repo, "\"test\"", "attr2");

    // should be true from the line '"test file" attr2'
    attr_check(repo, "test file", "attr2");

    return 0;
}

Expected behavior

The output of the program should be 0, 1, 1, 1, 0, 1, which would match the output of the command git check-attr that can check for what attributes are set on the given paths:

$ git check-attr --all test 'test file'
test: file: set
test: attr: set
test: attr2: set
test file: attr2: set

$ git check-attr attr2 '"test"'
"\"test\"": attr2: unspecified

Actual behavior

The output of the program is 0, 1, 1, 0, 1, 0; it appears quotes are not processed like git.

Version of libgit2 (release number or SHA1)

Release 1.1.0

Operating system(s) tested

Windows 10 2004, using WSL 1 to run Ubuntu 18.04.5 LTS

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0