commnads/migrate: add test for persisting gitattrs changes
This commit is contained in:
parent
92205c8b5c
commit
812407fc9f
@ -29,6 +29,10 @@ func migrateImportCommand(cmd *cobra.Command, args []string) {
|
||||
|
||||
migrate(args, rewriter, &githistory.RewriteOptions{
|
||||
BlobFn: func(path string, b *odb.Blob) (*odb.Blob, error) {
|
||||
if filepath.Base(path) == ".gitattributes" {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := clean(&buf, b.Contents, path, b.Size); err != nil {
|
||||
@ -115,7 +119,7 @@ func trackedFromFilter(filter *filepathfilter.Filter) *tools.OrderedSet {
|
||||
var (
|
||||
// attrsCache maintains a cache from the hex-encoded SHA1 of a
|
||||
// .gitattributes blob to the set of patterns parsed from that blob.
|
||||
attrsCache map[string]*tools.OrderedSet
|
||||
attrsCache = make(map[string]*tools.OrderedSet)
|
||||
)
|
||||
|
||||
// trackedFromAttrs returns an ordered line-delimited set of the contents of a
|
||||
|
@ -18,6 +18,32 @@ assert_ref_unmoved() {
|
||||
fi
|
||||
}
|
||||
|
||||
# setup_multiple_local_branches creates a repository as follows:
|
||||
#
|
||||
# A---B
|
||||
# \
|
||||
# refs/heads/master
|
||||
#
|
||||
# - Commit 'A' has 120, in a.txt, and a corresponding entry in .gitattributes.
|
||||
setup_local_branch_with_gitattrs() {
|
||||
set -e
|
||||
|
||||
reponame="migrate-single-remote-branch-with-attrs"
|
||||
|
||||
remove_and_create_local_repo "$reponame"
|
||||
|
||||
base64 < /dev/urandom | head -c 120 > a.txt
|
||||
|
||||
git add a.txt
|
||||
git commit -m "initial commit"
|
||||
|
||||
git lfs track "*.txt"
|
||||
git lfs track "*.other"
|
||||
|
||||
git add .gitattributes
|
||||
git commit -m "add .gitattributes"
|
||||
}
|
||||
|
||||
# setup_multiple_local_branches creates a repository as follows:
|
||||
#
|
||||
# B
|
||||
|
@ -281,3 +281,33 @@ begin_test "migrate import (include/exclude ref with filter)"
|
||||
echo "$feature_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs"
|
||||
)
|
||||
end_test
|
||||
|
||||
begin_test "migrate import (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 --include-ref=refs/heads/master --include="*.txt"
|
||||
|
||||
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
|
||||
EOF)
|
||||
|
||||
diff -u <(git cat-file -p $prev:.gitattributes) <(cat <<-EOF
|
||||
*.txt filter=lfs diff=lfs merge=lfs -text
|
||||
EOF)
|
||||
)
|
||||
end_test
|
||||
|
Loading…
Reference in New Issue
Block a user