Fixed issue #1264: TortoiseProc might crash if commands are executed w/o a working...
[TortoiseGit.git] / src / TortoiseProc / Commands / PullCommand.cpp
blobd0fa38db01714db80a9b13f5f660d9bd39002d0d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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 CString hashOld;
56 try
58 hashOld = g_Git.GetHash(_T("HEAD"));
60 catch (char* msg)
62 CString err(msg);
63 MessageBox(NULL, _T("Could not get HEAD hash.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
64 ExitProcess(1);
66 CString cmdRebase;
67 if(dlg.m_bRebase)
68 cmdRebase = "--rebase ";
70 CString noff;
71 CString ffonly;
72 CString squash;
73 CString nocommit;
74 if(dlg.m_bNoFF)
75 noff=_T("--no-ff");
77 if (dlg.m_bFFonly)
78 ffonly = _T("--ff-only");
80 if(dlg.m_bSquash)
81 squash=_T("--squash");
83 if(dlg.m_bNoCommit)
84 nocommit=_T("--no-commit");
86 int ver = CAppUtils::GetMsysgitVersion();
88 if(ver >= 0x01070203) //above 1.7.0.2
89 cmdRebase += _T("--progress ");
91 cmd.Format(_T("git.exe pull -v %s %s %s %s %s \"%s\" %s"), cmdRebase, noff, ffonly, squash, nocommit, url, dlg.m_RemoteBranchName);
92 CProgressDlg progress;
93 progress.m_GitCmd = cmd;
94 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_DIFFS)));
95 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_LOG)));
97 CTGitPath gitPath = g_Git.m_CurrentDir;
98 if (gitPath.HasSubmodules())
99 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE)));
101 //progress.m_PostCmdList.Add(_T("Show Conflict"));
103 if (parser.HasVal(_T("closeonend")))
104 progress.m_bAutoCloseOnSuccess = !!parser.GetLongVal(_T("closeonend"));
106 int ret = progress.DoModal();
108 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)
110 CChangedDlg dlg;
111 dlg.m_pathList.AddPath(CTGitPath());
112 dlg.DoModal();
114 return FALSE;
117 CString hashNew = g_Git.GetHash(L"HEAD");
119 if( ret == IDC_PROGRESS_BUTTON1)
121 if(hashOld == hashNew)
123 if(progress.m_GitStatus == 0)
124 CMessageBox::Show(NULL, IDS_UPTODATE, IDS_APPNAME, MB_OK | MB_ICONINFORMATION);
125 return TRUE;
128 CFileDiffDlg dlg;
129 dlg.SetDiff(NULL, hashNew, hashOld);
130 dlg.DoModal();
132 return TRUE;
134 else if ( ret == IDC_PROGRESS_BUTTON1 +1 )
136 if(hashOld == hashNew)
138 if(progress.m_GitStatus == 0)
139 CMessageBox::Show(NULL, IDS_UPTODATE, IDS_APPNAME, MB_OK | MB_ICONINFORMATION);
140 return TRUE;
144 CLogDlg dlg;
146 //dlg.SetParams(cmdLinePath);
147 dlg.SetParams(CTGitPath(_T("")),CTGitPath(_T("")),_T(""), hashOld, hashNew, 0);
148 // dlg.SetIncludeMerge(!!parser.HasKey(_T("merge")));
149 // val = parser.GetVal(_T("propspath"));
150 // if (!val.IsEmpty())
151 // dlg.SetProjectPropertiesPath(CTSVNPath(val));
152 dlg.DoModal();
156 else if (ret == IDC_PROGRESS_BUTTON1 + 2 && gitPath.HasSubmodules())
158 CString sCmd;
159 sCmd.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git.m_CurrentDir);
161 CAppUtils::RunTortoiseProc(sCmd);
165 return FALSE;