Update how git-theta track ${path} works.#227
Conversation
|
Maybe this is a silly question, but
Why can't we just check if the file is already tracked (by inspecting the .gitattributes file) and throw a warning/don't track if it is? |
|
It depends if we want If we want to always have a specific line for our current model there were issue detecting if a match was general or specific which is why I didn't have a check like that. Does this make sense: When |
|
Ah, I forgot about wildcard. Just to clarify,
Does this include a config line that covers path via a wildcard?
Seems like a crashable offense to me. |
This would include a config line that covers a path via wild card if it was the last config line that covers that path If my path was would result in no-op, but would result in an error |
|
Cool, SGTM. |
d561c84 to
b922c42
Compare
|
I updated this PR to the behavior we discussed. |
Currently, when a pattern in `.gitattributes` matches the path in `git-theta track`, the theta attributes (filter, merge, diff) are added to that line. This can cause issues as it may result in tracking more files with git-theta than expected. However, just adding a new line that is an exact match for the path to the end of the gitattribute file is not correct either. The *last* attribute line in the file is the one used by Git. This could result in `git-theta track` removing an some other attribute that is set for that file. This PR updates the way that git attributes are set. If there are already git attributes set to non-theta values for the file that are used by git-theta (filter, merge, diff) an error is raised. If these attributes are all set to git-theta, no new entry is added, even when the entry is a pattern match instead of an exact match. If the new file has no attributes set, or attributes that don't overlap with git-theta, then a new entry is added. Non-overlapping attributes are copied down if they were set before. When a line has an attribute set multiple times, the *last* one is used so we can add the theta filters at the end to override any previous ones. Added a `is_theta_tracked` function similar to the one from r-three#214 where the test for if a file is tracked by Git-Theta is abstracted into a function. However it is implemented differently as it now handles the subtleties of what attribute line is active at a given time. Only the final line that a path matches is used to set attributes and only the last entry for some key is used. This is now respected. Git attributes support the "unsetting" of attributes (e.g. "-diff"), these attributes are correctly copied around, but they aren't currently logically checked to see if they intersect with git-theta attributes.
b922c42 to
6abc2be
Compare
Currently, when a pattern in
.gitattributesmatches the path ingit-theta track, the theta attributes (filter, merge, diff) are added to that line. This can cause issues as it may result in tracking more files with git-theta than expected.However, just adding a new line that is an exact match for the path to the end of the gitattribute file is not correct either. The last attribute line in the file is the one used by Git. This could result in
git-theta trackremoving an some other attribute that is set for that file.This PR updates the way that git attributes are set. A new line that is an exact match to the current path is added, the currently active attributes are copied over, and the new theta attributes are added.
When a line has an attribute set multiple times, the last one is used so we can add the theta filters at the end to override any previous ones.
Note that with this PR running
git-theta trackon the same file multiple times it will keep adding lines to.gitattributes.This change is based on a comment in #214
This also adds a
is_theta_trackedfunction. (I meant to make it in a different branch lol)This change is based on a part of
#214 where the test for if a
file is tracked by Git-Theta is abstracted into a function.
However it is implemented differently as it now handles the subtleties of
what attribute line is active at a given time.
Only the final line that a path matches is used to set attributes and
only the last entry for some key is used. This is now respected.****