Skip to content

Conversation

@detouched
Copy link
Contributor

Git LFS installs pre-push hook which:

  • checks that git-lfs utility is on PATH, and if no, warns that Git LFS hook should probably be removed
  • calls it by executing git lfs pre-push <remote_name> <remote_url>

The introduced hook is a Ruby port of the same algorithm
modulo hook disabling note in the warning message.

For the reference, here's the original hook script:

#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\n"; exit 2; }
git lfs pre-push "$@"

Git LFS installs pre-push hook which:
- checks that git-lfs utility is on PATH, and if no, warns that
Git LFS hook should probably be removed
- calls it by executing `git lfs pre-push <remote_name> <remote_url>`

The introduced hook is a Ruby port of the same algorithm
modulo hook disabling note in the warning message.
result = execute(['git', 'lfs', 'pre-push', remote_name, remote_url])
return :fail, result.stderr unless result.success?

:pass
Copy link
Contributor Author

@detouched detouched Mar 23, 2017

Choose a reason for hiding this comment

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

Not sure: is it possible to output some information in case the hook passes?

In fact, ideally it'd be cool to be able to output something while the hook works cause uploading LFS files might take a while. The original LFS hook reports status interactively, something like:

$ git push
Git LFS: (0 of 1 files) 3.80 MB / 6.85 MB

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know of a good way. Would it make sense to instead of actually uploading just check if there is something to upload? The overcommit hook would then output something like

Checking for files that need to be uploaded..........................[GitLFS] FAILED
./some-file.large hasn't been uploaded. Run `git lfs pre-push ... something` to upload. 

I'm not a lfs user myself, so this idea might not be possible at all. Or it might just be annoying to have to run the upload manually.

Copy link
Owner

Choose a reason for hiding this comment

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

This would require some refactoring of the display logic for Overcommit. In the past we've kicked around the idea of supporting progress bars or similar, but this would require a much more complicated display controller that utilized more advanced cursor features so you could update multiple lines at the same time (since hooks run in parallel).

Copy link
Owner

Choose a reason for hiding this comment

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

Definitely open to the idea, but I think it's well outside the scope of what you're trying to accomplish with this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it make sense to instead of actually uploading just check if there is something to upload?

Not really, you'd just want it to be uploaded just with git push, without additionally calling git lfs .... Also, I'd not make overcommit behaviour different from standard (meaning what is installed by LFS client by default).

It's well outside the scope of what you're trying to accomplish with this change.

I totally agree, I was wondering if there's a way to do that, but if not, it's fine. It might be just mentioned in the doc since GitLfs hook is disabled by default and requires the user to add it in the config yaml.

@detouched
Copy link
Contributor Author

Hey @sds, how do I trigger AppVeyor build again? Looks like its failure is unrelated.

Also I'd love to get your feedback and get this merged eventually.

Thanks!

# @see https://git-lfs.github.com/
class GitLfs < Base
def run
result = execute(['command', '-v', 'git-lfs'])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it always safe to assume that a non-zero exit code means git-lfs wasn't installed? We could run a which git-lfs first for better precision.

Copy link
Owner

Choose a reason for hiding this comment

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

We have a helper for just this purpose: in_path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I simply followed what the original hook does, for consistency (original hook is installed by Git LFS client). I mentioned that before, here's its entire content:

#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\n"; exit 2; }
git lfs pre-push "$@"

But yeah, in_path looks like a safe replacement, will update.

result = execute(['git', 'lfs', 'pre-push', remote_name, remote_url])
return :fail, result.stderr unless result.success?

:pass
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know of a good way. Would it make sense to instead of actually uploading just check if there is something to upload? The overcommit hook would then output something like

Checking for files that need to be uploaded..........................[GitLFS] FAILED
./some-file.large hasn't been uploaded. Run `git lfs pre-push ... something` to upload. 

I'm not a lfs user myself, so this idea might not be possible at all. Or it might just be annoying to have to run the upload manually.

@sds
Copy link
Owner

sds commented Mar 27, 2017

Overall looks good, @detouched. Let's switch to using in_path? and we can ignore the Appveyor build, which is notoriously flakey.

- Use `in_path` to check LFS binary presence on PATH
- Fix newline in the warning message when LFS binary is not on PATH
@detouched detouched force-pushed the detouched/git-lfs-pre-push-hook branch from 22b8ef5 to ba71f99 Compare March 31, 2017 14:42
@detouched
Copy link
Contributor Author

As discussed, changed the way LFS binary is looked up to in_path tool.

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