some minor cleanup
[TortoiseGit.git] / src / TortoiseProc / Commands / PullCommand.cpp
blobf9bc976187b02f0bffbf6acd8861be5132bba21d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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.
20 #include "StdAfx.h"
21 #include "PullCommand.h"
23 //#include "SVNProgressDlg.h"
24 #include "StringUtils.h"
25 #include "Hooks.h"
26 #include "MessageBox.h"
27 #include "PullFetchDlg.h"
28 #include "ProgressDlg.h"
29 #include "FileDiffDlg.h"
30 #include "AppUtils.h"
31 #include "LogDlg.h"
32 #include "AppUtils.h"
33 #include "PathUtils.h"
35 bool PullCommand::Execute()
37 CPullFetchDlg dlg;
38 dlg.m_IsPull=TRUE;
39 if(dlg.DoModal()==IDOK)
41 CString url;
42 url=dlg.m_RemoteURL;
44 if(dlg.m_bAutoLoad)
46 CAppUtils::LaunchPAgent(NULL,&dlg.m_RemoteURL);
49 CString cmd;
50 CString hashOld = g_Git.GetHash(L"HEAD");
51 CString cmdRebase;
52 if(dlg.m_bRebase)
53 cmdRebase = "--rebase ";
55 CString noff;
56 CString ffonly;
57 CString squash;
58 CString nocommit;
59 if(dlg.m_bNoFF)
60 noff=_T("--no-ff");
62 if (dlg.m_bFFonly)
63 ffonly = _T("--ff-only");
65 if(dlg.m_bSquash)
66 squash=_T("--squash");
68 if(dlg.m_bNoCommit)
69 nocommit=_T("--no-commit");
71 int ver = CAppUtils::GetMsysgitVersion();
73 if(ver >= 0x01070203) //above 1.7.0.2
74 cmdRebase += _T("--progress ");
76 cmd.Format(_T("git.exe pull -v %s %s %s %s %s \"%s\" %s"), cmdRebase, noff, ffonly, squash, nocommit, url, dlg.m_RemoteBranchName);
77 CProgressDlg progress;
78 progress.m_GitCmd = cmd;
79 progress.m_PostCmdList.Add(_T("Pulled Diff"));
80 progress.m_PostCmdList.Add(_T("Pulled Log"));
82 CTGitPath gitPath = g_Git.m_CurrentDir;
83 if (gitPath.HasSubmodules())
84 progress.m_PostCmdList.Add(_T("Update submodules"));
86 //progress.m_PostCmdList.Add(_T("Show Conflict"));
88 if (parser.HasVal(_T("closeonend")))
89 progress.m_bAutoCloseOnSuccess = !!parser.GetLongVal(_T("closeonend"));
91 int ret = progress.DoModal();
93 CString hashNew = g_Git.GetHash(L"HEAD");
95 if( ret == IDC_PROGRESS_BUTTON1)
97 if(hashOld == hashNew)
99 if(progress.m_GitStatus == 0)
100 CMessageBox::Show(NULL, L"Already up to date.", L"Pull", MB_OK | MB_ICONINFORMATION);
101 return TRUE;
104 CFileDiffDlg dlg;
105 dlg.SetDiff(NULL, hashNew, hashOld);
106 dlg.DoModal();
108 return TRUE;
110 else if ( ret == IDC_PROGRESS_BUTTON1 +1 )
112 if(hashOld == hashNew)
114 if(progress.m_GitStatus == 0)
115 CMessageBox::Show(NULL, L"Already up to date.", L"Pull", MB_OK | MB_ICONINFORMATION);
116 return TRUE;
120 CLogDlg dlg;
122 //dlg.SetParams(cmdLinePath);
123 dlg.SetParams(CTGitPath(_T("")),CTGitPath(_T("")),_T(""), hashOld, hashNew, 0);
124 // dlg.SetIncludeMerge(!!parser.HasKey(_T("merge")));
125 // val = parser.GetVal(_T("propspath"));
126 // if (!val.IsEmpty())
127 // dlg.SetProjectPropertiesPath(CTSVNPath(val));
128 dlg.DoModal();
132 else if (ret == IDC_PROGRESS_BUTTON1 + 2 && gitPath.HasSubmodules())
134 CString sCmd;
135 sCmd.Format(_T("\"%s\" /command:subupdate /bkpath:\"%s\""), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)g_Git.m_CurrentDir);
137 CAppUtils::LaunchApplication(sCmd, NULL, false);
140 #if 0
141 CCloneDlg dlg;
142 dlg.m_Directory=this->orgCmdLinePath.GetWinPathString();
143 if(dlg.DoModal()==IDOK)
145 CString dir=dlg.m_Directory;
146 CString url=dlg.m_URL;
147 CString cmd;
148 cmd.Format(_T("git.exe clone %s %s"),
149 url,
150 dir);
151 CProgressDlg progress;
152 progress.m_GitCmd=cmd;
153 if(progress.DoModal()==IDOK)
154 return TRUE;
157 #endif
158 return FALSE;