Skip to content

Commit

Permalink
Merge pull request #2983 from patrickmarlier/symlink
Browse files Browse the repository at this point in the history
Do not migrate the symlinks to LFS objects.
  • Loading branch information
ttaylorr authored Apr 27, 2018
2 parents 67d8674 + f7349b4 commit 41794df
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
6 changes: 6 additions & 0 deletions git/githistory/rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ func (r *Rewriter) rewriteTree(commitOID []byte, treeOID []byte, path string, fn
continue
}

// If this is a symlink, skip it
if entry.Filemode == 0120000 {
entries = append(entries, copyEntry(entry))
continue
}

if cached := r.uncacheEntry(entry); cached != nil {
entries = append(entries, copyEntry(cached))
continue
Expand Down
25 changes: 24 additions & 1 deletion test/test-migrate-fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ assert_ref_unmoved() {
fi
}

# setup_multiple_local_branches creates a repository as follows:
# setup_local_branch_with_gitattrs creates a repository as follows:
#
# A---B
# \
Expand Down Expand Up @@ -261,6 +261,29 @@ setup_single_local_branch_deep_trees() {
git commit -m "initial commit"
}

# setup_local_branch_with_symlink creates a repository as follows:
#
# A
# \
# refs/heads/master
#
# - Commit 'A' has 120, in a.txt, and a symbolic link link.txt to a.txt.
setup_local_branch_with_symlink() {
set -e

reponame="migrate-single-local-branch-with-symlink"

remove_and_create_local_repo "$reponame"

base64 < /dev/urandom | head -c 120 > a.txt

git add a.txt
git commit -m "initial commit"

add_symlink "a.txt" "link.txt"
git commit -m "add symlink"
}

# make_bare converts the existing full checkout of a repository into a bare one,
# and then `cd`'s into it.
make_bare() {
Expand Down
20 changes: 20 additions & 0 deletions test/test-migrate-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,24 @@ begin_test "migrate import (--include with space)"
sed -e 's/^/ /g' < .gitattributes >&2
exit 1
fi
)
end_test
begin_test "migrate import (handle symbolic link)"
(
set -e
setup_local_branch_with_symlink
txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
link_oid="$(calc_oid "$(git cat-file -p :link.txt)")"
git lfs migrate import --include="*.txt"
assert_pointer "refs/heads/master" "a.txt" "$txt_oid" "120"
assert_local_object "$txt_oid" "120"
# "link.txt" is a symbolic link so it should be not in LFS
refute_local_object "$link_oid" "5"
)
end_test
11 changes: 11 additions & 0 deletions test/testhelpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,14 @@ has_test_dir() {
exit 0
fi
}

add_symlink() {
local src=$1
local dest=$2

prefix=`git rev-parse --show-prefix`
hashsrc=`printf "$src" | git hash-object -w --stdin`

git update-index --add --cacheinfo 120000 "$hashsrc" "$prefix$dest"
git checkout -- "$dest"
}

0 comments on commit 41794df

Please sign in to comment.