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.
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 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(':'));
44 if(out
.Left(5) == _T(":refs"))
48 out
=out
.Tokenize(_T("\n"),start
);
52 CMessageBox::Show(NULL
, _T("Found no SVN remote."), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
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
);
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
);
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
);
85 dlg
.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), upstreamOldHash
, upstreamNewHash
, 0);
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
);
99 dlg
.SetDiff(NULL
, upstreamNewHash
.ToString(), upstreamOldHash
.ToString());