From f8a5109ad8ffc390bd0b6787a41c3b44122853fd Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sat, 7 Jul 2012 02:30:23 +0200 Subject: [PATCH] Fixed issue #1264: TortoiseProc might crash if commands are executed w/o a working tree directory Signed-off-by: Sven Strickroth --- src/Changelog.txt | 1 + src/TortoiseProc/Commands/FetchCommand.cpp | 7 ++++++- src/TortoiseProc/Commands/PullCommand.cpp | 17 ++++++++++++++++- src/TortoiseProc/Commands/PushCommand.cpp | 7 ++++++- src/TortoiseProc/Commands/RepoStatusCommand.cpp | 8 +++++++- src/TortoiseProc/Commands/RepositoryBrowserCommand.cpp | 7 ++++++- src/TortoiseProc/Commands/SyncCommand.cpp | 7 ++++++- 7 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/Changelog.txt b/src/Changelog.txt index 87921c156..4767b638e 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -8,6 +8,7 @@ Released: unreleased * Fixed issue #1261: gitdll.dll can crash if an already closed handle is closed again * Fixed issue #1257: HOME environment variable is not set up correctly on x86 * Fixed issue #1262: TortoiseProc might crash if git.exe version is not parseable + * Fixed issue #1264: TortoiseProc might crash if commands are executed w/o a working tree directory = Release 1.7.11.0 = Released: 2012-07-02 diff --git a/src/TortoiseProc/Commands/FetchCommand.cpp b/src/TortoiseProc/Commands/FetchCommand.cpp index 082b1874b..7ac97dd8a 100644 --- a/src/TortoiseProc/Commands/FetchCommand.cpp +++ b/src/TortoiseProc/Commands/FetchCommand.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2011 Sven Strickroth +// Copyright (C) 2011-2012 Sven Strickroth // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -22,6 +22,11 @@ bool FetchCommand::Execute() { + if (!GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) && !GitAdminDir().IsBareRepo(g_Git.m_CurrentDir)) { + CMessageBox::Show(hwndExplorer, IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR); + return false; + } + bool autoClose = false; if (parser.HasVal(_T("closeonend"))) autoClose = !!parser.GetLongVal(_T("closeonend")); diff --git a/src/TortoiseProc/Commands/PullCommand.cpp b/src/TortoiseProc/Commands/PullCommand.cpp index 60297453d..d0fa38db0 100644 --- a/src/TortoiseProc/Commands/PullCommand.cpp +++ b/src/TortoiseProc/Commands/PullCommand.cpp @@ -34,6 +34,11 @@ bool PullCommand::Execute() { + if (!GitAdminDir().HasAdminDir(g_Git.m_CurrentDir)) { + CMessageBox::Show(hwndExplorer, IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR); + return false; + } + CPullFetchDlg dlg; dlg.m_IsPull=TRUE; if(dlg.DoModal()==IDOK) @@ -47,7 +52,17 @@ bool PullCommand::Execute() } CString cmd; - CString hashOld = g_Git.GetHash(L"HEAD"); + CString hashOld; + try + { + hashOld = g_Git.GetHash(_T("HEAD")); + } + catch (char* msg) + { + CString err(msg); + MessageBox(NULL, _T("Could not get HEAD hash.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR); + ExitProcess(1); + } CString cmdRebase; if(dlg.m_bRebase) cmdRebase = "--rebase "; diff --git a/src/TortoiseProc/Commands/PushCommand.cpp b/src/TortoiseProc/Commands/PushCommand.cpp index 120b54954..f03216355 100644 --- a/src/TortoiseProc/Commands/PushCommand.cpp +++ b/src/TortoiseProc/Commands/PushCommand.cpp @@ -1,7 +1,7 @@ // TortoiseGit - a Windows shell extension for easy version control // Copyright (C) 2007-2008 - TortoiseSVN -// Copyright (C) 2008-2011 - TortoiseGit +// Copyright (C) 2008-2012 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -31,6 +31,11 @@ bool PushCommand::Execute() { + if (!GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) && !GitAdminDir().IsBareRepo(g_Git.m_CurrentDir)) { + CMessageBox::Show(hwndExplorer, IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR); + return false; + } + bool autoCloseOnSuccess = false; if (parser.HasVal(_T("closeonend"))) autoCloseOnSuccess = !!parser.GetLongVal(_T("closeonend")); diff --git a/src/TortoiseProc/Commands/RepoStatusCommand.cpp b/src/TortoiseProc/Commands/RepoStatusCommand.cpp index 398771683..fbc7cf0d6 100644 --- a/src/TortoiseProc/Commands/RepoStatusCommand.cpp +++ b/src/TortoiseProc/Commands/RepoStatusCommand.cpp @@ -1,5 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control +// Copyright (C) 2012 - TortoiseGit // Copyright (C) 2007 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -18,11 +19,16 @@ // #include "StdAfx.h" #include "RepoStatusCommand.h" - +#include "MessageBox.h" #include "ChangedDlg.h" bool RepoStatusCommand::Execute() { + if (!GitAdminDir().HasAdminDir(g_Git.m_CurrentDir)) { + CMessageBox::Show(hwndExplorer, IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR); + return false; + } + CChangedDlg dlg; dlg.m_pathList = pathList; dlg.DoModal(); diff --git a/src/TortoiseProc/Commands/RepositoryBrowserCommand.cpp b/src/TortoiseProc/Commands/RepositoryBrowserCommand.cpp index a90726024..2c38001d3 100644 --- a/src/TortoiseProc/Commands/RepositoryBrowserCommand.cpp +++ b/src/TortoiseProc/Commands/RepositoryBrowserCommand.cpp @@ -18,11 +18,16 @@ // #include "StdAfx.h" #include "RepositoryBrowserCommand.h" - +#include "MessageBox.h" #include "RepositoryBrowser.h" bool RepositoryBrowserCommand::Execute() { + if (!GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) && !GitAdminDir().IsBareRepo(g_Git.m_CurrentDir)) { + CMessageBox::Show(hwndExplorer, IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR); + return false; + } + CString rev = _T("HEAD"); CString val = parser.GetVal(_T("rev")); if (!val.IsEmpty()) diff --git a/src/TortoiseProc/Commands/SyncCommand.cpp b/src/TortoiseProc/Commands/SyncCommand.cpp index 6fb1b31d6..8f7dfa0e1 100644 --- a/src/TortoiseProc/Commands/SyncCommand.cpp +++ b/src/TortoiseProc/Commands/SyncCommand.cpp @@ -1,7 +1,7 @@ // TortoiseGit - a Windows shell extension for easy version control // Copyright (C) 2008-2009 - TortoiseSVN -// Copyright (C) 2008-2011 - TortoiseGit +// Copyright (C) 2008-2012 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -28,6 +28,11 @@ bool SyncCommand::Execute() { + if (!GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) && !GitAdminDir().IsBareRepo(g_Git.m_CurrentDir)) { + CMessageBox::Show(hwndExplorer, IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR); + return false; + } + bool bRet = false; CSyncDlg dlg; if(dlg.DoModal() == IDOK) -- 2.11.4.GIT