Fix compilation warnings
[TortoiseGit.git] / src / TortoiseProc / Commands / SVNFetchCommand.cpp
blob7bf637053569972c2bdd05426d1cbe92802459c3
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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 bool autoClose = false;
32 if (parser.HasVal(_T("closeonend")))
33 autoClose = !!parser.GetLongVal(_T("closeonend"));
35 CString cmd, out, err;
36 cmd = _T("git.exe config svn-remote.svn.fetch");
38 if (!g_Git.Run(cmd, &out, &err, CP_UTF8))
40 int start = out.Find(_T(':'));
41 if( start >=0 )
42 out=out.Mid(start);
44 if(out.Left(5) == _T(":refs"))
45 out=out.Mid(6);
47 start = 0;
48 out=out.Tokenize(_T("\n"),start);
50 else
52 CMessageBox::Show(NULL, _T("Found no SVN remote."), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
53 return false;
56 CGitHash upstreamOldHash, upstreamNewHash;
57 if (g_Git.GetHash(upstreamOldHash, out))
59 MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get upstream hash.")), _T("TortoiseGit"), MB_ICONERROR);
60 return false;
63 CProgressDlg progress;
64 progress.m_GitCmd=_T("git.exe svn fetch");
65 progress.m_PostCmdList.Add(_T("Fetched Diff"));
66 progress.m_PostCmdList.Add(_T("Fetched Log"));
67 progress.m_bAutoCloseOnSuccess = autoClose;
69 INT_PTR userResponse = progress.DoModal();
70 if (g_Git.GetHash(upstreamNewHash, out))
72 MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get upstream hash after fetching.")), _T("TortoiseGit"), MB_ICONERROR);
73 return false;
75 if (userResponse == IDC_PROGRESS_BUTTON1)
77 if (upstreamOldHash == upstreamNewHash)
79 if (progress.m_GitStatus == 0)
80 CMessageBox::Show(NULL, L"No new revisions fetched.", L"TortoiseGit Fetch", MB_OK | MB_ICONINFORMATION);
81 return true;
84 CLogDlg dlg;
85 dlg.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), upstreamOldHash.ToString() + _T("..") + upstreamNewHash.ToString(), 0);
86 dlg.DoModal();
87 return true;
89 else if (userResponse == IDC_PROGRESS_BUTTON1 + 1)
91 if (upstreamOldHash == upstreamNewHash)
93 if (progress.m_GitStatus == 0)
94 CMessageBox::Show(NULL, L"No new revisions fetched.", L"TortoiseGit Fetch", MB_OK | MB_ICONINFORMATION);
95 return true;
98 CFileDiffDlg dlg;
99 dlg.SetDiff(NULL, upstreamNewHash.ToString(), upstreamOldHash.ToString());
100 dlg.DoModal();
101 return true;
103 else
104 return false;