Fixed issue #972: Add "fast forward only" checkbox in pull dialog
[TortoiseGit.git] / src / TortoiseProc / Commands / PullCommand.cpp
blob4698451f308ea646b681aa518434dc95ed7916b3
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 "ChangedDlg.h"
33 #include "AppUtils.h"
34 #include "PathUtils.h"
36 bool PullCommand::Execute()
38 CPullFetchDlg dlg;
39 dlg.m_IsPull=TRUE;
40 if(dlg.DoModal()==IDOK)
42 CString url;
43 url=dlg.m_RemoteURL;
45 if(dlg.m_bAutoLoad)
47 CAppUtils::LaunchPAgent(NULL,&dlg.m_RemoteURL);
50 CString cmd;
51 CString hashOld = g_Git.GetHash(L"HEAD");
52 CString cmdRebase;
53 if(dlg.m_bRebase)
54 cmdRebase = "--rebase ";
56 CString noff;
57 CString ffonly;
58 CString squash;
59 CString nocommit;
60 if(dlg.m_bNoFF)
61 noff=_T("--no-ff");
63 if (dlg.m_bFFonly)
64 ffonly = _T("--ff-only");
66 if(dlg.m_bSquash)
67 squash=_T("--squash");
69 if(dlg.m_bNoCommit)
70 nocommit=_T("--no-commit");
72 int ver = CAppUtils::GetMsysgitVersion();
74 if(ver >= 0x01070203) //above 1.7.0.2
75 cmdRebase += _T("--progress ");
77 cmd.Format(_T("git.exe pull -v %s %s %s %s %s \"%s\" %s"), cmdRebase, noff, ffonly, squash, nocommit, url, dlg.m_RemoteBranchName);
78 CProgressDlg progress;
79 progress.m_GitCmd = cmd;
80 progress.m_PostCmdList.Add(_T("Pulled Diff"));
81 progress.m_PostCmdList.Add(_T("Pulled Log"));
83 CTGitPath gitPath = g_Git.m_CurrentDir;
84 if (gitPath.HasSubmodules())
85 progress.m_PostCmdList.Add(_T("Update submodules"));
87 //progress.m_PostCmdList.Add(_T("Show Conflict"));
89 if (parser.HasVal(_T("closeonend")))
90 progress.m_bAutoCloseOnSuccess = !!parser.GetLongVal(_T("closeonend"));
92 int ret = progress.DoModal();
94 CString hashNew = g_Git.GetHash(L"HEAD");
96 if( ret == IDC_PROGRESS_BUTTON1)
98 if(hashOld == hashNew)
100 if(progress.m_GitStatus == 0)
101 CMessageBox::Show(NULL, L"Already up to date.", L"Pull", MB_OK | MB_ICONINFORMATION);
102 return TRUE;
105 CFileDiffDlg dlg;
106 dlg.SetDiff(NULL, hashNew, hashOld);
107 dlg.DoModal();
109 return TRUE;
111 else if ( ret == IDC_PROGRESS_BUTTON1 +1 )
113 if(hashOld == hashNew)
115 if(progress.m_GitStatus == 0)
116 CMessageBox::Show(NULL, L"Already up to date.", L"Pull", MB_OK | MB_ICONINFORMATION);
117 return TRUE;
121 CLogDlg dlg;
123 //dlg.SetParams(cmdLinePath);
124 dlg.SetParams(CTGitPath(_T("")),CTGitPath(_T("")),_T(""), hashOld, hashNew, 0);
125 // dlg.SetIncludeMerge(!!parser.HasKey(_T("merge")));
126 // val = parser.GetVal(_T("propspath"));
127 // if (!val.IsEmpty())
128 // dlg.SetProjectPropertiesPath(CTSVNPath(val));
129 dlg.DoModal();
133 else if (ret == IDC_PROGRESS_BUTTON1 + 2 && gitPath.HasSubmodules())
135 CString sCmd;
136 sCmd.Format(_T("\"%s\" /command:subupdate /bkpath:\"%s\""), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)g_Git.m_CurrentDir);
138 CAppUtils::LaunchApplication(sCmd, NULL, false);
141 #if 0
142 CCloneDlg dlg;
143 dlg.m_Directory=this->orgCmdLinePath.GetWinPathString();
144 if(dlg.DoModal()==IDOK)
146 CString dir=dlg.m_Directory;
147 CString url=dlg.m_URL;
148 CString cmd;
149 cmd.Format(_T("git.exe clone %s %s"),
150 url,
151 dir);
152 CProgressDlg progress;
153 progress.m_GitCmd=cmd;
154 if(progress.DoModal()==IDOK)
155 return TRUE;
158 #endif
159 return FALSE;