2018-05-26 00:11:14 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-07-11 18:15:53 +00:00
|
|
|
. "$(dirname "$0")/fixtures/migrate.sh"
|
2018-07-10 18:48:02 +00:00
|
|
|
. "$(dirname "$0")/testlib.sh"
|
2018-05-26 00:11:14 +00:00
|
|
|
|
|
|
|
begin_test "migrate import --no-rewrite (default branch)"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
setup_local_branch_with_gitattrs
|
|
|
|
|
|
|
|
txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
|
|
|
|
prev_commit_oid="$(git rev-parse HEAD)"
|
|
|
|
|
commands: warn if working copy is dirty
In 'git lfs migrate import' and 'git lfs migrate export', Git LFS makes
destructive changes to a caller's repository and therefore invokes 'git
checkout --force', which throws away local changes.
To prevent this, let's introduce a check that notifies users when they
are going to throw away local changes, and allows for the user to abort
if they do not wish to discard their local changes.
With this, a user can safely migrate over dirty repositories (i.e., in
the case that they wanted to fix a file that should have been in Git
LFS, but wasn't) without having to finagle their repository to get it
into a migrate-able state.
For users with lots of pending migrations, also teach --yes, which
allows a user to avoid the check, and instead simply prints the warning
message to STDERR.
2018-07-10 15:18:46 +00:00
|
|
|
git lfs migrate import --no-rewrite --yes *.txt
|
2018-05-26 00:11:14 +00:00
|
|
|
|
|
|
|
# Ensure our desired files were imported into git-lfs
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120"
|
2018-05-26 00:11:14 +00:00
|
|
|
assert_local_object "$txt_oid" "120"
|
|
|
|
|
|
|
|
# Ensure the git history remained the same
|
|
|
|
new_commit_oid="$(git rev-parse HEAD~1)"
|
|
|
|
if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure a new commit was made
|
|
|
|
new_head_oid="$(git rev-parse HEAD)"
|
|
|
|
if [ "$prev_commit_oid" == "$new_oid" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure a new commit message was generated based on the list of imported files
|
|
|
|
commit_msg="$(git log -1 --pretty=format:%s)"
|
|
|
|
echo "$commit_msg" | grep -q "a.txt: convert to Git LFS"
|
2018-10-11 18:50:04 +00:00
|
|
|
|
|
|
|
# Ensure we write a valid commit object.
|
|
|
|
git fsck
|
2018-05-26 00:11:14 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "migrate import --no-rewrite (bare repository)"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
setup_single_remote_branch_with_gitattrs
|
|
|
|
|
|
|
|
prev_commit_oid="$(git rev-parse HEAD)"
|
|
|
|
txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
|
|
|
|
md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
|
|
|
|
|
commands: warn if working copy is dirty
In 'git lfs migrate import' and 'git lfs migrate export', Git LFS makes
destructive changes to a caller's repository and therefore invokes 'git
checkout --force', which throws away local changes.
To prevent this, let's introduce a check that notifies users when they
are going to throw away local changes, and allows for the user to abort
if they do not wish to discard their local changes.
With this, a user can safely migrate over dirty repositories (i.e., in
the case that they wanted to fix a file that should have been in Git
LFS, but wasn't) without having to finagle their repository to get it
into a migrate-able state.
For users with lots of pending migrations, also teach --yes, which
allows a user to avoid the check, and instead simply prints the warning
message to STDERR.
2018-07-10 15:18:46 +00:00
|
|
|
git lfs migrate import --no-rewrite --yes a.txt a.md
|
2018-05-26 00:11:14 +00:00
|
|
|
|
|
|
|
# Ensure our desired files were imported
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "30"
|
|
|
|
assert_pointer "refs/heads/main" "a.md" "$md_oid" "50"
|
2018-05-26 00:11:14 +00:00
|
|
|
|
|
|
|
# Ensure the git history remained the same
|
|
|
|
new_commit_oid="$(git rev-parse HEAD~1)"
|
|
|
|
if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure a new commit was made
|
|
|
|
new_head_oid="$(git rev-parse HEAD)"
|
|
|
|
if [ "$prev_commit_oid" == "$new_oid" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "migrate import --no-rewrite (multiple branches)"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
setup_multiple_local_branches_with_gitattrs
|
|
|
|
|
|
|
|
prev_commit_oid="$(git rev-parse HEAD)"
|
|
|
|
|
|
|
|
md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
|
|
|
|
txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
|
|
|
|
md_feature_oid="$(calc_oid "$(git cat-file -p my-feature:a.md)")"
|
|
|
|
|
commands: warn if working copy is dirty
In 'git lfs migrate import' and 'git lfs migrate export', Git LFS makes
destructive changes to a caller's repository and therefore invokes 'git
checkout --force', which throws away local changes.
To prevent this, let's introduce a check that notifies users when they
are going to throw away local changes, and allows for the user to abort
if they do not wish to discard their local changes.
With this, a user can safely migrate over dirty repositories (i.e., in
the case that they wanted to fix a file that should have been in Git
LFS, but wasn't) without having to finagle their repository to get it
into a migrate-able state.
For users with lots of pending migrations, also teach --yes, which
allows a user to avoid the check, and instead simply prints the warning
message to STDERR.
2018-07-10 15:18:46 +00:00
|
|
|
git lfs migrate import --no-rewrite --yes *.txt *.md
|
2018-05-26 00:11:14 +00:00
|
|
|
|
|
|
|
# Ensure our desired files were imported
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_pointer "refs/heads/main" "a.md" "$md_oid" "140"
|
|
|
|
assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120"
|
2018-05-26 00:11:14 +00:00
|
|
|
|
|
|
|
assert_local_object "$md_oid" "140"
|
|
|
|
assert_local_object "$txt_oid" "120"
|
|
|
|
|
|
|
|
# Ensure our other branch was unmodified
|
|
|
|
refute_local_object "$md_feature_oid" "30"
|
|
|
|
|
|
|
|
# Ensure the git history remained the same
|
|
|
|
new_commit_oid="$(git rev-parse HEAD~1)"
|
|
|
|
if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure a new commit was made
|
|
|
|
new_head_oid="$(git rev-parse HEAD)"
|
|
|
|
if [ "$prev_commit_oid" == "$new_oid" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "migrate import --no-rewrite (no .gitattributes)"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
setup_multiple_local_branches
|
|
|
|
|
|
|
|
# Ensure command fails if no .gitattributes files are present
|
commands: warn if working copy is dirty
In 'git lfs migrate import' and 'git lfs migrate export', Git LFS makes
destructive changes to a caller's repository and therefore invokes 'git
checkout --force', which throws away local changes.
To prevent this, let's introduce a check that notifies users when they
are going to throw away local changes, and allows for the user to abort
if they do not wish to discard their local changes.
With this, a user can safely migrate over dirty repositories (i.e., in
the case that they wanted to fix a file that should have been in Git
LFS, but wasn't) without having to finagle their repository to get it
into a migrate-able state.
For users with lots of pending migrations, also teach --yes, which
allows a user to avoid the check, and instead simply prints the warning
message to STDERR.
2018-07-10 15:18:46 +00:00
|
|
|
git lfs migrate import --no-rewrite --yes *.txt *.md 2>&1 | tee migrate.log
|
2018-05-30 17:56:11 +00:00
|
|
|
if [ ${PIPESTATUS[0]} -eq 0 ]; then
|
|
|
|
echo >&2 "fatal: expected git lfs migrate import --no-rewrite to fail, didn't"
|
2018-05-31 18:19:45 +00:00
|
|
|
exit 1
|
2018-05-30 17:56:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
grep "no Git LFS filters found in .gitattributes" migrate.log
|
2018-05-26 00:11:14 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "migrate import --no-rewrite (nested .gitattributes)"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
setup_local_branch_with_nested_gitattrs
|
|
|
|
|
|
|
|
# Ensure a .md filter does not exist in the top-level .gitattributes
|
2020-06-29 16:18:57 +00:00
|
|
|
main_attrs="$(git cat-file -p "$main:.gitattributes")"
|
|
|
|
[ !"$(echo "$main_attrs" | grep -q ".md")" ]
|
2018-05-26 00:11:14 +00:00
|
|
|
|
|
|
|
# Ensure a .md filter exists in the nested .gitattributes
|
2020-06-29 16:18:57 +00:00
|
|
|
nested_attrs="$(git cat-file -p "$main:b/.gitattributes")"
|
2018-05-26 00:11:14 +00:00
|
|
|
echo "$nested_attrs" | grep -q "*.md filter=lfs diff=lfs merge=lfs"
|
|
|
|
|
|
|
|
md_oid="$(calc_oid "$(git cat-file -p :a.md)")"
|
2018-05-31 18:26:58 +00:00
|
|
|
nested_md_oid="$(calc_oid "$(git cat-file -p :b/a.md)")"
|
2018-05-26 00:11:14 +00:00
|
|
|
txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")"
|
|
|
|
|
commands: warn if working copy is dirty
In 'git lfs migrate import' and 'git lfs migrate export', Git LFS makes
destructive changes to a caller's repository and therefore invokes 'git
checkout --force', which throws away local changes.
To prevent this, let's introduce a check that notifies users when they
are going to throw away local changes, and allows for the user to abort
if they do not wish to discard their local changes.
With this, a user can safely migrate over dirty repositories (i.e., in
the case that they wanted to fix a file that should have been in Git
LFS, but wasn't) without having to finagle their repository to get it
into a migrate-able state.
For users with lots of pending migrations, also teach --yes, which
allows a user to avoid the check, and instead simply prints the warning
message to STDERR.
2018-07-10 15:18:46 +00:00
|
|
|
git lfs migrate import --no-rewrite --yes a.txt b/a.md
|
2018-05-26 00:11:14 +00:00
|
|
|
|
|
|
|
# Ensure a.txt and subtree/a.md were imported, even though *.md only exists in the
|
|
|
|
# nested subtree/.gitattributes file
|
2020-06-29 16:18:57 +00:00
|
|
|
assert_pointer "refs/heads/main" "b/a.md" "$nested_md_oid" "140"
|
|
|
|
assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120"
|
2018-05-26 00:11:14 +00:00
|
|
|
|
|
|
|
assert_local_object "$nested_md_oid" 140
|
|
|
|
assert_local_object "$txt_oid" 120
|
|
|
|
refute_local_object "$md_oid" 140
|
|
|
|
|
|
|
|
# Failure should occur when trying to import a.md as no entry exists in
|
|
|
|
# top-level .gitattributes file
|
commands: warn if working copy is dirty
In 'git lfs migrate import' and 'git lfs migrate export', Git LFS makes
destructive changes to a caller's repository and therefore invokes 'git
checkout --force', which throws away local changes.
To prevent this, let's introduce a check that notifies users when they
are going to throw away local changes, and allows for the user to abort
if they do not wish to discard their local changes.
With this, a user can safely migrate over dirty repositories (i.e., in
the case that they wanted to fix a file that should have been in Git
LFS, but wasn't) without having to finagle their repository to get it
into a migrate-able state.
For users with lots of pending migrations, also teach --yes, which
allows a user to avoid the check, and instead simply prints the warning
message to STDERR.
2018-07-10 15:18:46 +00:00
|
|
|
git lfs migrate import --no-rewrite --yes a.md 2>&1 | tee migrate.log
|
2018-05-30 17:56:11 +00:00
|
|
|
if [ ${PIPESTATUS[0]} -eq 0 ]; then
|
|
|
|
echo >&2 "fatal: expected git lfs migrate import --no-rewrite to fail, didn't"
|
2018-05-31 18:19:45 +00:00
|
|
|
exit 1
|
2018-05-30 17:56:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
grep "a.md did not match any Git LFS filters in .gitattributes" migrate.log
|
2018-05-26 00:11:14 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "migrate import --no-rewrite (with commit message)"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
setup_local_branch_with_gitattrs
|
|
|
|
|
|
|
|
prev_commit_oid="$(git rev-parse HEAD)"
|
|
|
|
expected_commit_msg="run git-lfs migrate import --no-rewrite"
|
|
|
|
|
commands: warn if working copy is dirty
In 'git lfs migrate import' and 'git lfs migrate export', Git LFS makes
destructive changes to a caller's repository and therefore invokes 'git
checkout --force', which throws away local changes.
To prevent this, let's introduce a check that notifies users when they
are going to throw away local changes, and allows for the user to abort
if they do not wish to discard their local changes.
With this, a user can safely migrate over dirty repositories (i.e., in
the case that they wanted to fix a file that should have been in Git
LFS, but wasn't) without having to finagle their repository to get it
into a migrate-able state.
For users with lots of pending migrations, also teach --yes, which
allows a user to avoid the check, and instead simply prints the warning
message to STDERR.
2018-07-10 15:18:46 +00:00
|
|
|
git lfs migrate import --message "$expected_commit_msg" --no-rewrite --yes *.txt
|
2018-05-26 00:11:14 +00:00
|
|
|
|
|
|
|
# Ensure the git history remained the same
|
|
|
|
new_commit_oid="$(git rev-parse HEAD~1)"
|
|
|
|
if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure a new commit was made
|
|
|
|
new_head_oid="$(git rev-parse HEAD)"
|
|
|
|
if [ "$prev_commit_oid" == "$new_oid" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure the provided commit message was used
|
|
|
|
commit_msg="$(git log -1 --pretty=format:%s)"
|
|
|
|
if [ "$commit_msg" != "$expected_commit_msg" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "migrate import --no-rewrite (with empty commit message)"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
setup_local_branch_with_gitattrs
|
|
|
|
|
|
|
|
prev_commit_oid="$(git rev-parse HEAD)"
|
|
|
|
|
commands: warn if working copy is dirty
In 'git lfs migrate import' and 'git lfs migrate export', Git LFS makes
destructive changes to a caller's repository and therefore invokes 'git
checkout --force', which throws away local changes.
To prevent this, let's introduce a check that notifies users when they
are going to throw away local changes, and allows for the user to abort
if they do not wish to discard their local changes.
With this, a user can safely migrate over dirty repositories (i.e., in
the case that they wanted to fix a file that should have been in Git
LFS, but wasn't) without having to finagle their repository to get it
into a migrate-able state.
For users with lots of pending migrations, also teach --yes, which
allows a user to avoid the check, and instead simply prints the warning
message to STDERR.
2018-07-10 15:18:46 +00:00
|
|
|
git lfs migrate import -m "" --no-rewrite --yes *.txt
|
2018-05-26 00:11:14 +00:00
|
|
|
|
|
|
|
# Ensure the git history remained the same
|
|
|
|
new_commit_oid="$(git rev-parse HEAD~1)"
|
|
|
|
if [ "$prev_commit_oid" != "$new_commit_oid" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure a new commit was made
|
|
|
|
new_head_oid="$(git rev-parse HEAD)"
|
|
|
|
if [ "$prev_commit_oid" == "$new_oid" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure the provided commit message was used
|
|
|
|
commit_msg="$(git log -1 --pretty=format:%s)"
|
|
|
|
if [ "$commit_msg" != "" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
)
|
2018-05-31 18:19:45 +00:00
|
|
|
end_test
|