summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fe61935)
raw | patch | inline | side by side (parent: fe61935)
author | Mike Hommey <mh@glandium.org> | |
Sat, 3 Nov 2007 11:23:11 +0000 (12:23 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 6 Nov 2007 06:47:57 +0000 (22:47 -0800) |
Create a setup_work_tree() that can be used from any command requiring
a working tree conditionally.
Signed-off-by: Mike Hommey <mh@glandium.org>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
a working tree conditionally.
Signed-off-by: Mike Hommey <mh@glandium.org>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h | patch | blob | history | |
git.c | patch | blob | history | |
setup.c | patch | blob | history |
index bfffa05dff149a948e46b04f6b15589e6f4be07e..497b9f962db0ca7f7c8dda8e848126e22da6685f 100644 (file)
--- a/cache.h
+++ b/cache.h
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
extern const char **get_pathspec(const char *prefix, const char **pathspec);
+extern void setup_work_tree(void);
extern const char *setup_git_directory_gently(int *);
extern const char *setup_git_directory(void);
extern const char *prefix_path(const char *prefix, int len, const char *path);
index 4e10581101c26444da5c7c44a80219b11607705b..eb31c93d0f70abdd6230d72f555adbfb121df613 100644 (file)
--- a/git.c
+++ b/git.c
prefix = setup_git_directory();
if (p->option & USE_PAGER)
setup_pager();
- if (p->option & NEED_WORK_TREE) {
- const char *work_tree = get_git_work_tree();
- const char *git_dir = get_git_dir();
- if (!is_absolute_path(git_dir))
- set_git_dir(make_absolute_path(git_dir));
- if (!work_tree || chdir(work_tree))
- die("%s must be run in a work tree", p->cmd);
- }
+ if (p->option & NEED_WORK_TREE)
+ setup_work_tree();
+
trace_argv_printf(argv, argc, "trace: built-in: git");
status = p->fn(argc, argv, prefix);
index 145eca50f41d811c4c8fcb21ed2604e6b2971aba..df006d9c4a674b224f36318742ef01b339d797b3 100644 (file)
--- a/setup.c
+++ b/setup.c
return NULL;
}
+void setup_work_tree(void) {
+ const char *work_tree = get_git_work_tree();
+ const char *git_dir = get_git_dir();
+ if (!is_absolute_path(git_dir))
+ set_git_dir(make_absolute_path(git_dir));
+ if (!work_tree || chdir(work_tree))
+ die("This operation must be run in a work tree");
+}
+
/*
* We cannot decide in this function whether we are in the work tree or
* not, since the config can only be read _after_ this function was called.