Make more use of theApp.m_pMainWnd
[TortoiseGit.git] / src / TortoiseProc / Commands / SVNFetchCommand.cpp
blob1c2feb322f16508ac3c216969d9d2207b22cb40b
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016, 2018 - 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 "Git.h"
25 #include "LogDlg.h"
26 #include "FileDiffDlg.h"
28 bool SVNFetchCommand::Execute()
30 CString out, err;
31 if (!g_Git.Run(L"git.exe config svn-remote.svn.fetch", &out, &err, CP_UTF8))
33 int start = out.Find(L':');
34 if( start >=0 )
35 out=out.Mid(start);
37 if (CStringUtils::StartsWith(out, L":refs"))
38 out=out.Mid(6);
40 start = 0;
41 out = out.Tokenize(L"\n", start);
43 else
45 MessageBox(GetExplorerHWND(), L"Found no SVN remote.", L"TortoiseGit", MB_OK | MB_ICONERROR);
46 return false;
49 CGitHash upstreamOldHash;
50 if (g_Git.GetHash(upstreamOldHash, out))
52 MessageBox(GetExplorerHWND(), g_Git.GetGitLastErr(L"Could not get upstream hash."), L"TortoiseGit", MB_ICONERROR);
53 return false;
56 CProgressDlg progress;
57 theApp.m_pMainWnd = &progress;
58 progress.m_GitCmd = L"git.exe svn fetch";
60 CGitHash upstreamNewHash; // declare outside lambda, because it is captured by reference
61 progress.m_PostCmdCallback = [&](DWORD status, PostCmdList& postCmdList)
63 if (status)
64 return;
66 if (g_Git.GetHash(upstreamNewHash, out))
68 MessageBox(GetExplorerHWND(), g_Git.GetGitLastErr(L"Could not get upstream hash after fetching."), L"TortoiseGit", MB_ICONERROR);
69 return;
71 if (upstreamOldHash == upstreamNewHash)
72 return;
74 postCmdList.emplace_back(IDI_DIFF, L"Fetched Diff", [&]
76 CFileDiffDlg dlg;
77 theApp.m_pMainWnd = &dlg;
78 dlg.SetDiff(nullptr, upstreamOldHash.ToString(), upstreamNewHash.ToString());
79 dlg.DoModal();
80 });
82 postCmdList.emplace_back(IDI_LOG, L"Fetched Log", [&]
84 CLogDlg dlg;
85 theApp.m_pMainWnd = &dlg;
86 dlg.SetParams(CTGitPath(L""), CTGitPath(L""), L"", upstreamOldHash.ToString() + L".." + upstreamNewHash.ToString(), 0);
87 dlg.DoModal();
88 });
91 return progress.DoModal() == IDOK;