Fix typos
[TortoiseGit.git] / src / TortoiseProc / Commands / SVNFetchCommand.cpp
blobd7f9cba3fb0ec0b4d9b27cfc26204cddd4be572e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016, 2018-2020 - 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 "AppUtils.h"
27 bool SVNFetchCommand::Execute()
29 CString out, err;
30 if (!g_Git.Run(L"git.exe config svn-remote.svn.fetch", &out, &err, CP_UTF8))
32 int start = out.Find(L':');
33 if( start >=0 )
34 out=out.Mid(start);
36 if (CStringUtils::StartsWith(out, L":refs"))
37 out = out.Mid(static_cast<int>(wcslen(L":refs")) + 1);
39 start = 0;
40 out = out.Tokenize(L"\n", start);
42 else
44 MessageBox(GetExplorerHWND(), L"Found no SVN remote.", L"TortoiseGit", MB_OK | MB_ICONERROR);
45 return false;
48 CGitHash upstreamOldHash;
49 if (g_Git.GetHash(upstreamOldHash, out))
51 MessageBox(GetExplorerHWND(), g_Git.GetGitLastErr(L"Could not get upstream hash."), L"TortoiseGit", MB_ICONERROR);
52 return false;
55 CProgressDlg progress;
56 progress.m_GitCmd = L"git.exe svn fetch";
58 CGitHash upstreamNewHash; // declare outside lambda, because it is captured by reference
59 progress.m_PostCmdCallback = [&](DWORD status, PostCmdList& postCmdList)
61 if (status)
62 return;
64 if (g_Git.GetHash(upstreamNewHash, out))
66 MessageBox(GetExplorerHWND(), g_Git.GetGitLastErr(L"Could not get upstream hash after fetching."), L"TortoiseGit", MB_ICONERROR);
67 return;
69 if (upstreamOldHash == upstreamNewHash)
70 return;
72 postCmdList.emplace_back(IDI_DIFF, IDS_PROC_PULL_DIFFS, [&]
74 CString sCmd;
75 sCmd.Format(L"/command:showcompare /path:\"%s\" /revision1:%s /revision2:%s", static_cast<LPCWSTR>(g_Git.m_CurrentDir), static_cast<LPCWSTR>(upstreamOldHash.ToString()), static_cast<LPCWSTR>(upstreamNewHash.ToString()));
76 CAppUtils::RunTortoiseGitProc(sCmd);
77 });
79 postCmdList.emplace_back(IDI_LOG, IDS_PROC_PULL_LOG, [&]
81 CString sCmd;
82 sCmd.Format(L"/command:log /path:\"%s\" /range:%s", static_cast<LPCWSTR>(g_Git.m_CurrentDir), static_cast<LPCWSTR>(upstreamOldHash.ToString() + L".." + upstreamNewHash.ToString()));
83 CAppUtils::RunTortoiseGitProc(sCmd);
84 });
87 return progress.DoModal() == IDOK;