]> git.proxmox.com Git - libgit2.git/commitdiff
Add tests for deleting a config var
authorCarlos Martín Nieto <cmn@elego.de>
Tue, 28 Jun 2011 13:21:44 +0000 (15:21 +0200)
committerVicent Marti <tanoku@gmail.com>
Tue, 5 Jul 2011 00:32:17 +0000 (02:32 +0200)
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
include/git2/config.h
tests/resources/config/config9
tests/t15-config.c

index 75003645411fab508058e3ef2084b60e004ed0cb..a8bff6cf0cddd7a76d54eaa3ca9479b3c52eb120 100644 (file)
@@ -254,7 +254,15 @@ GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value
 GIT_EXTERN(int) git_config_set_string(git_config *cfg, const char *name, const char *value);
 
 /**
- * Perform an operation on each config variable
+ * Delete a config variable
+ *
+ * @param cfg the configuration
+ * @param name the variable to delete
+ */
+GIT_EXTERN(int) git_config_del(git_config *cfg, const char *name);
+
+/**
+ * Perform an operation on each config variable.
  *
  * The callback receives the normalized name and value of each variable
  * in the config backend, and the data pointer passed to this function.
index 4359c7826d86b2d7b3b182475612c3e9690fc734..34fdc07a546da022458ffb17229fb9c39ce9a961 100644 (file)
@@ -1,2 +1,3 @@
 [core]
+       dummy2 = 42
        dummy = 1
index 63fe8e1008e3c7ed64b4739e5379149bfe0b8492..25cdcbd6508a44bd70652f658b649ce3c2adcf74 100644 (file)
@@ -235,6 +235,34 @@ BEGIN_TEST(config11, "fall back to the global config")
        git_repository_free(repo);
 END_TEST
 
+BEGIN_TEST(config12, "delete a value")
+       git_config *cfg;
+       int i;
+
+       /* By freeing the config, we make sure we flush the values  */
+       must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config9"));
+       must_pass(git_config_set_int(cfg, "core.dummy", 5));
+       git_config_free(cfg);
+
+       must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config9"));
+       must_pass(git_config_del(cfg, "core.dummy"));
+       git_config_free(cfg);
+
+       must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config9"));
+       must_be_true(git_config_get_int(cfg, "core.dummy", &i) == GIT_ENOTFOUND);
+       must_pass(git_config_set_int(cfg, "core.dummy", 1));
+       git_config_free(cfg);
+END_TEST
+
+BEGIN_TEST(config13, "can't delete a non-existent value")
+       git_config *cfg;
+
+       /* By freeing the config, we make sure we flush the values  */
+       must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config9"));
+       must_be_true(git_config_del(cfg, "core.imaginary") == GIT_ENOTFOUND);
+       git_config_free(cfg);
+END_TEST
+
 BEGIN_SUITE(config)
         ADD_TEST(config0);
         ADD_TEST(config1);
@@ -248,4 +276,6 @@ BEGIN_SUITE(config)
         ADD_TEST(config9);
         ADD_TEST(config10);
         ADD_TEST(config11);
+        ADD_TEST(config12);
+        ADD_TEST(config13);
 END_SUITE