Skip to content

Config include exclude - #1257

Merged
technoweenie merged 8 commits into
git-lfs:masterfrom
ttaylorr:config-include-exclude
Jun 1, 2016
Merged

technoweenie merged 8 commits into
git-lfs:masterfrom
ttaylorr:config-include-exclude

Conversation

@ttaylorr

@ttaylorr ttaylorr commented May 27, 2016 •

Copy link
Copy Markdown
Contributor

@dipnlik reported #1251 the other day that the include/exclude filters made a distinction between ./foo/bar/ (with the trailing slash) and ./foo/bar (without).

This pull-request introduces a patch that essentially runs filepath.Clean() against the paths before processing them. In addition, it removes the command.determineIncludeExcludeFilters function, and instead introduces a set of more granular replacement functions in the config.Configuration type. Those functions are all documented within the changeset.

@ttaylorr

Copy link
Copy Markdown
Contributor Author

As a side note, the config.Configuration type is quickly becoming a dumping ground for miscellaneous methods. I will try and spend this weekend thinking about alternative designs or patterns to refactor against, but am definitely more than open to suggestions on this as well.

For now, I think this is fine, as I assume it will be a pretty drawn-out process to preform this refactor, since so many parts of LFS depend on this type.

/cc @sinbad

Comment thread commands/commands.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think this function was better where it was; it's specifically about converting string arguments to slices or defaulting and so belongs firmly unexported in command in my view. I don't see any benefit in promoting it to an exported function in Configuration, doing so widens that scope outside its remit IMO (which I think you were feeling too based on your follow up comment).

@sinbad

sinbad commented May 31, 2016

Copy link
Copy Markdown
Contributor

👍 except for packaging comments

@sinbad

sinbad commented May 31, 2016

Copy link
Copy Markdown
Contributor

Oh, should have a test too.

@ttaylorr
ttaylorr force-pushed the config-include-exclude branch 5 times, most recently from f48ab26 to 190789f Compare May 31, 2016 16:38
@ttaylorr

Copy link
Copy Markdown
Contributor Author

@sinbad great points. I was definitely feeling the weight of *config.Configuration. I refactored according to your comments, and added tests as appropriate. Let me know your thoughts!

@ttaylorr
ttaylorr force-pushed the config-include-exclude branch from 0052443 to 190789f Compare May 31, 2016 21:53
@ttaylorr
ttaylorr force-pushed the config-include-exclude branch from 190789f to 02236d2 Compare June 1, 2016 00:36
@ttaylorr

ttaylorr commented Jun 1, 2016

Copy link
Copy Markdown
Contributor Author

Looks like the prune tests are still flaky. Will investigate tomorrow. :/

@sinbad

sinbad commented Jun 1, 2016

Copy link
Copy Markdown
Contributor

Sorry, I should have been more specific: there's a test for the --include options in test-fetch.sh, you could just add a dir there and prove that using --include="dir/" works after your changes.

Comment thread config/config.go
//
// NOTE: this method should only be called during testing.
func NewFromValues(gitconfig map[string]string) *Configuration {
config := &Configuration{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could actually put this in config_test.go to enforce the 'only testing' requirement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally this func was in the config_test.go file, but I needed to use it in the commands_test.go. This is sort of smelly to me, but I'm not quite sure what to do about it.

@sinbad

sinbad commented Jun 1, 2016

Copy link
Copy Markdown
Contributor

Looks good to me, the prune failure is puzzling (auth error), I re-ran the test to be sure it wasn't just an intermittent thing but it happened again.

@ttaylorr

ttaylorr commented Jun 1, 2016

Copy link
Copy Markdown
Contributor Author

@sinbad yeah, not sure what's up with the prune failure, either. @technoweenie and I re-ran the tests in #1267 and the failures were intermittent, so you may have just gotten unlucky.

Thoughts on moving OS X git-latest-go-1.5 test to the "allowed failures" section?

@technoweenie
technoweenie merged commit 5bed973 into git-lfs:master Jun 1, 2016
@ttaylorr
ttaylorr deleted the config-include-exclude branch June 1, 2016 21:02
ttaylorr pushed a commit that referenced this pull request Jun 2, 2016
ttaylorr added a commit that referenced this pull request Jun 2, 2016
Backport #1257 for v1.2.x: Config include exclude
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Nov 14, 2025
In commit b7e4910 of our "main"
development branch and commit 779d7a3
of our "release-3.7" branch, when we expanded our tests of the
"git lfs checkout" and "git lfs pull" commands, we also corrected a
typo in the initial "pull" test in our t/t-pull.sh test script.

Specifically, we fixed a call to our refute_server_object() assertion
where ever since commit 7158e3b of
PR git-lfs#2641 we had accidentally passed the name of a nonexistent variable
as the second parameter.  As a result, an empty string was passed
for the Git LFS object ID the assertion was supposed to verify did
not exist in the test server's storage.  Since the server then
responded with an error, the assertion concluded the object did not
exist on the server, and incorrectly allowed the test to continue
and ultimately pass.

We have two other similar assertion functions, the refute_local_object()
and refute_remote_object() functions, both of which also incorrectly
succeed when passed empty or invalid Git LFS object IDs.  Both functions
simply check that no file exists at a location whose path is derived
from the given object ID, which is virtually always going to be the
case when an invalid ID is provided as a parameter.

To ensure that all three assertions allow only valid object IDs, we
introduce an is_valid_oid() function which checks that its single
"oid" parameter matches the format of all the SHA-256 hashes generated
by the Git LFS client, i.e., a 64-character string consisting of only
lowercase ASCII letters and the digits zero through nine.

We then call the new is_valid_oid() function in each of our three
refute_*_object() assertions and pass their "oid" parameters before
they proceed to using those parameters in their normal checks.  With
this change, we should prevent any future regressions in our shell
test suite where we accidentally pass empty or invalid object IDs
to these assertions.

Note that we do not need to call the is_valid_oid() function in our
various "positive" assertion functions like the assert_local_object()
or assert_server_object() functions because they can only succeed
when the given Git LFS object ID actually corresponds to an object
file in the appropriate storage location.

We also adjust two of our test helper functions so that they also
verify their object ID parameters, even though these functions are
not assertions per se.

In the corrupt_local_object() helper function, which overwrites an
object file in the local storage directories, we add a check that
the file actually exists before we alter its contents.  This is
sufficient to ensure that the function will fail if it is passed an
empty or invalid "oid" parameter, so we do not need to call our
new is_valid_oid() function.

Likewise, we do not need to call the is_valid_oid() function in our
delete_local_object() helper function because it already will fail if
the object file it intends to remove does not exist.  This is the case
because we invoke the rm(1) command on the file but do not pass the -f
option.  We therefore add a comment to note that if we ever change the
function passes the -f option to the rm(1) command, we should then also
add a preliminary check that the object file exists.

Unlike the delete_local_object() helper function, however, at present
the delete_server_object() function will succeed even if it is passed
an empty or invalid "oid" parameter.  The function makes a "DELETE"
HTTP request to the test server, whose lfsDeleteHandler() function
always returns a 200 status code even if the object ID extracted from
the request URL does not correspond to an entry in the in-memory set
of object data retained by the server.  Hence we add a call to our
new is_valid_oid() function in the delete_local_object() function to
guard against a caller passing an empty or invalid "oid" parameter.

Finally, we correct one invocation of the refute_server_object()
assertion where we currently only pass an object ID parameter without
a preceding repository name parameter, because otherwise the "init fetch
unclean paths" test in the t/t-fetch-paths.sh test script will now fail.
This oversight was first introduced when the predecessor version of
the test, the "fetch include/exclude with unclean paths" test, was
originally added to the former test/test-fetch.sh script in commit
9e0a30a of PR git-lfs#1257.

Co-authored-by: Lars Schneider <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants