migrate import: set text to unspecified for excluded fields

When we specify the --exclude option to git lfs migrate import to
exclude certain patterns, we currently specify the files as text.
However, in many cases, the files are not text, so it doesn't make sense
to set them that way.

Let's set the text attribute to unspecified instead and let Git
automatically figure out whether the file should be treated as text or
binary.  That's at least less likely to result in silent breakage and
will likely be less surprising to the user.
This commit is contained in:
brian m. carlson 2020-03-11 14:46:01 +00:00
parent 26a7961d10
commit c8524d2563
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1
2 changed files with 33 additions and 1 deletions

@ -283,7 +283,7 @@ func trackedFromFilter(filter *filepathfilter.Filter) *tools.OrderedSet {
}
for _, exclude := range filter.Exclude() {
tracked.Add(fmt.Sprintf("%s text -filter -merge -diff", escapeAttrPattern(exclude)))
tracked.Add(fmt.Sprintf("%s !text -filter -merge -diff", escapeAttrPattern(exclude)))
}
return tracked

@ -439,6 +439,38 @@ EOF)
)
end_test
begin_test "migrate import (--exclude with existing .gitattributes)"
(
set -e
setup_local_branch_with_gitattrs
pwd
master="$(git rev-parse refs/heads/master)"
txt_master_oid="$(calc_oid "$(git cat-file -p "$master:a.txt")")"
git lfs migrate import --yes --include-ref=refs/heads/master --include="*.txt" --exclude="*.bin"
assert_local_object "$txt_master_oid" "120"
master="$(git rev-parse refs/heads/master)"
prev="$(git rev-parse refs/heads/master^1)"
diff -u <(git cat-file -p $master:.gitattributes) <(cat <<-EOF
*.txt filter=lfs diff=lfs merge=lfs -text
*.other filter=lfs diff=lfs merge=lfs -text
*.bin !text -filter -merge -diff
EOF)
diff -u <(git cat-file -p $prev:.gitattributes) <(cat <<-EOF
*.txt filter=lfs diff=lfs merge=lfs -text
*.bin !text -filter -merge -diff
EOF)
)
end_test
begin_test "migrate import (identical contents, different permissions)"
(
set -e