summaryrefslogtreecommitdiff
path: root/src/settings.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-06-22 19:17:08 +0900
committerEdward Thomson <ethomson@edwardthomson.com>2018-06-29 14:54:29 +0100
commitbfa1f02292d1b637928fe18663a5f2d0aa993400 (patch)
tree0d08a6eb80acf9b6114d2f817cd9e8cd711daf10 /src/settings.c
parent787768c2d70dfcd1c9ebc1854b5d0f67d2e6d4d9 (diff)
downloadlibgit2-bfa1f02292d1b637928fe18663a5f2d0aa993400.tar.gz
settings: optional unsaved index safety
Add the `GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY` option, which will cause commands that reload the on-disk index to fail if the current `git_index` has changed that have not been saved. This will prevent users from - for example - adding a file to the index then calling a function like `git_checkout` and having that file be silently removed from the index since it was re-read from disk. Now calls that would re-read the index will fail if the index is "dirty", meaning changes have been made to it but have not been written. Users can either `git_index_read` to discard those changes explicitly, or `git_index_write` to write them.
Diffstat (limited to 'src/settings.c')
-rw-r--r--src/settings.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/settings.c b/src/settings.c
index 14280f8c0..ba2f7158c 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -23,6 +23,7 @@
#include "object.h"
#include "odb.h"
#include "refs.h"
+#include "index.h"
#include "transports/smart.h"
#include "streams/openssl.h"
#include "streams/mbedtls.h"
@@ -265,6 +266,10 @@ int git_libgit2_opts(int key, ...)
error = git_allocator_setup(va_arg(ap, git_allocator *));
break;
+ case GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY:
+ git_index__enforce_unsaved_safety = (va_arg(ap, int) != 0);
+ break;
+
default:
giterr_set(GITERR_INVALID, "invalid option key");
error = -1;