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

Feature: obtain repository from filepath within git repository #71

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

mizlan
Copy link

@mizlan mizlan commented Feb 16, 2021

Adds functionality to obtain a Repository object given a file anywhere within a Git repository. Includes support for addCeilingDirectories and would be used like so (as an example):

Usage without ceiling directories

(find-repo (io/file "/Users/ml/code/clj-jgit/src/clj_jgit/porcelain.clj"))
;; => #object[org.eclipse.jgit.api.Git 0x1ff2d3f "Git[Repository[/Users/ml/code/clj-jgit/.git]]"]

Usage with ceiling directories

(def ceil [(io/file "/Users/ml/code/clj-jgit/src")])
(find-repo (io/file "/Users/ml/code/clj-jgit/src/clj_jgit/porcelain.clj") :ceiling-dirs ceil)
Execution error (FileNotFoundException) at clj-jgit.porcelain/find-repo (form-init17805399835728471910.clj:234).
Could not load a git repository at '/Users/ml/code/clj-jgit/src/clj_jgit/porcelain.clj' with ceiling dirs: [#object[java.io.File 0xe82bcfe "/Users/ml/code/clj-jgit/src"]]

@mizlan
Copy link
Author

mizlan commented Feb 16, 2021

Resolves #70

@edannenberg
Copy link
Member

edannenberg commented Feb 17, 2021

Thanks for the swift PR!

I was thinking to change load-repo directly so it would support your use case, should be non-breaking. The only downside is that we can't change with-repo to support the :ceiling-dirs arg in a non-breaking fashion.

If we go with find-repo I would prefer that it only returns the root path of the git repo, if one is found. Which can than be fed to load-repo, etc.

Maybe other users want to chime in with some feedback. /cc @jaromil

@mizlan
Copy link
Author

mizlan commented Feb 17, 2021

If we go with find-repo I would prefer that it only returns the root path of the git repo, if one is found. Which can than be fed to load-repo, etc.

Ah, this makes much more sense. I will modify the function for now to reflect that. If that's the case, do you think the name of the function should be changed as well?

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.

None yet

2 participants