1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2007-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "PullCommand.h"
23 //#include "SVNProgressDlg.h"
24 #include "StringUtils.h"
26 #include "MessageBox.h"
27 #include "PullFetchDlg.h"
28 #include "ProgressDlg.h"
29 #include "FileDiffDlg.h"
33 #include "ChangedDlg.h"
35 bool PullCommand::Execute()
37 if (!GitAdminDir().HasAdminDir(g_Git
.m_CurrentDir
)) {
38 CMessageBox::Show(hwndExplorer
, IDS_NOWORKINGCOPY
, IDS_APPNAME
, MB_ICONERROR
);
44 if(dlg
.DoModal()==IDOK
)
51 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_RemoteURL
);
56 if (g_Git
.GetHash(hashOld
, _T("HEAD")))
58 MessageBox(hwndExplorer
, g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
63 cmdRebase
= "--rebase ";
70 if (!dlg
.m_bFetchTags
)
71 notags
= _T("--no-tags");
76 ffonly
= _T("--ff-only");
79 squash
=_T("--squash");
82 nocommit
=_T("--no-commit");
84 int ver
= CAppUtils::GetMsysgitVersion();
86 if(ver
>= 0x01070203) //above 1.7.0.2
87 cmdRebase
+= _T("--progress ");
89 cmd
.Format(_T("git.exe pull -v %s %s %s %s %s %s \"%s\" %s"), cmdRebase
, noff
, ffonly
, squash
, nocommit
, notags
, url
, dlg
.m_RemoteBranchName
);
90 CProgressDlg progress
;
91 progress
.m_GitCmd
= cmd
;
92 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_DIFFS
)));
93 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_LOG
)));
95 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
96 if (gitPath
.HasSubmodules())
97 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
99 //progress.m_PostCmdList.Add(_T("Show Conflict"));
101 if (parser
.HasVal(_T("closeonend")))
102 progress
.m_bAutoCloseOnSuccess
= !!parser
.GetLongVal(_T("closeonend"));
104 INT_PTR ret
= progress
.DoModal();
106 if (ret
== IDOK
&& progress
.m_GitStatus
== 1 && progress
.m_LogText
.Find(_T("CONFLICT")) >= 0 && CMessageBox::Show(NULL
, IDS_SEECHANGES
, IDS_APPNAME
, MB_YESNO
| MB_ICONINFORMATION
) == IDYES
)
109 dlg
.m_pathList
.AddPath(CTGitPath());
116 if (g_Git
.GetHash(hashNew
, L
"HEAD"))
118 MessageBox(hwndExplorer
, g_Git
.GetGitLastErr(_T("Could not get HEAD hash after pulling.")), _T("TortoiseGit"), MB_ICONERROR
);
122 if( ret
== IDC_PROGRESS_BUTTON1
)
124 if(hashOld
== hashNew
)
126 if(progress
.m_GitStatus
== 0)
127 CMessageBox::Show(NULL
, IDS_UPTODATE
, IDS_APPNAME
, MB_OK
| MB_ICONINFORMATION
);
132 dlg
.SetDiff(NULL
, hashNew
.ToString(), hashOld
.ToString());
137 else if ( ret
== IDC_PROGRESS_BUTTON1
+1 )
139 if(hashOld
== hashNew
)
141 if(progress
.m_GitStatus
== 0)
142 CMessageBox::Show(NULL
, IDS_UPTODATE
, IDS_APPNAME
, MB_OK
| MB_ICONINFORMATION
);
149 //dlg.SetParams(cmdLinePath);
150 dlg
.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), hashOld
.ToString() + _T("..") + hashNew
.ToString(), 0);
151 // dlg.SetIncludeMerge(!!parser.HasKey(_T("merge")));
152 // val = parser.GetVal(_T("propspath"));
153 // if (!val.IsEmpty())
154 // dlg.SetProjectPropertiesPath(CTSVNPath(val));
159 else if (ret
== IDC_PROGRESS_BUTTON1
+ 2 && gitPath
.HasSubmodules())
162 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
164 CAppUtils::RunTortoiseGitProc(sCmd
);