Skip to content

Commit

Permalink
Merge branch 'nd/setup'
Browse files Browse the repository at this point in the history
* nd/setup: (47 commits)
  setup_work_tree: adjust relative $GIT_WORK_TREE after moving cwd
  git.txt: correct where --work-tree path is relative to
  Revert "Documentation: always respect core.worktree if set"
  t0001: test git init when run via an alias
  Remove all logic from get_git_work_tree()
  setup: rework setup_explicit_git_dir()
  setup: clean up setup_discovered_git_dir()
  t1020-subdirectory: test alias expansion in a subdirectory
  setup: clean up setup_bare_git_dir()
  setup: limit get_git_work_tree()'s to explicit setup case only
  Use git_config_early() instead of git_config() during repo setup
  Add git_config_early()
  git-rev-parse.txt: clarify --git-dir
  t1510: setup case #31
  t1510: setup case #30
  t1510: setup case #29
  t1510: setup case #28
  t1510: setup case #27
  t1510: setup case #26
  t1510: setup case #25
  ...
  • Loading branch information
Junio C Hamano committed Dec 28, 2010
2 parents 73e7b2e + 0ed7481 commit f3bb8b4
Show file tree
Hide file tree
Showing 17 changed files with 4,868 additions and 134 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
/test-sha1
/test-sigchain
/test-string-pool
/test-subprocess
/test-svn-fe
/test-treap
/common-cmds.h
Expand Down
23 changes: 8 additions & 15 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -317,24 +317,17 @@ false), while all other repositories are assumed to be bare (bare
= true).

core.worktree::
Set the path to the root of the work tree.
Set the path to the working tree. The value will not be
used in combination with repositories found automatically in
a .git directory (i.e. $GIT_DIR is not set).
This can be overridden by the GIT_WORK_TREE environment
variable and the '--work-tree' command line option. It can be
an absolute path or a relative path to the .git directory,
either specified by --git-dir or GIT_DIR, or automatically
discovered.
If --git-dir or GIT_DIR are specified but none of
an absolute path or relative path to the directory specified by
--git-dir or GIT_DIR.
Note: If --git-dir or GIT_DIR are specified but none of
--work-tree, GIT_WORK_TREE and core.worktree is specified,
the current working directory is regarded as the root of the
work tree.
+
Note that this variable is honored even when set in a configuration
file in a ".git" subdirectory of a directory, and its value differs
from the latter directory (e.g. "/path/to/.git/config" has
core.worktree set to "/different/path"), which is most likely a
misconfiguration. Running git commands in "/path/to" directory will
still use "/different/path" as the root of the work tree and can cause
great confusion to the users.
the current working directory is regarded as the top directory
of your working tree.

core.logAllRefUpdates::
Enable the reflog. Updates to a ref <ref> is logged to the file
Expand Down
7 changes: 6 additions & 1 deletion Documentation/git-rev-parse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ appending `/{asterisk}`.
directory (typically a sequence of "../", or an empty string).

--git-dir::
Show `$GIT_DIR` if defined else show the path to the .git directory.
Show `$GIT_DIR` if defined. Otherwise show the path to
the .git directory, relative to the current directory.
+
If `$GIT_DIR` is not defined and the current directory
is not detected to lie in a git repository or work tree
print a message to stderr and exit with nonzero status.

--is-inside-git-dir::
When the current working directory is below the repository
Expand Down
2 changes: 1 addition & 1 deletion Documentation/git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ help ...`.
This can also be controlled by setting the GIT_WORK_TREE
environment variable and the core.worktree configuration
variable. It can be an absolute path or relative path to
the directory specified by --git-dir or GIT_DIR.
current working directory.
Note: If --git-dir or GIT_DIR are specified but none of
--work-tree, GIT_WORK_TREE and core.worktree is specified,
the current working directory is regarded as the top directory
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ TEST_PROGRAMS_NEED_X += test-run-command
TEST_PROGRAMS_NEED_X += test-sha1
TEST_PROGRAMS_NEED_X += test-sigchain
TEST_PROGRAMS_NEED_X += test-string-pool
TEST_PROGRAMS_NEED_X += test-subprocess
TEST_PROGRAMS_NEED_X += test-svn-fe
TEST_PROGRAMS_NEED_X += test-treap
TEST_PROGRAMS_NEED_X += test-index-version
Expand Down
13 changes: 11 additions & 2 deletions builtin/init-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ static const char *const init_db_usage[] = {
int cmd_init_db(int argc, const char **argv, const char *prefix)
{
const char *git_dir;
const char *work_tree;
const char *template_dir = NULL;
unsigned int flags = 0;
const struct option init_db_options[] = {
Expand Down Expand Up @@ -480,8 +481,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
* without --bare. Catch the error early.
*/
git_dir = getenv(GIT_DIR_ENVIRONMENT);
if ((!git_dir || is_bare_repository_cfg == 1)
&& getenv(GIT_WORK_TREE_ENVIRONMENT))
work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
if ((!git_dir || is_bare_repository_cfg == 1) && work_tree)
die("%s (or --work-tree=<directory>) not allowed without "
"specifying %s (or --git-dir=<directory>)",
GIT_WORK_TREE_ENVIRONMENT,
Expand Down Expand Up @@ -510,10 +511,18 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
if (!getcwd(git_work_tree_cfg, PATH_MAX))
die_errno ("Cannot access current working directory");
}
if (work_tree)
set_git_work_tree(make_absolute_path(work_tree));
else
set_git_work_tree(git_work_tree_cfg);
if (access(get_git_work_tree(), X_OK))
die_errno ("Cannot access work tree '%s'",
get_git_work_tree());
}
else {
if (work_tree)
set_git_work_tree(make_absolute_path(work_tree));
}

set_git_dir(make_absolute_path(git_dir));

Expand Down
2 changes: 2 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ extern int git_config_parse_parameter(const char *text);
extern int git_config_parse_environment(void);
extern int git_config_from_parameters(config_fn_t fn, void *data);
extern int git_config(config_fn_t fn, void *);
extern int git_config_early(config_fn_t fn, void *, const char *repo_config);
extern int git_parse_ulong(const char *, unsigned long *);
extern int git_config_int(const char *, const char *);
extern unsigned long git_config_ulong(const char *, const char *);
Expand Down Expand Up @@ -1066,6 +1067,7 @@ __attribute__((format (printf, 1, 2)))
extern void trace_printf(const char *format, ...);
__attribute__((format (printf, 2, 3)))
extern void trace_argv_printf(const char **argv, const char *format, ...);
extern void trace_repo_setup(const char *prefix);

/* convert.c */
/* returns 1 if *dst was used */
Expand Down
19 changes: 14 additions & 5 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,9 @@ int git_config_from_parameters(config_fn_t fn, void *data)
return 0;
}

int git_config(config_fn_t fn, void *data)
int git_config_early(config_fn_t fn, void *data, const char *repo_config)
{
int ret = 0, found = 0;
char *repo_config = NULL;
const char *home = NULL;

/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
Expand All @@ -877,12 +876,10 @@ int git_config(config_fn_t fn, void *data)
free(user_config);
}

repo_config = git_pathdup("config");
if (!access(repo_config, R_OK)) {
if (repo_config && !access(repo_config, R_OK)) {
ret += git_config_from_file(fn, repo_config, data);
found += 1;
}
free(repo_config);

ret += git_config_from_parameters(fn, data);
if (config_parameters)
Expand All @@ -891,6 +888,18 @@ int git_config(config_fn_t fn, void *data)
return ret == 0 ? found : ret;
}

int git_config(config_fn_t fn, void *data)
{
char *repo_config = NULL;
int ret;

repo_config = git_pathdup("config");
ret = git_config_early(fn, data, repo_config);
if (repo_config)
free(repo_config);
return ret;
}

/*
* Find all the stuff for git_config_set() below.
*/
Expand Down
26 changes: 8 additions & 18 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,20 @@ static int git_work_tree_initialized;
*/
void set_git_work_tree(const char *new_work_tree)
{
if (is_bare_repository_cfg >= 0)
die("cannot set work tree after initialization");
if (git_work_tree_initialized) {
new_work_tree = make_absolute_path(new_work_tree);
if (strcmp(new_work_tree, work_tree))
die("internal error: work tree has already been set\n"
"Current worktree: %s\nNew worktree: %s",
work_tree, new_work_tree);
return;
}
git_work_tree_initialized = 1;
free(work_tree);
work_tree = xstrdup(make_absolute_path(new_work_tree));
is_bare_repository_cfg = 0;
}

const char *get_git_work_tree(void)
{
if (!git_work_tree_initialized) {
work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
/* core.bare = true overrides implicit and config work tree */
if (!work_tree && is_bare_repository_cfg < 1) {
work_tree = git_work_tree_cfg;
/* make_absolute_path also normalizes the path */
if (work_tree && !is_absolute_path(work_tree))
work_tree = xstrdup(make_absolute_path(git_path("%s", work_tree)));
} else if (work_tree)
work_tree = xstrdup(make_absolute_path(work_tree));
git_work_tree_initialized = 1;
if (work_tree)
is_bare_repository_cfg = 0;
}
return work_tree;
}

Expand Down
4 changes: 4 additions & 0 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
use_pager = check_pager_config(p->cmd);
if (use_pager == -1 && p->option & USE_PAGER)
use_pager = 1;

if ((p->option & (RUN_SETUP | RUN_SETUP_GENTLY)) &&
startup_info->have_repository) /* get_git_dir() may set up repo, avoid that */
trace_repo_setup(prefix);
}
commit_pager_choice();

Expand Down
Loading

0 comments on commit f3bb8b4

Please sign in to comment.