Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file is outside repository in pre-commit git hook #955

Closed
dkoudela opened this issue Jan 27, 2016 · 5 comments
Closed

file is outside repository in pre-commit git hook #955

dkoudela opened this issue Jan 27, 2016 · 5 comments

Comments

@dkoudela
Copy link

Hi,

I am creating a pre-commit git hook for automatic lfs tracking of particular file types.
I have discovered following error:
JArchitectOut/2016_01/24_00_24/JArchitectAnalysisResult_Advanced_Ldap_for_Crucible_2016Jan24_00h22.jdar is outside repository

If I run the script manually, it works fine.

It looks like related to different lfs env (see below).
Is it possible to run 'git lfs track' in the git hooks?

Thanks,
David.

git hook:

git-lfs/1.1.0 (GitHub; linux amd64; go 1.5.1; git 258acf1)
git version 2.7.0

Endpoint=https://github.com/dkoudela/lfs-test.git/info/lfs (auth=none)
SSH=git@github.com:dkoudela/lfs-test.git
LocalWorkingDir=.
LocalGitDir=.git
LocalGitStorageDir=.git
LocalMediaDir=.git/lfs/objects
TempDir=.git/lfs/tmp
ConcurrentTransfers=3
BatchTransfer=true
GIT_DIR=.git
GIT_AUTHOR_DATE=@1453925380 -0800
GIT_INDEX_FILE=.git/index
GIT_WORK_TREE=.
GIT_AUTHOR_NAME=David Koudela
GIT_PREFIX=
GIT_AUTHOR_EMAIL=...
git config filter.lfs.smudge = "git-lfs smudge %f"
git config filter.lfs.clean = "git-lfs clean %f"

terminal:

git-lfs/1.1.0 (GitHub; linux amd64; go 1.5.1; git 258acf1)
git version 2.7.0

Endpoint=https://github.com/dkoudela/lfs-test.git/info/lfs (auth=none)
SSH=git@github.com:dkoudela/lfs-test.git
LocalWorkingDir=/opt/gitrepos/lfs-test
LocalGitDir=/opt/gitrepos/lfs-test/.git
LocalGitStorageDir=/opt/gitrepos/lfs-test/.git
LocalMediaDir=/opt/gitrepos/lfs-test/.git/lfs/objects
TempDir=/opt/gitrepos/lfs-test/.git/lfs/tmp
ConcurrentTransfers=3
BatchTransfer=true
git config filter.lfs.smudge = "git-lfs smudge %f"
git config filter.lfs.clean = "git-lfs clean %f"

@technoweenie
Copy link
Contributor

Ah, it's clearly not getting the right directory when run as a hook. I'm not positive how git executes the command.

@dkoudela
Copy link
Author

Yeah, that's right.
Is there any workaround for this issue?
Thanks.

@technoweenie
Copy link
Contributor

@dkoudela Ok, I found the problem while looking at an unrelated one. The way Git LFS handles GIT_WORK_TREE is broken.

You can get around this by changing your hook to override GIT_WORK_TREE:

$ GIT_WORK_TREE=".." git lfs whatever

# or try an absolute path
$ GIT_WORK_TREE="/path/to/repo" git lfs whatever

Your hook is running with these two values:

GIT_DIR=.git
GIT_WORK_TREE=.

Due to some confusing git documentation, Git LFS is treating the GIT_WORK_TREE value of . as relative to GIT_DIR. But, your repository working directory can't be the same as the bare repository. Fixed (but waiting for review) in #963

@dkoudela
Copy link
Author

Thanks a lot!

I am going to try the workaround.

@dkoudela
Copy link
Author

dkoudela commented Feb 2, 2016

I can confirm, my pre-commit hook : https://github.com/dkoudela/lfs-tracking-hook/blob/master/pre-commit is working with the workaround.

FYI, during my LFS testing, I found it is easy to miss some files and once they are committed they are never managed by the LFS.
I have created the hook ensuring all files defined by RegExp patterns are tracked and managed by the LFS.

As I got a solution, I am closing the issue.
Thanks a lot!
David.

@dkoudela dkoudela closed this as completed Feb 2, 2016
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

No branches or pull requests

2 participants