diff --git a/Documentation/config.txt b/Documentation/config.txt index a3587f8397..8abb0820ff 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -79,8 +79,11 @@ core.logAllRefUpdates:: file is automatically created for branch heads. This information can be used to determine what commit - was the tip of a branch "2 days ago". This value is - false by default (no automated creation of log files). + was the tip of a branch "2 days ago". + + This value is true by default in a repository that has + a working directory associated with it, and false by + default in a bare repository. core.repositoryFormatVersion:: Internal variable identifying the repository format and layout diff --git a/builtin-init-db.c b/builtin-init-db.c index 8f2b7500dc..1d7d15e8d5 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -242,6 +242,9 @@ static int create_default_files(const char *git_dir, const char *template_path) filemode ? "true" : "false"); } + /* Enable logAllRefUpdates if a working tree is attached */ + if (!is_bare_git_dir(git_dir)) + git_config_set("core.logallrefupdates", "true"); return reinit; } diff --git a/cache.h b/cache.h index f2ec5c8c14..2d3df98dc4 100644 --- a/cache.h +++ b/cache.h @@ -123,6 +123,7 @@ extern int cache_errno; #define INDEX_ENVIRONMENT "GIT_INDEX_FILE" #define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE" +extern int is_bare_git_dir(const char *dir); extern const char *get_git_dir(void); extern char *get_object_directory(void); extern char *get_refs_directory(void); diff --git a/environment.c b/environment.c index 84d870ca4e..f8c7dbcead 100644 --- a/environment.c +++ b/environment.c @@ -48,6 +48,16 @@ static void setup_git_env(void) git_graft_file = getenv(GRAFT_ENVIRONMENT); if (!git_graft_file) git_graft_file = xstrdup(git_path("info/grafts")); + log_all_ref_updates = !is_bare_git_dir(git_dir); +} + +int is_bare_git_dir (const char *dir) +{ + const char *s; + if (!strcmp(dir, DEFAULT_GIT_DIR_ENVIRONMENT)) + return 0; + s = strrchr(dir, '/'); + return !s || strcmp(s + 1, DEFAULT_GIT_DIR_ENVIRONMENT); } const char *get_git_dir(void) diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 6a917f2ff4..5637cb5eac 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -63,8 +63,8 @@ test_expect_failure \ "test $B"' = $(cat .git/'"$m"')' rm -f .git/$m -mkdir -p .git/logs/refs/heads -touch .git/logs/refs/heads/master +: a repository with working tree always has reflog these days... +: >.git/logs/refs/heads/master test_expect_success \ "create $m (logged by touch)" \ 'GIT_COMMITTER_DATE="2005-05-26 23:30" \