Fix compilation warnings
[TortoiseGit.git] / src / TortoiseProc / Commands / PullCommand.cpp
blob076d9cacc0f3c4d024ea744c9c5229a14bc9d651
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.
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 "ChangedDlg.h"
35 bool PullCommand::Execute()
37 if (!GitAdminDir().HasAdminDir(g_Git.m_CurrentDir)) {
38 CMessageBox::Show(hwndExplorer, IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR);
39 return false;
42 CPullFetchDlg dlg;
43 dlg.m_IsPull=TRUE;
44 if(dlg.DoModal()==IDOK)
46 CString url;
47 url=dlg.m_RemoteURL;
49 if(dlg.m_bAutoLoad)
51 CAppUtils::LaunchPAgent(NULL,&dlg.m_RemoteURL);
54 CString cmd;
55 CGitHash hashOld;
56 if (g_Git.GetHash(hashOld, _T("HEAD")))
58 MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR);
59 return false;
61 CString cmdRebase;
62 if(dlg.m_bRebase)
63 cmdRebase = "--rebase ";
65 CString noff;
66 CString ffonly;
67 CString squash;
68 CString nocommit;
69 CString notags;
70 if (!dlg.m_bFetchTags)
71 notags = _T("--no-tags");
72 if(dlg.m_bNoFF)
73 noff=_T("--no-ff");
75 if (dlg.m_bFFonly)
76 ffonly = _T("--ff-only");
78 if(dlg.m_bSquash)
79 squash=_T("--squash");
81 if(dlg.m_bNoCommit)
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)
108 CChangedDlg dlg;
109 dlg.m_pathList.AddPath(CTGitPath());
110 dlg.DoModal();
112 return FALSE;
115 CGitHash hashNew;
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);
119 return FALSE;
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);
128 return TRUE;
131 CFileDiffDlg dlg;
132 dlg.SetDiff(NULL, hashNew.ToString(), hashOld.ToString());
133 dlg.DoModal();
135 return TRUE;
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);
143 return TRUE;
147 CLogDlg dlg;
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));
155 dlg.DoModal();
159 else if (ret == IDC_PROGRESS_BUTTON1 + 2 && gitPath.HasSubmodules())
161 CString sCmd;
162 sCmd.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git.m_CurrentDir);
164 CAppUtils::RunTortoiseGitProc(sCmd);
168 return FALSE;