Skip to content

Commit

Permalink
Fixed issue #2376: Accidental stash-pops can so easily overwrite the …
Browse files Browse the repository at this point in the history
…uncommited working dir changes

Signed-off-by: Yue Lin Ho <b8732003@student.nsysu.edu.tw>
  • Loading branch information
YueLinHo committed Feb 10, 2015
1 parent 9e66601 commit 8065118
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Languages/Tortoise.pot
Original file line number Diff line number Diff line change
Expand Up @@ -9283,6 +9283,10 @@ msgstr ""
msgid "The working tree is not clean and contains unstaged changes.\nReview and commit the changes?"
msgstr ""

#. Resource IDs: (603)
msgid "The working tree is not clean!\nDo you want to stash pop/apply changes?"
msgstr ""

#. Resource IDs: (65535)
msgid "Their file:"
msgstr ""
Expand Down
1 change: 1 addition & 0 deletions src/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Released: unreleased
* Fixed issue #2388: See the exact time when the Relative time in log enabled
* Fixed issue #2346: Add drag'n'drop to "Apply patches" window
* Fixed issue #2357: Save the state of Search criteria checkboxes in Log dialog
* Fixed issue #2376: Accidental stash-pops can so easily overwrite the uncommited working dir changes

== Bug Fixes ==
* Fixed issue #2359: Selected files counter not updated after revert
Expand Down
1 change: 1 addition & 0 deletions src/Resources/TortoiseProcENG.rc
Original file line number Diff line number Diff line change
Expand Up @@ -4257,6 +4257,7 @@ BEGIN
IDS_MENU_APPLY "Apply Patch..."
IDS_MENU_SENDMAIL "Send Mail..."
IDS_ERROR_NOREF "No reference found"
IDS_WARN_NOCLEAN "The working tree is not clean!\nDo you want to stash pop/apply changes?"
IDS_ERROR_NOCLEAN_STASH "The current working tree is not clean.\nDo you want to stash the changes?"
IDS_ERROR_NOTHING_COMMIT "Nothing to commit"
IDS_COMMIT_FINISH "Commit Finish"
Expand Down
17 changes: 17 additions & 0 deletions src/TortoiseProc/AppUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ bool CAppUtils::StashSave(const CString& msg, bool showPull, bool pullShowPush,

bool CAppUtils::StashApply(CString ref, bool showChanges /* true */)
{
if (!CheckCleanWorkTreeAndWarn())
return false;

CString cmd,out;
cmd = _T("git.exe stash apply ");
if (ref.Find(_T("refs/")) == 0)
Expand Down Expand Up @@ -210,6 +213,9 @@ bool CAppUtils::StashApply(CString ref, bool showChanges /* true */)

bool CAppUtils::StashPop(bool showChanges /* true */)
{
if (!CheckCleanWorkTreeAndWarn())
return false;

CString cmd,out;
cmd=_T("git.exe stash pop ");

Expand Down Expand Up @@ -256,6 +262,17 @@ bool CAppUtils::StashPop(bool showChanges /* true */)
return false;
}

bool CAppUtils::CheckCleanWorkTreeAndWarn()
{
if (g_Git.CheckCleanWorkTree())
return true;

if (CMessageBox::Show(nullptr, IDS_WARN_NOCLEAN, IDS_APPNAME, 1, IDI_WARNING, IDS_MSGBOX_ABORT, IDS_IGNOREBUTTON) == 2)
return true;

return false;
}

BOOL CAppUtils::StartExtMerge(
const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
const CString& basename, const CString& theirname, const CString& yourname, const CString& mergedname, bool bReadOnly,
Expand Down
2 changes: 2 additions & 0 deletions src/TortoiseProc/AppUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class CAppUtils : public CCommonAppUtils
static bool StashApply(CString ref, bool showChanges = true);
static bool StashPop(bool showChanges = true);

static bool CheckCleanWorkTreeAndWarn();

static bool IsSSHPutty();

static bool LaunchRemoteSetting();
Expand Down
10 changes: 9 additions & 1 deletion src/TortoiseProc/SyncDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,14 @@ void CSyncDlg::OnBnClickedButtonSubmodule()

void CSyncDlg::OnBnClickedButtonStash()
{
INT_PTR curEntry = m_ctrlStash.GetCurrentEntry();

if (curEntry == 1 || curEntry == 2)
{
if (!CAppUtils::CheckCleanWorkTreeAndWarn())
return;
}

UpdateData();
UpdateCombox();
m_ctrlCmdOut.SetWindowTextW(_T(""));
Expand All @@ -1530,7 +1538,7 @@ void CSyncDlg::OnBnClickedButtonStash()
m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT -1, false);

CString cmd;
switch (m_ctrlStash.GetCurrentEntry())
switch (curEntry)
{
case 0:
cmd = _T("git.exe stash save");
Expand Down
1 change: 1 addition & 0 deletions src/TortoiseProc/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,7 @@
#define IDS_MENU_APPLY 9635
#define IDS_MENU_SENDMAIL 9636
#define IDS_ERROR_NOREF 9638
#define IDS_WARN_NOCLEAN 9640
#define IDS_ERROR_NOCLEAN_STASH 9641
#define IDS_ERROR_NOTHING_COMMIT 9642
#define IDS_COMMIT_FINISH 9643
Expand Down

0 comments on commit 8065118

Please sign in to comment.