From 847095cf322618a1739ef4e9baf35f58bd4b59f7 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sat, 28 Sep 2013 22:42:35 +0200 Subject: [PATCH] Warn user before saving if source differs from destination store Signed-off-by: Sven Strickroth --- src/Resources/TortoiseProcENG.rc | 1 + src/TortoiseProc/Settings/GitSettings.h | 20 ++++++++++++++++++++ src/TortoiseProc/resource.h | 1 + 3 files changed, 22 insertions(+) diff --git a/src/Resources/TortoiseProcENG.rc b/src/Resources/TortoiseProcENG.rc index 70a43052a..4a22a4d29 100644 --- a/src/Resources/TortoiseProcENG.rc +++ b/src/Resources/TortoiseProcENG.rc @@ -4245,6 +4245,7 @@ BEGIN IDS_CONFIG_PROJECT_TT ".tgitconfig in the repository root" IDS_CONFIG_LOCAL_TT ".git/config in the repository root" IDS_ASK_DELETE_EMPTY "You are about to save an empty/default value. This can be useful to prevent inheriting another value.\nDo you want to remove the key instead of saving the empty/default value?" + IDS_WARNUSERSAFEDIFFERENT "Are you sure you want to save to ""%s""?" END #endif // English (U.S.) resources diff --git a/src/TortoiseProc/Settings/GitSettings.h b/src/TortoiseProc/Settings/GitSettings.h index 6e3894d78..1718be1e7 100644 --- a/src/TortoiseProc/Settings/GitSettings.h +++ b/src/TortoiseProc/Settings/GitSettings.h @@ -165,6 +165,20 @@ protected: git_config_free(config); } + bool WarnUserSafeToDifferentDestination(int storeTo) + { + if ((storeTo == IDS_CONFIG_GLOBAL && m_iConfigSource != 3) || (storeTo == IDS_CONFIG_PROJECT && m_iConfigSource != 2) || (storeTo == IDS_CONFIG_LOCAL && m_iConfigSource != 1)) + { + CString dest; + dest.LoadString(storeTo); + CString msg; + msg.Format(IDS_WARNUSERSAFEDIFFERENT, dest); + if (CMessageBox::Show(nullptr, msg, _T("TortoiseGit"), 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_SAVEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2) + return false; + } + return true; + } + BOOL SafeData() { git_config * config; @@ -173,6 +187,8 @@ protected: int err = 0; if (m_bGlobal || (m_cSaveTo.GetCurSel() == 1 && (!m_bHonorProjectConfig || m_bIsBareRepo)) || m_cSaveTo.GetCurSel() == 2) { + if (!WarnUserSafeToDifferentDestination(IDS_CONFIG_GLOBAL)) + return FALSE; if (PathIsDirectory(g_Git.GetGitGlobalXDGConfigPath())) err = git_config_add_file_ondisk(config, CUnicodeUtils::GetUTF8(g_Git.GetGitGlobalXDGConfig()), GIT_CONFIG_LEVEL_XDG, FALSE); else @@ -180,10 +196,14 @@ protected: } else if (m_cSaveTo.GetCurSel() == 1 && !m_bIsBareRepo && m_bHonorProjectConfig) { + if (!WarnUserSafeToDifferentDestination(IDS_CONFIG_PROJECT)) + return FALSE; err = git_config_add_file_ondisk(config, CUnicodeUtils::GetUTF8(g_Git.m_CurrentDir) + "\\.tgitconfig", GIT_CONFIG_LEVEL_APP, FALSE); } else { + if (!WarnUserSafeToDifferentDestination(IDS_CONFIG_PROJECT)) + return FALSE; err = git_config_add_file_ondisk(config, CUnicodeUtils::GetMulti(g_Git.GetGitLocalConfig(), CP_UTF8), GIT_CONFIG_LEVEL_LOCAL, FALSE); } if (err) diff --git a/src/TortoiseProc/resource.h b/src/TortoiseProc/resource.h index 9d1d68aff..c43c48860 100644 --- a/src/TortoiseProc/resource.h +++ b/src/TortoiseProc/resource.h @@ -947,6 +947,7 @@ #define IDS_CONFIG_PROJECT_TT 1447 #define IDS_CONFIG_LOCAL_TT 1448 #define IDS_ASK_DELETE_EMPTY 1449 +#define IDS_WARNUSERSAFEDIFFERENT 1450 #define IDC_TEXTSIZE2 1462 #define IDC_SHOWUNVERSIONEDOVERLAY 1462 #define IDC_LINK 1466 -- 2.11.4.GIT