Repository navigation
fs: specify a file as existing if it's empty - #4654
Merged
Merged
Conversation
chrisd8088
approved these changes
Sep 27, 2021
chrisd8088
left a comment
Member
There was a problem hiding this comment.
Thanks for fixing this! The new tests definitely fail without these changes, which is excellent. Would there be any value in adding additional tests for the prune and dedup use cases as well?
Comment on lines
+117
to
+118
| if srcFile == os.DevNull { | ||
| return true, nil | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
I suppose this could move up to just below where srcFile is initialized, since we don't need dstFile yet. But it's a minor thing.
If the object has a size of zero, then we already have its object: it's the empty file, and we shouldn't need to download it from anywhere. If we inquire if it exists, then say it does, and say its location is the system's equivalent of /dev/null. The only tricky case is if we're de-duplicating, linking, or writing to a file, in which case we should not try to use a link or replace on the file, since we neither want to link nor replace the system's /dev/null.
Member
Author
|
I've added tests for the prune case; unfortunately, dedup doesn't run on my system, so I can't test it here. To be clear, I believe prune worked before just fine, it's just that with my changes, we don't want to try to delete |
bk2204
added a commit
that referenced
this pull request
Sep 28, 2021
fs: specify a file as existing if it's empty
chrisd8088
added a commit
that referenced
this pull request
Oct 16, 2025
In PR #527 we introduced the "git lfs checkout" and "git lfs pull" commands and added some initial tests of those commands to our test suite, which we have subsequently expanded over time. Before we adjust how these commands check and creates files, we want to further revise and expand their test suites to validate a broader range of conditions. In the initial "checkout" test of the t/t-checkout.sh test script we expand two sets of tests, both those we perform within a subdirectory of the current working tree, and those we perform with various "glob" file pattern arguments. After changing the working directory to a subdirectory of the working tree, at present the test suite only checks the behaviour of the "git lfs checkout" command when passed either a single relative file name and or the "." current directory name. We now add similar checks using first a bare ".." parent directory name and then using a relative path pattern to a sibling subdirectory combined with a trailing "/**" component, following the gitignore(5) rules we support for pattern matching. We also run the "git lfs checkout" command in the root of the working tree and check that it behaves as expected when passed the name of a subdirectory which already exists, and when that subdirectory's name is followed by a trailing "/**" pattern component. When the "git lfs checkout" command internally converts its file path pattern arguments into file path patterns that are relative to the root of the repository, rather being relative to the current working directory, it appends a trailing "/" character if the pattern is actually just the path to a directory (or a symbolic link to a directory). This change is implemented in the Convert() method of the currentToRepoPatternConverter structure in our "lfs" package, and was added in commit 56abb71 of PR #4556 so as to ensure that arguments which resolve to specific directories are properly converted into patterns that match both the directories and all of their contents. Note, though, when we run the "git lfs checkout" command with a "." directory name argument while in a subdirectory of the working tree, the internal addition of a trailing "/" character does not actually affect the success of the command. This is because the Convert() of the currentToRepoPatternConverter structure first creates a path relative to the root of the repository, which necessarily includes the subdirectory's name as its final component. When used as a path pattern according to the gitignore(5) rules, then even without a trailing "/" character the pattern will still match the subdirectory and therefore its contents. On the other hand, the internal additional of a trailing "/" character does affect the success of the "git lfs checkout" command when we run the command in a subdirectory and provide a ".." argument. In this case, the Convert() method first converts the path into one relative to the root of the repository, which is simply the "." directory name, the same as if the user had supplied a "." argument to a "git lfs checkout" command run in the root of the working tree. Although "." is a valid file path, when treated as a pattern according to the gitignore(5) rules, it does not work to match a directory and all of its contents. To allow users to provide simple a "." argument and have it work as expected, the Convert() method first appends the "/" character, and then strips any leading "./" path component. If the result is an empty path, it is replaced with the "**" pattern component so the final pattern matches everything in the root of the repository. Thus our new check in the initial "checkout" test of the t/t-checkout.sh script where we run the "git lfs checkout" command in a subdirectory and pass a ".." argument, we validate the behaviour described above. The check would fail unless the command converted the ".." argument into a "." path relative to the root of the repository, and into into a "./" path, and then into the "**" pattern component. In parallel with our changes to the t/t-checkout.sh test script, we make a number of changes to the initial "pull" test of the t/t-pull.sh test script to ensure that test performs all its checks under a common set of conditions. We will further enlarge this set of conditions in subsequent commits. First, we correct a typo in the refute_server_object() assertion call that was added to the "pull" test in commit 7158e3b of PR #2641. This commit revised the "git lfs pull" and "git lfs checkout" commands so that the paths they passed to the "git update-index" command were relative to the current working directory. To confirm this new behaviour worked as expected, the "pull" test was updated so it creates a third test file named "dir/dir.dat", and some of the checks in the test were then revised to reference this new file. However, the refute_server_object() assertion which is intended to prove that the corresponding Git LFS object does not exist on the test remote server passes an incorrect variable name, so we fix that now. Because the "dir/dir.dat" file and corresponding local Git LFS object file are not comprehensively referenced in all the checks of the "git lfs pull" command, we add the appropriate assertions for it into those checks. (As well, we revise several invocations of the rm(1) command to align with others in the same test and elsewhere.) The same commit 7158e3b also extended the "pull" test to run the "git lfs pull" command with its -I option under several conditions, but without removing the local Git LFS object files and working tree files, or checking that they have been re-created after the "git lfs pull" command is run. As a consequence, these checks effectively only confirm that the command does not fail. To rectify this limitation we delete all the relevant local files before each of these checks, and then verify that they have been restored by the "git lfs pull" command. We also run the "git lfs pull" command with a more restricted set of file path patterns to confirm that files which do not match those patterns are not fetched from the remote server; we then run the command again to fetch those files. Previously our checks did not actually test the file path filtering capability of the command. As well, we use a file path pattern which is relative to the root of the repository, so that when we run the "git lfs pull" command in a subdirectory of the current working tree and pass this pattern, our test now ascertains that patterns specified with the -I option are correctly matched with file paths starting from the root of the repository. (For the moment we do not check that the "git lfs pull" command accepts "glob" pattern components such as "**", but in a subsequent commit we will add patterns of this type to the arguments we pass to the -I option.) Making these changes, however, exposes another concern which would cause the "pull: with missing object" test to fail unless we adjust it as well. This test appears later in the same t/t-pull.sh test script, and depends on the repository clone created by the "pull" test in the local "clone" test directory. (Ideally, our tests should not depend on each other in this way, so that the failure of one test doesn't cause a series of otherwise unrelated tests to also fail. For the moment, though, we defer this issue to a future PR.) The "pull: with missing object" test was introduced in commit 68ac0f5 of PR #2237 and checks that if a Git LFS object is missing both locally and on the remote server, the "git lfs pull" command should report the missing object and return a non-zero exit code, but should retrieve all other requested Git LFS objects. To simulate this condition, the test removes the Git LFS object corresponding to the "a.dat" test file in the local storage directories and from the remote test server, and then runs the "git lfs pull" command. However, the test does not remove the "a.dat" file from the working tree, and as noted above, is dependent on the state of the cloned repository left by the initial "pull" test. These two factors combine to make the test vulnerable to transient failures, particularly now that we have revised the "pull" test such that the final "git lfs pull" commands in that test re-create all the files in the working tree, except that we have also changed the "pull" test to drop the commit which adds an empty file, as we explain below. In commit d97c785 of PR #4654 the "pull" test was revised to commit an empty file which matches the Git LFS file patterns, and then confirm that the "git lfs pull" command handles that case without trying to fetch the object. This check was added before the final checks of the "git lfs pull" command, which occur within a subdirectory of the working tree. As a result, those checks used to run with the empty file as one of the Git LFS objects, and so did the "pull: with missing object" test. In these instances, when "git lfs pull" runs, it finds the empty file matches the defined Git LFS file patterns, and is considered to exist locally by the LFSObjectExists() method of the Configuration structure in our "config" package. Therefore the command passes the object's pointer data to the Run() method of the singleCheckout structure, which invokes the DecodePointerFromFile() function in our "lfs" package. That function returns a successful result because it detects that the pointer refers to a zero-byte object, and so the RunToPath() method of the singleCheckout structure is executed, and then the file's path is passed to the Add() method of the gitIndexer structure. That method starts a "git update-index" command and writes the file's path to the Git command on its standard input file descriptor. We start the "git update-index" command with the --refresh option, so it reviews all of its cached index entries, including the one for the "a.dat" file. If that file in the working tree has the same modification timestamp as the Git index file (at least to within the same second, assuming Git was not compiled with the USE_NSEC macro definition) then Git considers the file to potentially be "racily clean", because it's file size and modification timestamp are insufficient to determine whether the file has changed since the index entry was cached. The "git update-index" command therefore reads the contents of the "a.dat" file in the working tree. Because the file's path matches a Git LFS file pattern, the data is streamed to the "git-lfs-filter-process" command, which regenerates a new object file in the local storage directories under ".git/lfs/objects". Unfortunately, the "pull: with missing object" test starts by removing the local and remote copies of the "a.dat" file's Git LFS object file, and expects that running the "git lfs pull" command will not result in a new local copy being generated, as none can be fetched from the remote test server. But if the "pull" test leaves the "a.dat" file in the working tree with an identical timestamp as the Git index file, and has also committed the "empty.dat" file to the Git history, then as described above, the "git lfs pull" invokes "git update-index" with the --refresh option, which finds the "a.dat" file and re-creates the local Git LFS object file, and so the test will fail. Note that without the presence of an empty file in the commit history, the "git lfs pull" command does not find any local Git LFS object files, and so it calls the Run() method of the singleCheckout structure after fetching the available objects from the remote server. The Run() method then executes the DecodePointerFromFile() function, which returns an error because the file in the working tree is not a raw Git LFS pointer, and so the Run() method skips calling the RunToPath() method and also does not pass the file's path to the "git update-index" command. In fact, the "git update-index" command will not be started at all, as there are no files in the working tree which could be considered to contain raw Git LFS pointer data, like the empty file is. Since the "git update-index" command does not run, the "git-lfs-filter-process" command is also never invoked, and so a local Git LFS object file is never re-created for the "a.dat" file, and the test succeeds. For this reason, we change the "pull" test so that it removes the "empty.dat" file from the Git commit history after performing the appropriate check of the "git lfs pull" command's behaviour with regard to empty files. To further guard against a potential regression of our tests and ensure the "pull: with missing object" test passes, we update that test to remove the "a.dat" file from the working tree as well as removing its Git LFS object files from both local and remote storage. Without the "a.dat" file in the working tree, it now becomes impossible for the local object file to be re-created under any circumstances. Finally, we strengthen our check of the log message output by the "git lfs pull" command so that we require a specific "does not exist" message rather than just the raw OID of the missing Git LFS object.
chrisd8088
added a commit
that referenced
this pull request
Oct 16, 2025
In PR #527 we introduced the "git lfs checkout" and "git lfs pull" commands and added some initial tests of those commands to our test suite, which we have subsequently expanded over time. Before we adjust how these commands check and creates files, we want to further revise and expand their test suites to validate a broader range of conditions. In the initial "checkout" test of the t/t-checkout.sh test script we expand two sets of tests, both those we perform within a subdirectory of the current working tree, and those we perform with various "glob" file pattern arguments. After changing the working directory to a subdirectory of the working tree, at present the test suite only checks the behaviour of the "git lfs checkout" command when passed either a single relative file name and or the "." current directory name. We now add similar checks using first a bare ".." parent directory name and then using a relative path pattern to a sibling subdirectory combined with a trailing "/**" component, following the gitignore(5) rules we support for pattern matching. We also run the "git lfs checkout" command in the root of the working tree and check that it behaves as expected when passed the name of a subdirectory which already exists, and when that subdirectory's name is followed by a trailing "/**" pattern component. When the "git lfs checkout" command internally converts its file path pattern arguments into file path patterns that are relative to the root of the repository, rather being relative to the current working directory, it appends a trailing "/" character if the pattern is actually just the path to a directory (or a symbolic link to a directory). This change is implemented in the Convert() method of the currentToRepoPatternConverter structure in our "lfs" package, and was added in commit 56abb71 of PR #4556 so as to ensure that arguments which resolve to specific directories are properly converted into patterns that match both the directories and all of their contents. Note, though, when we run the "git lfs checkout" command with a "." directory name argument while in a subdirectory of the working tree, the internal addition of a trailing "/" character does not actually affect the success of the command. This is because the Convert() of the currentToRepoPatternConverter structure first creates a path relative to the root of the repository, which necessarily includes the subdirectory's name as its final component. When used as a path pattern according to the gitignore(5) rules, then even without a trailing "/" character the pattern will still match the subdirectory and therefore its contents. On the other hand, the internal additional of a trailing "/" character does affect the success of the "git lfs checkout" command when we run the command in a subdirectory and provide a ".." argument. In this case, the Convert() method first converts the path into one relative to the root of the repository, which is simply the "." directory name, the same as if the user had supplied a "." argument to a "git lfs checkout" command run in the root of the working tree. Although "." is a valid file path, when treated as a pattern according to the gitignore(5) rules, it does not work to match a directory and all of its contents. To allow users to provide simple a "." argument and have it work as expected, the Convert() method first appends the "/" character, and then strips any leading "./" path component. If the result is an empty path, it is replaced with the "**" pattern component so the final pattern matches everything in the root of the repository. Thus our new check in the initial "checkout" test of the t/t-checkout.sh script where we run the "git lfs checkout" command in a subdirectory and pass a ".." argument, we validate the behaviour described above. The check would fail unless the command converted the ".." argument into a "." path relative to the root of the repository, and into into a "./" path, and then into the "**" pattern component. In parallel with our changes to the t/t-checkout.sh test script, we make a number of changes to the initial "pull" test of the t/t-pull.sh test script to ensure that test performs all its checks under a common set of conditions. We will further enlarge this set of conditions in subsequent commits. First, we correct a typo in the refute_server_object() assertion call that was added to the "pull" test in commit 7158e3b of PR #2641. This commit revised the "git lfs pull" and "git lfs checkout" commands so that the paths they passed to the "git update-index" command were relative to the current working directory. To confirm this new behaviour worked as expected, the "pull" test was updated so it creates a third test file named "dir/dir.dat", and some of the checks in the test were then revised to reference this new file. However, the refute_server_object() assertion which is intended to prove that the corresponding Git LFS object does not exist on the test remote server passes an incorrect variable name, so we fix that now. Because the "dir/dir.dat" file and corresponding local Git LFS object file are not comprehensively referenced in all the checks of the "git lfs pull" command, we add the appropriate assertions for it into those checks. (As well, we revise several invocations of the rm(1) command to align with others in the same test and elsewhere.) The same commit 7158e3b also extended the "pull" test to run the "git lfs pull" command with its -I option under several conditions, but without removing the local Git LFS object files and working tree files, or checking that they have been re-created after the "git lfs pull" command is run. As a consequence, these checks effectively only confirm that the command does not fail. To rectify this limitation we delete all the relevant local files before each of these checks, and then verify that they have been restored by the "git lfs pull" command. We also run the "git lfs pull" command with a more restricted set of file path patterns to confirm that files which do not match those patterns are not fetched from the remote server; we then run the command again to fetch those files. Previously our checks did not actually test the file path filtering capability of the command. As well, we use a file path pattern which is relative to the root of the repository, so that when we run the "git lfs pull" command in a subdirectory of the current working tree and pass this pattern, our test now ascertains that patterns specified with the -I option are correctly matched with file paths starting from the root of the repository. (For the moment we do not check that the "git lfs pull" command accepts "glob" pattern components such as "**", but in a subsequent commit we will add patterns of this type to the arguments we pass to the -I option.) Making these changes, however, exposes another concern which would cause the "pull: with missing object" test to fail unless we adjust it as well. This test appears later in the same t/t-pull.sh test script, and depends on the repository clone created by the "pull" test in the local "clone" test directory. (Ideally, our tests should not depend on each other in this way, so that the failure of one test doesn't cause a series of otherwise unrelated tests to also fail. For the moment, though, we defer this issue to a future PR.) The "pull: with missing object" test was introduced in commit 68ac0f5 of PR #2237 and checks that if a Git LFS object is missing both locally and on the remote server, the "git lfs pull" command should report the missing object and return a non-zero exit code, but should retrieve all other requested Git LFS objects. To simulate this condition, the test removes the Git LFS object corresponding to the "a.dat" test file in the local storage directories and from the remote test server, and then runs the "git lfs pull" command. However, the test does not remove the "a.dat" file from the working tree, and as noted above, is dependent on the state of the cloned repository left by the initial "pull" test. These two factors combine to make the test vulnerable to transient failures, particularly now that we have revised the "pull" test such that the final "git lfs pull" commands in that test re-create all the files in the working tree, except that we have also changed the "pull" test to drop the commit which adds an empty file, as we explain below. In commit d97c785 of PR #4654 the "pull" test was revised to commit an empty file which matches the Git LFS file patterns, and then confirm that the "git lfs pull" command handles that case without trying to fetch the object. This check was added before the final checks of the "git lfs pull" command, which occur within a subdirectory of the working tree. As a result, those checks used to run with the empty file as one of the Git LFS objects, and so did the "pull: with missing object" test. In these instances, when "git lfs pull" runs, it finds the empty file matches the defined Git LFS file patterns, and is considered to exist locally by the LFSObjectExists() method of the Configuration structure in our "config" package. Therefore the command passes the object's pointer data to the Run() method of the singleCheckout structure, which invokes the DecodePointerFromFile() function in our "lfs" package. That function returns a successful result because it detects that the pointer refers to a zero-byte object, and so the RunToPath() method of the singleCheckout structure is executed, and then the file's path is passed to the Add() method of the gitIndexer structure. That method starts a "git update-index" command and writes the file's path to the Git command on its standard input file descriptor. We start the "git update-index" command with the --refresh option, so it reviews all of its cached index entries, including the one for the "a.dat" file. If that file in the working tree has the same modification timestamp as the Git index file (at least to within the same second, assuming Git was not compiled with the USE_NSEC macro definition) then Git considers the file to potentially be "racily clean", because it's file size and modification timestamp are insufficient to determine whether the file has changed since the index entry was cached. The "git update-index" command therefore reads the contents of the "a.dat" file in the working tree. Because the file's path matches a Git LFS file pattern, the data is streamed to the "git-lfs-filter-process" command, which regenerates a new object file in the local storage directories under ".git/lfs/objects". Unfortunately, the "pull: with missing object" test starts by removing the local and remote copies of the "a.dat" file's Git LFS object file, and expects that running the "git lfs pull" command will not result in a new local copy being generated, as none can be fetched from the remote test server. But if the "pull" test leaves the "a.dat" file in the working tree with an identical timestamp as the Git index file, and has also committed the "empty.dat" file to the Git history, then as described above, the "git lfs pull" invokes "git update-index" with the --refresh option, which finds the "a.dat" file and re-creates the local Git LFS object file, and so the test will fail. Note that without the presence of an empty file in the commit history, the "git lfs pull" command does not find any local Git LFS object files, and so it calls the Run() method of the singleCheckout structure after fetching the available objects from the remote server. The Run() method then executes the DecodePointerFromFile() function, which returns an error because the file in the working tree is not a raw Git LFS pointer, and so the Run() method skips calling the RunToPath() method and also does not pass the file's path to the "git update-index" command. In fact, the "git update-index" command will not be started at all, as there are no files in the working tree which could be considered to contain raw Git LFS pointer data, like the empty file is. Since the "git update-index" command does not run, the "git-lfs-filter-process" command is also never invoked, and so a local Git LFS object file is never re-created for the "a.dat" file, and the test succeeds. For this reason, we change the "pull" test so that it removes the "empty.dat" file from the Git commit history after performing the appropriate check of the "git lfs pull" command's behaviour with regard to empty files. To further guard against a potential regression of our tests and ensure the "pull: with missing object" test passes, we update that test to remove the "a.dat" file from the working tree as well as removing its Git LFS object files from both local and remote storage. Without the "a.dat" file in the working tree, it now becomes impossible for the local object file to be re-created under any circumstances. Finally, we strengthen our check of the log message output by the "git lfs pull" command so that we require a specific "does not exist" message rather than just the raw OID of the missing Git LFS object.
hswong3i
pushed a commit
to alvistack/git-lfs-git-lfs
that referenced
this pull request
Oct 18, 2025
In PR git-lfs#527 we introduced the "git lfs checkout" and "git lfs pull" commands and added some initial tests of those commands to our test suite, which we have subsequently expanded over time. Before we adjust how these commands check and creates files, we want to further revise and expand their test suites to validate a broader range of conditions. In the initial "checkout" test of the t/t-checkout.sh test script we expand two sets of tests, both those we perform within a subdirectory of the current working tree, and those we perform with various "glob" file pattern arguments. After changing the working directory to a subdirectory of the working tree, at present the test suite only checks the behaviour of the "git lfs checkout" command when passed either a single relative file name and or the "." current directory name. We now add similar checks using first a bare ".." parent directory name and then using a relative path pattern to a sibling subdirectory combined with a trailing "/**" component, following the gitignore(5) rules we support for pattern matching. We also run the "git lfs checkout" command in the root of the working tree and check that it behaves as expected when passed the name of a subdirectory which already exists, and when that subdirectory's name is followed by a trailing "/**" pattern component. When the "git lfs checkout" command internally converts its file path pattern arguments into file path patterns that are relative to the root of the repository, rather being relative to the current working directory, it appends a trailing "/" character if the pattern is actually just the path to a directory (or a symbolic link to a directory). This change is implemented in the Convert() method of the currentToRepoPatternConverter structure in our "lfs" package, and was added in commit 56abb71 of PR git-lfs#4556 so as to ensure that arguments which resolve to specific directories are properly converted into patterns that match both the directories and all of their contents. Note, though, when we run the "git lfs checkout" command with a "." directory name argument while in a subdirectory of the working tree, the internal addition of a trailing "/" character does not actually affect the success of the command. This is because the Convert() of the currentToRepoPatternConverter structure first creates a path relative to the root of the repository, which necessarily includes the subdirectory's name as its final component. When used as a path pattern according to the gitignore(5) rules, then even without a trailing "/" character the pattern will still match the subdirectory and therefore its contents. On the other hand, the internal additional of a trailing "/" character does affect the success of the "git lfs checkout" command when we run the command in a subdirectory and provide a ".." argument. In this case, the Convert() method first converts the path into one relative to the root of the repository, which is simply the "." directory name, the same as if the user had supplied a "." argument to a "git lfs checkout" command run in the root of the working tree. Although "." is a valid file path, when treated as a pattern according to the gitignore(5) rules, it does not work to match a directory and all of its contents. To allow users to provide simple a "." argument and have it work as expected, the Convert() method first appends the "/" character, and then strips any leading "./" path component. If the result is an empty path, it is replaced with the "**" pattern component so the final pattern matches everything in the root of the repository. Thus our new check in the initial "checkout" test of the t/t-checkout.sh script where we run the "git lfs checkout" command in a subdirectory and pass a ".." argument, we validate the behaviour described above. The check would fail unless the command converted the ".." argument into a "." path relative to the root of the repository, and into into a "./" path, and then into the "**" pattern component. In parallel with our changes to the t/t-checkout.sh test script, we make a number of changes to the initial "pull" test of the t/t-pull.sh test script to ensure that test performs all its checks under a common set of conditions. We will further enlarge this set of conditions in subsequent commits. First, we correct a typo in the refute_server_object() assertion call that was added to the "pull" test in commit 7158e3b of PR git-lfs#2641. This commit revised the "git lfs pull" and "git lfs checkout" commands so that the paths they passed to the "git update-index" command were relative to the current working directory. To confirm this new behaviour worked as expected, the "pull" test was updated so it creates a third test file named "dir/dir.dat", and some of the checks in the test were then revised to reference this new file. However, the refute_server_object() assertion which is intended to prove that the corresponding Git LFS object does not exist on the test remote server passes an incorrect variable name, so we fix that now. Because the "dir/dir.dat" file and corresponding local Git LFS object file are not comprehensively referenced in all the checks of the "git lfs pull" command, we add the appropriate assertions for it into those checks. (As well, we revise several invocations of the rm(1) command to align with others in the same test and elsewhere.) The same commit 7158e3b also extended the "pull" test to run the "git lfs pull" command with its -I option under several conditions, but without removing the local Git LFS object files and working tree files, or checking that they have been re-created after the "git lfs pull" command is run. As a consequence, these checks effectively only confirm that the command does not fail. To rectify this limitation we delete all the relevant local files before each of these checks, and then verify that they have been restored by the "git lfs pull" command. We also run the "git lfs pull" command with a more restricted set of file path patterns to confirm that files which do not match those patterns are not fetched from the remote server; we then run the command again to fetch those files. Previously our checks did not actually test the file path filtering capability of the command. As well, we use a file path pattern which is relative to the root of the repository, so that when we run the "git lfs pull" command in a subdirectory of the current working tree and pass this pattern, our test now ascertains that patterns specified with the -I option are correctly matched with file paths starting from the root of the repository. (For the moment we do not check that the "git lfs pull" command accepts "glob" pattern components such as "**", but in a subsequent commit we will add patterns of this type to the arguments we pass to the -I option.) Making these changes, however, exposes another concern which would cause the "pull: with missing object" test to fail unless we adjust it as well. This test appears later in the same t/t-pull.sh test script, and depends on the repository clone created by the "pull" test in the local "clone" test directory. (Ideally, our tests should not depend on each other in this way, so that the failure of one test doesn't cause a series of otherwise unrelated tests to also fail. For the moment, though, we defer this issue to a future PR.) The "pull: with missing object" test was introduced in commit 68ac0f5 of PR git-lfs#2237 and checks that if a Git LFS object is missing both locally and on the remote server, the "git lfs pull" command should report the missing object and return a non-zero exit code, but should retrieve all other requested Git LFS objects. To simulate this condition, the test removes the Git LFS object corresponding to the "a.dat" test file in the local storage directories and from the remote test server, and then runs the "git lfs pull" command. However, the test does not remove the "a.dat" file from the working tree, and as noted above, is dependent on the state of the cloned repository left by the initial "pull" test. These two factors combine to make the test vulnerable to transient failures, particularly now that we have revised the "pull" test such that the final "git lfs pull" commands in that test re-create all the files in the working tree, except that we have also changed the "pull" test to drop the commit which adds an empty file, as we explain below. In commit d97c785 of PR git-lfs#4654 the "pull" test was revised to commit an empty file which matches the Git LFS file patterns, and then confirm that the "git lfs pull" command handles that case without trying to fetch the object. This check was added before the final checks of the "git lfs pull" command, which occur within a subdirectory of the working tree. As a result, those checks used to run with the empty file as one of the Git LFS objects, and so did the "pull: with missing object" test. In these instances, when "git lfs pull" runs, it finds the empty file matches the defined Git LFS file patterns, and is considered to exist locally by the LFSObjectExists() method of the Configuration structure in our "config" package. Therefore the command passes the object's pointer data to the Run() method of the singleCheckout structure, which invokes the DecodePointerFromFile() function in our "lfs" package. That function returns a successful result because it detects that the pointer refers to a zero-byte object, and so the RunToPath() method of the singleCheckout structure is executed, and then the file's path is passed to the Add() method of the gitIndexer structure. That method starts a "git update-index" command and writes the file's path to the Git command on its standard input file descriptor. We start the "git update-index" command with the --refresh option, so it reviews all of its cached index entries, including the one for the "a.dat" file. If that file in the working tree has the same modification timestamp as the Git index file (at least to within the same second, assuming Git was not compiled with the USE_NSEC macro definition) then Git considers the file to potentially be "racily clean", because it's file size and modification timestamp are insufficient to determine whether the file has changed since the index entry was cached. The "git update-index" command therefore reads the contents of the "a.dat" file in the working tree. Because the file's path matches a Git LFS file pattern, the data is streamed to the "git-lfs-filter-process" command, which regenerates a new object file in the local storage directories under ".git/lfs/objects". Unfortunately, the "pull: with missing object" test starts by removing the local and remote copies of the "a.dat" file's Git LFS object file, and expects that running the "git lfs pull" command will not result in a new local copy being generated, as none can be fetched from the remote test server. But if the "pull" test leaves the "a.dat" file in the working tree with an identical timestamp as the Git index file, and has also committed the "empty.dat" file to the Git history, then as described above, the "git lfs pull" invokes "git update-index" with the --refresh option, which finds the "a.dat" file and re-creates the local Git LFS object file, and so the test will fail. Note that without the presence of an empty file in the commit history, the "git lfs pull" command does not find any local Git LFS object files, and so it calls the Run() method of the singleCheckout structure after fetching the available objects from the remote server. The Run() method then executes the DecodePointerFromFile() function, which returns an error because the file in the working tree is not a raw Git LFS pointer, and so the Run() method skips calling the RunToPath() method and also does not pass the file's path to the "git update-index" command. In fact, the "git update-index" command will not be started at all, as there are no files in the working tree which could be considered to contain raw Git LFS pointer data, like the empty file is. Since the "git update-index" command does not run, the "git-lfs-filter-process" command is also never invoked, and so a local Git LFS object file is never re-created for the "a.dat" file, and the test succeeds. For this reason, we change the "pull" test so that it removes the "empty.dat" file from the Git commit history after performing the appropriate check of the "git lfs pull" command's behaviour with regard to empty files. To further guard against a potential regression of our tests and ensure the "pull: with missing object" test passes, we update that test to remove the "a.dat" file from the working tree as well as removing its Git LFS object files from both local and remote storage. Without the "a.dat" file in the working tree, it now becomes impossible for the local object file to be re-created under any circumstances. Finally, we strengthen our check of the log message output by the "git lfs pull" command so that we require a specific "does not exist" message rather than just the raw OID of the missing Git LFS object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If the object has a size of zero, then we already have its object: it's the empty file, and we shouldn't need to download it from anywhere. If we inquire if it exists, then say it does, and say its location is the system's equivalent of
/dev/null.The only tricky case is if we're de-duplicating, linking, or writing to a file, in which case we should not try to use a link or replace on the file, since we neither want to link nor replace the system's
/dev/null.Fixes #4645