Skip to content

Prevent to track file outside git repository - #294

Closed
aorjoa wants to merge 5 commits into
git-lfs:masterfrom
aorjoa:master
Closed

aorjoa wants to merge 5 commits into
git-lfs:masterfrom
aorjoa:master

Conversation

@aorjoa

@aorjoa aorjoa commented May 10, 2015

Copy link
Copy Markdown
Contributor

according #293 my report issue, now i already hack code for fixed.
if anybody run $ git lfs track outside git repository it's show message "Git LFS cannot perform outside git repository."

@rubyist

rubyist commented May 11, 2015

Copy link
Copy Markdown
Contributor

Thanks for the PR! One piece of feedback I have is, we have some existing code that determines the local git directory and sets lfs.LocalGitDir on init. We should be able to just check whether or not that it set and avoid execing a git command here. 👍 for the test, that looks legit.

/cc #200

@aorjoa

aorjoa commented May 11, 2015

Copy link
Copy Markdown
Contributor Author

👍

@aorjoa

aorjoa commented May 15, 2015

Copy link
Copy Markdown
Contributor Author

I was change code for check lfs.LocalGitDir == ""

@michael-k

Copy link
Copy Markdown
Contributor

I think it's better to inline the function workingInsideGit() like this:

if lfs.LocalGitDir == "" {
    Print("Git LFS cannot perform outside git repository.")
    return
}

Small helper functions are considered good style in go, but in this case it's just a bunch of negations (equal → false → negation) which makes it harder to understand what happens on a low level (maintainability).

The message in Print() makes it clear what happens on a high level (readability), so imho the “speaking name” workingInsideGit adds no further benefit.

And last, but not least, I'm voting in favor of squashing the commits together. :)

@aorjoa

aorjoa commented May 17, 2015

Copy link
Copy Markdown
Contributor Author

Thank you very much for your advice. 👍 I would like to change the message to "Not in a Git LFS repository". Do you think it's clear enough? @michael-k :)

@michael-k

Copy link
Copy Markdown
Contributor

git itself says:

fatal: Not a git repository (or any parent up to mount point /home)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

or with GIT_DISCOVERY_ACROSS_FILESYSTEM=1:

fatal: Not a git repository (or any of the parent directories): .git

Not in a Git LFS repository might not be correct, as lfs.LocalGitDir does not check if git-lfs was initialized.

This was referenced May 21, 2015
@technoweenie

Copy link
Copy Markdown
Contributor

I redid this PR as #323. Normally I wouldn't do something like that, but I wanted to test this on the new test suite. The actual command change is pretty minimal. My PR takes @michael-k's suggestion into account. It also doesn't change the import formatting in commands/command_track.go.

@technoweenie technoweenie mentioned this pull request Jun 11, 2015
38 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants