Code Monkey home page Code Monkey logo

Comments (3)

huush avatar huush commented on June 26, 2024 1

Also, the linked Generator appears to not pick up the files in Global and Community

from gitattributes.

alexkaratarakis avatar alexkaratarakis commented on June 26, 2024

What happens if there are then multiple lines of "* text=auto" throughout the file? Does this cause some form of reset of the overrides? Can this generated file actually be used, or do we first need to filter this combined file and remove all duplication?

That is a good point! Let's explore. I made a toy repository with just 2 files:

.gitattributes
 test.cpp

git check-attr --all test.cpp returns what git treats the file as. Here are the results for a given .gitattribute file:
(git version 2.34.1)

(1)

* text=auto
*.cpp binary
*.cpp text
test.cpp: binary: set
test.cpp: diff: unset
test.cpp: merge: unset
test.cpp: text: set

(2)

*.cpp binary
*.cpp text
* text=auto
test.cpp: binary: set
test.cpp: diff: unset
test.cpp: merge: unset
test.cpp: text: auto

(3)

* text=auto
*.cpp text
*.cpp binary
test.cpp: binary: set
test.cpp: diff: unset
test.cpp: merge: unset
test.cpp: text: unset

(4)

*.cpp text
*.cpp binary
* text=auto
test.cpp: binary: set
test.cpp: diff: unset
test.cpp: merge: unset
test.cpp: text: auto

The results are interesting. It seems like the last entry takes precedence, so text is either auto or set depending on the last entry. But also binary seems to "win" regardless of where it is. binary is always set in the above cases and it even unsets text when it comes last.

This doesn't look immediately obvious, so a Generator could flatten and deduplicate entries to avoid possible confusion - and have the entry match what git would have done if all entries where present.
On the other hand, having separate sections for each gitattribute that you used is very similar to what one would do manually (without a generator) and allows further manual modification and future update because any section would be exactly as you found it from the source.
I think it could go either way (maybe an option?).

Note that the behavior would be easily observable. If binary is set, then we get the following with git diff:

diff --git a/test.cpp b/test.cpp
index cc3f56d..1df2af6 100644
Binary files a/test.cpp and b/test.cpp differ

whereas if it is not set, then:

diff --git a/test.cpp b/test.cpp
index cc3f56d..1df2af6 100644
--- a/test.cpp
+++ b/test.cpp
@@ -1 +1,2 @@
 // blah
+// blah2

Similarly, with customized diff options, the diff would show the "winning" setting.

from gitattributes.

alexkaratarakis avatar alexkaratarakis commented on June 26, 2024

Also, the linked Generator appears to not pick up the files in Global and Community

You are right. The subfolders are recent additions. The generator(s) have not been updated to take this into account.

from gitattributes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.