diff options
-rw-r--r-- | include/git2/common.h | 14 | ||||
-rw-r--r-- | src/libgit2/libgit2.c | 19 |
2 files changed, 32 insertions, 1 deletions
diff --git a/include/git2/common.h b/include/git2/common.h index ccf66334a..f968deb23 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -222,7 +222,9 @@ typedef enum { GIT_OPT_GET_EXTENSIONS, GIT_OPT_SET_EXTENSIONS, GIT_OPT_GET_OWNER_VALIDATION, - GIT_OPT_SET_OWNER_VALIDATION + GIT_OPT_SET_OWNER_VALIDATION, + GIT_OPT_GET_HOMEDIR, + GIT_OPT_SET_HOMEDIR } git_libgit2_opt_t; /** @@ -468,6 +470,16 @@ typedef enum { * > Set that repository directories should be owned by the current * > user. The default is to validate ownership. * + * opts(GIT_OPT_GET_HOMEDIR, git_buf *out) + * > Gets the current user's home directory, as it will be used + * > for file lookups. The path is written to the `out` buffer. + * + * opts(GIT_OPT_SET_HOMEDIR, const char *path) + * > Sets the directory used as the current user's home directory, + * > for file lookups. + * > + * > - `path` directory of home directory. + * * @param option Option key * @param ... value to set the option * @return 0 on success, <0 on failure diff --git a/src/libgit2/libgit2.c b/src/libgit2/libgit2.c index 2fda0722e..f225122e5 100644 --- a/src/libgit2/libgit2.c +++ b/src/libgit2/libgit2.c @@ -414,6 +414,25 @@ int git_libgit2_opts(int key, ...) git_repository__validate_ownership = (va_arg(ap, int) != 0); break; + case GIT_OPT_GET_HOMEDIR: + { + git_buf *out = va_arg(ap, git_buf *); + git_str str = GIT_STR_INIT; + const git_str *tmp; + + if ((error = git_buf_tostr(&str, out)) < 0 || + (error = git_sysdir_get(&tmp, GIT_SYSDIR_HOME)) < 0 || + (error = git_str_put(&str, tmp->ptr, tmp->size)) < 0) + break; + + error = git_buf_fromstr(out, &str); + } + break; + + case GIT_OPT_SET_HOMEDIR: + error = git_sysdir_set(GIT_SYSDIR_HOME, va_arg(ap, const char *)); + break; + default: git_error_set(GIT_ERROR_INVALID, "invalid option key"); error = -1; |