Skip to content

Commit

Permalink
/t-migrate-{ex,im}port.sh: avoid using mktemp
Browse files Browse the repository at this point in the history
In commit 96775c6 of PR git-lfs#2929 the
"migrate import (--object-map)" test was added to the test suite for
the "git lfs migrate import" command to validate the --object-map option
for that command, which was introduced in the same PR.  This test
makes use of the mktemp(1) shell command to generate a unique temporary
directory, into which the test then writes several files including
the Git LFS migration's object map file.

Likewise, in commit 7632a20 of PR git-lfs#3084,
a similar "migrate export (--object-map)" test was added to the test
suite for the "git lfs migrate export" command, which was introduced
in that PR, and this test also uses the mktemp(1) shell command to
create a unique temporary directory.

However, neither test removes these temporary directories after
completion, so they remain in place indefinitely in whatever system
location is used by the mktemp(1) command.  This is in addition to the
temporary directory created by the mktemp(1) command which is used
throughout all our test suites, whose path we store in the
GIT_LFS_TEST_DIR variable so it can be reused by all test suites after
the first one to run.  (At least, that is the intent of the variable,
but in practice, because we do not export it, and because each test
script runs in its own shell session, each script creates another
temporary directory.  We will address this issue in a subsequent PR.)

In a previous commit in this PR we introduced a new lfstest-genrandom
utility program for our test suite, so we can now make use of it to
replace both instances where our migration tests make an extra call
to the mktemp(1) shell command (beyond the one used to populate the
GIT_LFS_TEST_DIR variable).

In both tests, we now create a unique directory whose path begins
with the path in the GIT_LFS_TEST_DIR variable, followed by a directory
name partially generated by our lfstest-genrandom program.  We pass
the --base64url flag to the program ensure it returns only characters
safe to use in a file or directory name on any OS platform.
  • Loading branch information
chrisd8088 committed Sep 18, 2024
1 parent c4173da commit b17b038
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion t/t-migrate-export.sh
Original file line number Diff line number Diff line change
@@ -455,7 +455,8 @@ begin_test "migrate export (--object-map)"

setup_multiple_local_branches_tracked

output_dir=$(mktemp -d)
output_dir="$GIT_LFS_TEST_DIR/export-object-map-$(lfstest-genrandom --base64url 32)"
mkdir -p "$output_dir"

git log --all --pretty='format:%H' > "${output_dir}/old_sha.txt"
git lfs migrate export --everything --include="*" --object-map "${output_dir}/object-map.txt"
3 changes: 2 additions & 1 deletion t/t-migrate-import.sh
Original file line number Diff line number Diff line change
@@ -935,7 +935,8 @@ begin_test "migrate import (--object-map)"

setup_multiple_local_branches

output_dir=$(mktemp -d)
output_dir="$GIT_LFS_TEST_DIR/import-object-map-$(lfstest-genrandom --base64url 32)"
mkdir -p "$output_dir"

git log --all --pretty='format:%H' > "${output_dir}/old_sha.txt"
git lfs migrate import --everything --object-map "${output_dir}/object-map.txt"

0 comments on commit b17b038

Please sign in to comment.