Commit 89454382 by Edward Thomson

core: allow users to configure home directory

Some callers -- like our test suite and the test suites of our language
bindings -- want to isolate the home directory to avoid accidentally
including the executing user's actual home directory data.

Previously, we combined the notion of a home directory and global
configuration -- now that this is separated, we provide users the
ability to configure both.
parent cdf5ae9f
......@@ -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
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment