#include "clar_libgit2.h"
-#include "buffer.h"
-#include "path.h"
+#include "fs_path.h"
static git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config1")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.that.other"));
- cl_assert_equal_s("true", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("true", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.other"));
- cl_assert_equal_s("yes", git_buf_cstr(&buf));
+ cl_assert_equal_s("yes", buf.ptr);
cl_git_pass(git_config_get_bool(&i, cfg, "this.that.other"));
cl_assert(i == 1);
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.and"));
- cl_assert_equal_s("one one one two two three three", git_buf_cstr(&buf));
+ cl_assert_equal_s("one one one two two three three", buf.ptr);
git_config_free(cfg);
}
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "header.key1"));
- cl_assert_equal_s("foo", git_buf_cstr(&buf));
+ cl_assert_equal_s("foo", buf.ptr);
git_config_free(cfg);
}
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "header.key1"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", buf.ptr);
git_config_free(cfg);
}
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config3")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "section.subsection.var"));
- cl_assert_equal_s("hello", git_buf_cstr(&buf));
+ cl_assert_equal_s("hello", buf.ptr);
/* The subsection is transformed to lower-case */
cl_must_fail(git_config_get_string_buf(&buf, cfg, "section.subSectIon.var"));
cl_git_fail(git_config_get_int32(&i, cfg, "some.section.variable"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variable"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable"));
cl_assert(i == 1);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variableeq"));
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", buf.ptr);
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variableeq"));
cl_assert(i == 0);
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config20")));
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "valid.[subsection].something"));
+ cl_assert_equal_s("a", buf.ptr);
+ git_buf_dispose(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "sec.[subsec]/child.parent"));
+ cl_assert_equal_s("grand", buf.ptr);
+ git_buf_dispose(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "sec2.[subsec2]/child2.type"));
+ cl_assert_equal_s("dvcs", buf.ptr);
+ git_buf_dispose(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "sec3.escape\"quote.vcs"));
+ cl_assert_equal_s("git", buf.ptr);
+ git_buf_dispose(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "sec4.escaping\\slash.lib"));
+ cl_assert_equal_s("git2", buf.ptr);
+ git_buf_dispose(&buf);
git_config_free(cfg);
}
git_config_free(cfg);
}
+void test_config_read__multiline_multiple_quoted_quote_at_beginning_of_line(void)
+{
+ git_config* cfg;
+ cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config22")));
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "alias.m"));
+ cl_assert_equal_s("cmd ;; ;; bar", buf.ptr);
+ git_buf_dispose(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, cfg, "alias.m2"));
+ cl_assert_equal_s("'; ; something '", buf.ptr);
+ git_buf_dispose(&buf);
+ git_config_free(cfg);
+}
+
void test_config_read__header_in_last_line(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.ab.url"));
- cl_assert_equal_s("http://example.com/git/ab", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("http://example.com/git/ab", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.abba.url"));
- cl_assert_equal_s("http://example.com/git/abba", git_buf_cstr(&buf));
+ cl_assert_equal_s("http://example.com/git/abba", buf.ptr);
git_config_free(cfg);
}
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.editor"));
- cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", git_buf_cstr(&buf));
+ cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", buf.ptr);
git_config_free(cfg);
}
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config14")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "a.b"));
- cl_assert_equal_s("c", git_buf_cstr(&buf));
- git_buf_clear(&buf);
+ cl_assert_equal_s("c", buf.ptr);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "d.e"));
- cl_assert_equal_s("f", git_buf_cstr(&buf));
+ cl_assert_equal_s("f", buf.ptr);
git_config_free(cfg);
}
cl_git_pass(git_config_get_bool(&i, cfg_specific, "core.boolglobal"));
cl_assert_equal_b(true, i);
cl_git_pass(git_config_get_string_buf(&buf, cfg_specific, "core.stringglobal"));
- cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
+ cl_assert_equal_s("I'm a global config value!", buf.ptr);
git_config_free(cfg_specific);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
- cl_assert_equal_s("two", git_buf_cstr(&buf));
+ cl_assert_equal_s("two", buf.ptr);
git_config_free(cfg);
}
git_config *cfg;
git_buf path = GIT_BUF_INIT;
git_buf old_path = GIT_BUF_INIT;
- git_buf home_path = GIT_BUF_INIT;
- git_buf expected_path = GIT_BUF_INIT;
+ git_str home_path = GIT_STR_INIT;
+ git_str expected_path = GIT_STR_INIT;
cl_git_pass(p_mkdir("fakehome", 0777));
- cl_git_pass(git_path_prettify(&home_path, "fakehome", NULL));
+ cl_git_pass(git_fs_path_prettify(&home_path, "fakehome", NULL));
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &old_path));
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, home_path.ptr));
cl_git_mkfile("./testconfig", "[some]\n path = ~/somefile");
- cl_git_pass(git_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL));
+ cl_git_pass(git_fs_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL));
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
git_buf_dispose(&path);
cl_git_mkfile("./testconfig", "[some]\n path = ~/");
- cl_git_pass(git_path_join_unrooted(&expected_path, "", home_path.ptr, NULL));
+ cl_git_pass(git_fs_path_join_unrooted(&expected_path, "", home_path.ptr, NULL));
cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
cl_assert_equal_s(expected_path.ptr, path.ptr);
git_buf_dispose(&path);
cl_git_mkfile("./testconfig", "[some]\n path = ~");
- cl_git_pass(git_buf_sets(&expected_path, home_path.ptr));
+ cl_git_pass(git_str_sets(&expected_path, home_path.ptr));
cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
cl_assert_equal_s(expected_path.ptr, path.ptr);
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, old_path.ptr));
git_buf_dispose(&old_path);
- git_buf_dispose(&home_path);
- git_buf_dispose(&expected_path);
+ git_str_dispose(&home_path);
+ git_str_dispose(&expected_path);
git_config_free(cfg);
}
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s(buf.ptr, "value");
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.OtheR.var"));
cl_assert_equal_s(buf.ptr, "value");
git_config_free(cfg);
cl_git_mkfile("./testconfig", "[some] var = value\n[some \"OtheR\"]var = value");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s(buf.ptr, "value");
- git_buf_clear(&buf);
+ git_buf_dispose(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.OtheR.var"));
cl_assert_equal_s(buf.ptr, "value");