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.
20 #include "SVNFetchCommand.h"
22 #include "SysProgressDlg.h"
23 #include "ProgressDlg.h"
24 #include "MessageBox.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(':'));
40 if(out
.Left(5) == _T(":refs"))
44 out
=out
.Tokenize(_T("\n"),start
);
48 CMessageBox::Show(NULL
, _T("Found no SVN remote."), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
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
);
59 CProgressDlg progress
;
60 progress
.m_GitCmd
=_T("git.exe svn fetch");
62 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
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
);
73 if (upstreamOldHash
== upstreamNewHash
)
76 postCmdList
.push_back(PostCmd(_T("Fetched Diff"), [&]
79 dlg
.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), upstreamOldHash
.ToString() + _T("..") + upstreamNewHash
.ToString(), 0);
83 postCmdList
.push_back(PostCmd(_T("Fetched Log"), [&]
86 dlg
.SetDiff(NULL
, upstreamNewHash
.ToString(), upstreamOldHash
.ToString());
91 INT_PTR userResponse
= progress
.DoModal();
92 ::DeleteFile(g_Git
.m_CurrentDir
+ _T("\\sys$command"));
94 return userResponse
== IDOK
;