Skip to content

Please support discovering repositories using the standard git environment variables #123

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

Merged
merged 2 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,8 @@ git_enum! {
GIT_REPOSITORY_OPEN_NO_SEARCH = (1 << 0),
GIT_REPOSITORY_OPEN_CROSS_FS = (1 << 1),
GIT_REPOSITORY_OPEN_BARE = (1 << 2),
GIT_REPOSITORY_OPEN_NO_DOTGIT = (1 << 3),
GIT_REPOSITORY_OPEN_FROM_ENV = (1 << 4),
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ bitflags! {
const REPOSITORY_OPEN_CROSS_FS = raw::GIT_REPOSITORY_OPEN_CROSS_FS as u32,
/// Force opening as bare repository, and defer loading its config.
const REPOSITORY_OPEN_BARE = raw::GIT_REPOSITORY_OPEN_BARE as u32,
/// Don't try appending `/.git` to the specified repository path.
const REPOSITORY_OPEN_NO_DOTGIT = raw::GIT_REPOSITORY_OPEN_NO_DOTGIT as u32,
/// Respect environment variables like `$GIT_DIR`.
const REPOSITORY_OPEN_FROM_ENV = raw::GIT_REPOSITORY_OPEN_FROM_ENV as u32,
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ impl Repository {
}
}

/// Find and open an existing repository, respecting git environment
/// variables. This acts like `open_ext` with the
/// `REPOSITORY_OPEN_FROM_ENV` flag, but additionally respects `$GIT_DIR`.
/// With `$GIT_DIR` unset, this will search for a repository starting in
/// the current directory.
Copy link
Member

Choose a reason for hiding this comment

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

Could this elaborate a bit on what "respecting git environment variables" means in the documentation as well? It's not entirely obvious to me at first glance.

Copy link
Member Author

@joshtriplett joshtriplett Jul 2, 2016

Choose a reason for hiding this comment

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

Sure, I can elaborate a bit. I'd rather not duplicate the entire libgit2 documentation for this, though.

(Not least of which because git2-rs uses a different license than libgit2, so I can't just copy/paste from libgit2. Though I suppose I could in this case, since I wrote the documentation in question. :) But in the general case, that doesn't work.)

Copy link
Member

Choose a reason for hiding this comment

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

Note that quite a few docs are copy/pasted from libgit2 (I think it's good to be exhaustive here as not everyone will jump to libgit2 docs), but if there's license shenanigans that should likely be mentioned in the README or something like that.

pub fn open_from_env() -> Result<Repository, Error> {
init();
let mut ret = 0 as *mut raw::git_repository;
unsafe {
try_call!(raw::git_repository_open_ext(&mut ret,
0 as *const _,
raw::GIT_REPOSITORY_OPEN_FROM_ENV,
0 as *const _));
Ok(Binding::from_raw(ret))
}
}

/// Find and open an existing repository, with additional options.
///
/// If flags contains REPOSITORY_OPEN_NO_SEARCH, the path must point
Expand All @@ -75,6 +92,14 @@ impl Repository {
/// bare even if it isn't, ignoring any working directory, and defer
/// loading the repository configuration for performance.
///
/// If flags contains REPOSITORY_OPEN_NO_DOTGIT, don't try appending
/// `/.git` to `path`.
///
/// If flags contains REPOSITORY_OPEN_FROM_ENV, `open_ext` will ignore
/// other flags and `ceiling_dirs`, and respect the same environment
/// variables git does. Note, however, that `path` overrides `$GIT_DIR`; to
/// respect `$GIT_DIR` as well, use `open_from_env`.
///
/// ceiling_dirs specifies a list of paths that the search through parent
/// directories will stop before entering. Use the functions in std::env
/// to construct or manipulate such a path list.
Expand Down