diff options
author | Vicent Marti <vicent@github.com> | 2014-03-20 20:08:01 +0100 |
---|---|---|
committer | Vicent Marti <vicent@github.com> | 2014-03-20 20:08:01 +0100 |
commit | 7d633572669fdc7d4a0b16984d7124c3e0e45b3d (patch) | |
tree | db5c9459836cb7ab55040fc6e2fccdc2c42d55f4 | |
parent | f29e48995e1af91127157a1eca4177c2f411b1bb (diff) | |
parent | 1c35165993c7aac42421354614e216ea8ad3f353 (diff) | |
download | libgit2-7d633572669fdc7d4a0b16984d7124c3e0e45b3d.tar.gz |
Merge pull request #2194 from libgit2/cmn/reflog-bare
reflog: follow core.logallrefupdates
-rw-r--r-- | src/refdb_fs.c | 44 | ||||
-rw-r--r-- | tests/refs/reflog/reflog.c | 73 |
2 files changed, 104 insertions, 13 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 25316fe46..9120a3e87 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -925,16 +925,34 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co static int has_reflog(git_repository *repo, const char *name); /* We only write if it's under heads/, remotes/ or notes/ or if it already has a log */ -static bool should_write_reflog(git_repository *repo, const char *name) +static int should_write_reflog(int *write, git_repository *repo, const char *name) { - if (has_reflog(repo, name)) - return 1; + git_config *config; + int error, logall, is_bare; - if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR) || - !git__strcmp(name, GIT_HEAD_FILE) || - !git__prefixcmp(name, GIT_REFS_REMOTES_DIR) || - !git__prefixcmp(name, GIT_REFS_NOTES_DIR)) - return 1; + /* Defaults to the oppsite of being bare */ + is_bare = git_repository_is_bare(repo); + logall = !is_bare; + + if ((error = git_repository_config__weakptr(&config, repo)) < 0) + return error; + + error = git_config_get_bool(&logall, config, "core.logallrefupdates"); + if (error < 0 && error != GIT_ENOTFOUND) + return error; + + if (!logall) { + *write = 0; + } else if (has_reflog(repo, name)) { + *write = 1; + } else if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR) || + !git__strcmp(name, GIT_HEAD_FILE) || + !git__prefixcmp(name, GIT_REFS_REMOTES_DIR) || + !git__prefixcmp(name, GIT_REFS_NOTES_DIR)) { + *write = 1; + } else { + *write = 0; + } return 0; } @@ -1030,9 +1048,6 @@ static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref name = git_reference_name(tmp); } - if (error < 0) - goto cleanup; - if (strcmp(name, ref->name)) goto cleanup; @@ -1056,7 +1071,7 @@ static int refdb_fs_backend__write( { refdb_fs_backend *backend = (refdb_fs_backend *)_backend; git_filebuf file = GIT_FILEBUF_INIT; - int error = 0, cmp = 0; + int error = 0, cmp = 0, should_write; const char *new_target = NULL; const git_oid *new_id = NULL; @@ -1094,7 +1109,10 @@ static int refdb_fs_backend__write( goto on_error; /* not really error */ } - if (should_write_reflog(backend->repo, ref->name)) { + if ((error = should_write_reflog(&should_write, backend->repo, ref->name)) < 0) + goto on_error; + + if (should_write) { if ((error = reflog_append(backend, ref, NULL, NULL, who, message)) < 0) goto on_error; if ((error = maybe_append_head(backend, ref, who, message)) < 0) diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c index a50d40aac..792b0f05d 100644 --- a/tests/refs/reflog/reflog.c +++ b/tests/refs/reflog/reflog.c @@ -261,3 +261,76 @@ void test_refs_reflog_reflog__do_not_append_when_no_update(void) cl_assert_equal_i(nlogs_after, nlogs); } + +static void assert_no_reflog_update(void) +{ + size_t nlogs, nlogs_after; + size_t nlogs_master, nlogs_master_after; + git_reference *ref; + git_reflog *log; + git_oid id; + + cl_git_pass(git_reflog_read(&log, g_repo, "HEAD")); + nlogs = git_reflog_entrycount(log); + git_reflog_free(log); + + cl_git_pass(git_reflog_read(&log, g_repo, "refs/heads/master")); + nlogs_master = git_reflog_entrycount(log); + git_reflog_free(log); + + /* Move it back */ + git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/master", &id, 1, NULL, NULL)); + git_reference_free(ref); + + cl_git_pass(git_reflog_read(&log, g_repo, "HEAD")); + nlogs_after = git_reflog_entrycount(log); + git_reflog_free(log); + + cl_assert_equal_i(nlogs_after, nlogs); + + cl_git_pass(git_reflog_read(&log, g_repo, "refs/heads/master")); + nlogs_master_after = git_reflog_entrycount(log); + git_reflog_free(log); + + cl_assert_equal_i(nlogs_after, nlogs); + cl_assert_equal_i(nlogs_master_after, nlogs_master); + +} + +void test_refs_reflog_reflog__logallrefupdates_bare_set_false(void) +{ + git_config *config; + + cl_git_pass(git_repository_config(&config, g_repo)); + cl_git_pass(git_config_set_bool(config, "core.logallrefupdates", false)); + git_config_free(config); + + assert_no_reflog_update(); +} + +void test_refs_reflog_reflog__logallrefupdates_bare_unset(void) +{ + git_config *config; + + cl_git_pass(git_repository_config(&config, g_repo)); + cl_git_pass(git_config_delete_entry(config, "core.logallrefupdates")); + git_config_free(config); + + assert_no_reflog_update(); +} + +void test_refs_reflog_reflog__logallrefupdates_nonbare_set_false(void) +{ + git_config *config; + + cl_git_sandbox_cleanup(); + g_repo = cl_git_sandbox_init("testrepo"); + + + cl_git_pass(git_repository_config(&config, g_repo)); + cl_git_pass(git_config_set_bool(config, "core.logallrefupdates", false)); + git_config_free(config); + + assert_no_reflog_update(); +} |