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

openRepo from a sub directory #64

Closed
facewindu opened this issue May 27, 2015 · 10 comments
Closed

openRepo from a sub directory #64

facewindu opened this issue May 27, 2015 · 10 comments
Milestone

Comments

@facewindu
Copy link

I have the following git repo structure

GIT_REPO
|----- .git dir
|----- sub-repo (eclipse proj)

If I perform Grgit.open('.') from within the sub-repo, I get an exception saying that the GIT repo cannot be found.

Shouldn't Grgit behave like JGit (and regular C git) on this subject, and walk through the parent directory to detect the Git repository ?

@ajoberstar
Copy link
Owner

At least initially, I think I have the same response to both of your questions. Let me know if you have further thoughts.

It seems unlikely that it doesn't behave like JGit, since OpenOp directly calls JGit's Git.open. Maybe there's some flavor of it that I missed, but I would expect it's a difference between JGit and regular Git.

@facewindu
Copy link
Author

I did not find a 'OpenCommand' class on the Jgit sources.
It's true that JGit's Git class offers a 'open' command, but it needs
<<

  • @param dir
    •        the repository to open. May be either the GIT_DIR, or the
      
    •        working tree directory that contains {@code .git}.
      

JGit offers better solution to open a Git repository, see https://wiki.eclipse.org/JGit/User_Guide#Porcelain_API
<<
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File("/my/git/directory"))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();

With a repository instance, you can call Git.wrap(repo) to get a Git repo.

I think using this would offer better ways to find and open a git repo, than the sole 'open' command.

Since Egit guys advocates the hierarchy I presented above for the git repositories (i.e. avoid .git inside the eclipse project, for 'refresh'/'Build workspace' performances), it would be nice to get access to the git repo from anywhere inside the directory tree.

@ajoberstar
Copy link
Owner

I wasn't aware of those RepositoryBuilder classes. Looks like that will be a good solution. I'll take a look at that.

@ajoberstar ajoberstar added this to the 1.3.0 milestone May 28, 2015
@facewindu
Copy link
Author

cool, thanks

@ajoberstar
Copy link
Owner

Can you try 1.3.0-milestone.1 to see if that resolves your issue? (call Grgit.open() instead of Grgit.open(dir: 'something')).

@facewindu
Copy link
Author

Hi, thanks for the quick implementation. I'll try milestone 2 on Monday and keep you posted on 63, 64 and 65

@facewindu
Copy link
Author

Works like a charm, thanks Andrew :)

@ajoberstar
Copy link
Owner

Awesome!

@facewindu
Copy link
Author

I sometimes get
...
org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method open() to invoke from this list:
public static org.ajoberstar.grgit.Grgit org.ajoberstar.grgit.Grgit#open(java.io.File)
public static org.ajoberstar.grgit.Grgit org.ajoberstar.grgit.Grgit#open(java.lang.String)
public static org.ajoberstar.grgit.Grgit org.ajoberstar.grgit.Grgit#open(java.io.File, org.ajoberstar.grgit.Credentials)
public static org.ajoberstar.grgit.Grgit org.ajoberstar.grgit.Grgit#open(java.lang.String, org.ajoberstar.grgit.Credentials)

even if I call Grgit.open() in my gradle plugin.
Any idea why ?

@facewindu
Copy link
Author

Nevermind. It was a conflict between two gradle plug-ins, and one was retrieving the old grgit version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants