From 0c8dae23755d31ff9a19137ec8049804fc652444 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Sat, 7 Feb 2015 12:53:54 -0800 Subject: [PATCH] Only run git_deconfig if Git configuration exists This will let us run 'git lock' even if no filters are configured. This logic is more complicated than I would like because running 'git config --remove-section' on a non-existent section results in a noisy error (with text printed to stderr and an exit code of 128) instead of a quiet error like the other 'git config' commands. --- commands.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/commands.cpp b/commands.cpp index 78674bb..fc44021 100644 --- a/commands.cpp +++ b/commands.cpp @@ -73,6 +73,22 @@ static void git_config (const std::string& name, const std::string& value) } } +static bool git_has_config (const std::string& name) +{ + std::vector command; + command.push_back("git"); + command.push_back("config"); + command.push_back("--get-all"); + command.push_back(name); + + std::stringstream output; + switch (exit_status(exec_command(command, output))) { + case 0: return true; + case 1: return false; + default: throw Error("'git config' failed"); + } +} + static void git_deconfig (const std::string& name) { std::vector command; @@ -110,8 +126,16 @@ static void configure_git_filters (const char* key_name) static void deconfigure_git_filters (const char* key_name) { // deconfigure the git-crypt filters - git_deconfig("filter." + attribute_name(key_name)); - git_deconfig("diff." + attribute_name(key_name)); + if (git_has_config("filter." + attribute_name(key_name) + ".smudge") || + git_has_config("filter." + attribute_name(key_name) + ".clean") || + git_has_config("filter." + attribute_name(key_name) + ".required")) { + + git_deconfig("filter." + attribute_name(key_name)); + } + + if (git_has_config("diff." + attribute_name(key_name) + ".textconv")) { + git_deconfig("diff." + attribute_name(key_name)); + } } static bool git_checkout (const std::vector& paths)