@matheusbsbs / matheus-bagliano / commits / 0bee591869
Fork 0

Enable reflogs by default in any repository with a working directory.

New and experienced Git users alike are finding out too late that they forgot to enable reflogs in the current repository, and cannot use the information stored within it to recover from an incorrectly entered command such as `git reset --hard HEAD^^^` when they really meant HEAD^^ (aka HEAD~2). So enable reflogs by default in all future versions of Git, unless the user specifically disables it with: [core] logAllRefUpdates = false in their .git/config or ~/.gitconfig. We only enable reflogs in repositories that have a working directory associated with them, as shared/bare repositories do not have an easy means to prune away old log entries, or may fail logging entirely if the user's gecos information is not valid during a push. This heuristic was suggested on the mailing list by Junio. Documentation was also updated to indicate the new default behavior. We probably should start to teach usuing the reflog to recover from mistakes in some of the tutorial material, as new users are likely to make a few along the way and will feel better knowing they can recover from them quickly and easily, without fsck-objects' lost+found features. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Dec 14, 2006 at 17:41 UTC 0bee59186976b1d9e6b2dd77332480c9480131d5
5 files changed +21 -4
Documentation/config.txt
+5 -2
@@ -79,8 +79,11 @@ core.logAllRefUpdates::
79 file is automatically created for branch heads.
80
81 This information can be used to determine what commit
82 - was the tip of a branch "2 days ago". This value is
83 - false by default (no automated creation of log files).
82 + was the tip of a branch "2 days ago".
83 +
84 + This value is true by default in a repository that has
85 + a working directory associated with it, and false by
86 + default in a bare repository.
87
88 core.repositoryFormatVersion::
89 Internal variable identifying the repository format and layout
builtin-init-db.c
+3
@@ -242,6 +242,9 @@ static int create_default_files(const char *git_dir, const char *template_path)
242 filemode ? "true" : "false");
243 }
244
245 + /* Enable logAllRefUpdates if a working tree is attached */
246 + if (!is_bare_git_dir(git_dir))
247 + git_config_set("core.logallrefupdates", "true");
248 return reinit;
249 }
250
cache.h
+1
@@ -123,6 +123,7 @@ extern int cache_errno;
123 #define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
124 #define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
125
126 +extern int is_bare_git_dir(const char *dir);
127 extern const char *get_git_dir(void);
128 extern char *get_object_directory(void);
129 extern char *get_refs_directory(void);
environment.c
+10
@@ -48,6 +48,16 @@ static void setup_git_env(void)
48 git_graft_file = getenv(GRAFT_ENVIRONMENT);
49 if (!git_graft_file)
50 git_graft_file = xstrdup(git_path("info/grafts"));
51 + log_all_ref_updates = !is_bare_git_dir(git_dir);
52 +}
53 +
54 +int is_bare_git_dir (const char *dir)
55 +{
56 + const char *s;
57 + if (!strcmp(dir, DEFAULT_GIT_DIR_ENVIRONMENT))
58 + return 0;
59 + s = strrchr(dir, '/');
60 + return !s || strcmp(s + 1, DEFAULT_GIT_DIR_ENVIRONMENT);
61 }
62
63 const char *get_git_dir(void)
t/t1400-update-ref.sh
+2 -2
@@ -63,8 +63,8 @@ test_expect_failure \
63 "test $B"' = $(cat .git/'"$m"')'
64 rm -f .git/$m
65
66 -mkdir -p .git/logs/refs/heads
67 -touch .git/logs/refs/heads/master
66 +: a repository with working tree always has reflog these days...
67 +: >.git/logs/refs/heads/master
68 test_expect_success \
69 "create $m (logged by touch)" \
70 'GIT_COMMITTER_DATE="2005-05-26 23:30" \