commands/{un,}track: local-prefix agnostic comparison
This patch use the trimCurrentPrefix utility introduced in the previous patch to make all .gitattributes comparisons agnostic to the "current-prefix" of "./" or ".\". Since we treat both sides of the comparison as having passed through "trimCurrentPrefix", we harden ourselves against "legacy"-style .gitattributes patterns containing prefixes, and "modern"-style ones lacking prefixes. That means that both combinations of "git lfs untrack ./a.dat" and "git lfs untrack a.dat" will remove both of these lines from a .gittatributes file: ./a.dat filter=lfs ... a.dat filter=lfs ... Signed-off-by: Taylor Blau <me@ttaylorr.com>
This commit is contained in:
parent
1c8209bacf
commit
49bdc2b1b0
@ -67,7 +67,7 @@ func trackCommand(cmd *cobra.Command, args []string) {
|
||||
var writeablePatterns []string
|
||||
ArgsLoop:
|
||||
for _, unsanitizedPattern := range args {
|
||||
pattern := cleanRootPath(unsanitizedPattern)
|
||||
pattern := trimCurrentPrefix(cleanRootPath(unsanitizedPattern))
|
||||
if !trackNoModifyAttrsFlag {
|
||||
for _, known := range knownPatterns {
|
||||
if known.Path == filepath.Join(relpath, pattern) &&
|
||||
|
@ -63,8 +63,9 @@ func untrackCommand(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
func removePath(path string, args []string) bool {
|
||||
withoutCurrentDir := trimCurrentPrefix(path)
|
||||
for _, t := range args {
|
||||
if path == escapeAttrPattern(t) {
|
||||
if withoutCurrentDir == escapeAttrPattern(trimCurrentPrefix(t)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -540,3 +540,21 @@ begin_test "track (with comments)"
|
||||
[ "0" -eq "$(grep -c "\.png" track.log)" ]
|
||||
)
|
||||
end_test
|
||||
|
||||
begin_test "track (with current-directory prefix)"
|
||||
(
|
||||
set -e
|
||||
|
||||
reponame="track-with-current-directory-prefix"
|
||||
git init "$reponame"
|
||||
cd "$reponame"
|
||||
|
||||
git lfs track "./a.dat"
|
||||
printf "a" > a.dat
|
||||
|
||||
git add .gitattributes a.dat
|
||||
git commit -m "initial commit"
|
||||
|
||||
grep -e "^a.dat" .gitattributes
|
||||
)
|
||||
end_test
|
||||
|
@ -72,3 +72,65 @@ begin_test "untrack removes escape sequences"
|
||||
assert_attributes_count "\\#" "filter=lfs" 0
|
||||
)
|
||||
end_test
|
||||
|
||||
begin_test "untrack removes prefixed patterns (legacy)"
|
||||
(
|
||||
set -e
|
||||
|
||||
reponame="untrack-removes-prefix-patterns-legacy"
|
||||
git init "$reponame"
|
||||
cd "$reponame"
|
||||
|
||||
echo "./a.dat filter=lfs diff=lfs merge=lfs" > .gitattributes
|
||||
printf "a" > a.dat
|
||||
git add .gitattributes a.dat
|
||||
git commit -m "initial commit"
|
||||
|
||||
git lfs untrack "./a.dat"
|
||||
|
||||
if [ ! -z "$(cat .gitattributes)" ]; then
|
||||
echo &>2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git checkout -- .gitattributes
|
||||
|
||||
git lfs untrack "a.dat"
|
||||
|
||||
if [ ! -z "$(cat .gitattributes)" ]; then
|
||||
echo &>2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
end_test
|
||||
|
||||
begin_test "untrack removes prefixed patterns (modern)"
|
||||
(
|
||||
set -e
|
||||
|
||||
reponame="untrack-removes-prefix-patterns-modern"
|
||||
git init "$reponame"
|
||||
cd "$reponame"
|
||||
|
||||
echo "a.dat filter=lfs diff=lfs merge=lfs" > .gitattributes
|
||||
printf "a" > a.dat
|
||||
git add .gitattributes a.dat
|
||||
git commit -m "initial commit"
|
||||
|
||||
git lfs untrack "./a.dat"
|
||||
|
||||
if [ ! -z "$(cat .gitattributes)" ]; then
|
||||
echo &>2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git checkout -- .gitattributes
|
||||
|
||||
git lfs untrack "a.dat"
|
||||
|
||||
if [ ! -z "$(cat .gitattributes)" ]; then
|
||||
echo &>2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
end_test
|
||||
|
Loading…
Reference in New Issue
Block a user