Use lambda methods for task actions
[TortoiseGit.git] / src / TortoiseProc / Commands / SVNFetchCommand.cpp
blobe9d1931c42db6af14d54cd619f1520f320f178f7
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "SVNFetchCommand.h"
22 #include "SysProgressDlg.h"
23 #include "ProgressDlg.h"
24 #include "MessageBox.h"
25 #include "Git.h"
26 #include "LogDlg.h"
27 #include "FileDiffDlg.h"
29 bool SVNFetchCommand::Execute()
31 CString cmd, out, err;
32 cmd = _T("git.exe config svn-remote.svn.fetch");
34 if (!g_Git.Run(cmd, &out, &err, CP_UTF8))
36 int start = out.Find(_T(':'));
37 if( start >=0 )
38 out=out.Mid(start);
40 if(out.Left(5) == _T(":refs"))
41 out=out.Mid(6);
43 start = 0;
44 out=out.Tokenize(_T("\n"),start);
46 else
48 CMessageBox::Show(NULL, _T("Found no SVN remote."), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
49 return false;
52 CGitHash upstreamOldHash;
53 if (g_Git.GetHash(upstreamOldHash, out))
55 MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get upstream hash.")), _T("TortoiseGit"), MB_ICONERROR);
56 return false;
59 CProgressDlg progress;
60 progress.m_GitCmd=_T("git.exe svn fetch");
62 progress.m_PostCmdCallback = [&](DWORD status, PostCmdList& postCmdList)
64 if (status)
65 return;
67 CGitHash upstreamNewHash;
68 if (g_Git.GetHash(upstreamNewHash, out))
70 MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get upstream hash after fetching.")), _T("TortoiseGit"), MB_ICONERROR);
71 return;
73 if (upstreamOldHash == upstreamNewHash)
74 return;
76 postCmdList.push_back(PostCmd(_T("Fetched Diff"), [&]
78 CLogDlg dlg;
79 dlg.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), upstreamOldHash.ToString() + _T("..") + upstreamNewHash.ToString(), 0);
80 dlg.DoModal();
81 }));
83 postCmdList.push_back(PostCmd(_T("Fetched Log"), [&]
85 CFileDiffDlg dlg;
86 dlg.SetDiff(NULL, upstreamNewHash.ToString(), upstreamOldHash.ToString());
87 dlg.DoModal();
88 }));
91 INT_PTR userResponse = progress.DoModal();
92 ::DeleteFile(g_Git.m_CurrentDir + _T("\\sys$command"));
94 return userResponse == IDOK;