From 4948f779bade5da68fb509ac44d7aca8c65bfb04 Mon Sep 17 00:00:00 2001 From: maxisam <456807+maxisam@users.noreply.github.com.> Date: Mon, 11 Nov 2024 00:56:46 -0600 Subject: [PATCH] feat: Enhance git_config functions to support worktree option #105 --- commands.cpp | 14 +++++++++----- commands.hpp | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/commands.cpp b/commands.cpp index 6b3c498..232c0d0 100644 --- a/commands.cpp +++ b/commands.cpp @@ -111,11 +111,12 @@ static std::vector make_version (int a, int b, int c) return version; } -static void git_config (const std::string& name, const std::string& value) +static void git_config (const std::string& name, const std::string& value, bool from_worktree=true) { std::vector command; command.push_back("git"); command.push_back("config"); + if (from_worktree) command.push_back("--worktree"); command.push_back(name); command.push_back(value); @@ -124,11 +125,12 @@ static void git_config (const std::string& name, const std::string& value) } } -static bool git_has_config (const std::string& name) +static bool git_has_config (const std::string& name, bool from_worktree) { std::vector command; command.push_back("git"); command.push_back("config"); + if (from_worktree) command.push_back("--worktree"); command.push_back("--get-all"); command.push_back(name); @@ -140,11 +142,12 @@ static bool git_has_config (const std::string& name) } } -static void git_deconfig (const std::string& name) +static void git_deconfig (const std::string& name, bool from_worktree=true) { std::vector command; command.push_back("git"); command.push_back("config"); + if (from_worktree) command.push_back("--worktree"); command.push_back("--remove-section"); command.push_back(name); @@ -277,12 +280,13 @@ static std::string get_internal_key_path (const char* key_name) return path; } -std::string get_git_config (const std::string& name) +std::string get_git_config (const std::string& name, bool from_worktree=true) { // git config --get std::vector command; command.push_back("git"); command.push_back("config"); + if (from_worktree) command.push_back("--worktree"); command.push_back("--get"); command.push_back(name); @@ -321,7 +325,7 @@ static std::string get_repo_state_path () } // Check if the repo state dir has been explicitly configured. If so, use that in path construction. - if (git_has_config("git-crypt.repoStateDir")) { + if (git_has_config("git-crypt.repoStateDir", false)) { std::string repoStateDir = get_git_config("git-crypt.repoStateDir"); // The repoStateDir value must always be relative to git work tree to ensure the repoStateDir can be committed diff --git a/commands.hpp b/commands.hpp index f441e93..7001f32 100644 --- a/commands.hpp +++ b/commands.hpp @@ -71,6 +71,6 @@ void help_refresh (std::ostream&); void help_status (std::ostream&); // other -std::string get_git_config (const std::string& name); +std::string get_git_config (const std::string& name, bool from_worktree=true); #endif