Skip to content

Commit d7ac12b

Browse files
dschogitster
authored andcommitted
Add set_git_dir() function
With the function set_git_dir() you can reset the path that will be used for git_path(), git_dir() and friends. The responsibility to close files and throw away information from the old git_dir lies with the caller. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e663674 commit d7ac12b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ extern char *get_object_directory(void);
214214
extern char *get_refs_directory(void);
215215
extern char *get_index_file(void);
216216
extern char *get_graft_file(void);
217+
extern int set_git_dir(const char *path);
217218

218219
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
219220

environment.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,11 @@ char *get_graft_file(void)
107107
setup_git_env();
108108
return git_graft_file;
109109
}
110+
111+
int set_git_dir(const char *path)
112+
{
113+
if (setenv(GIT_DIR_ENVIRONMENT, path, 1))
114+
return error("Could not set GIT_DIR to '%s'", path);
115+
setup_git_env();
116+
return 0;
117+
}

0 commit comments

Comments
 (0)