OSDN Git Service

RebaseDlg: Squash provide chance to modified last message.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RebaseDlg.cpp
1 // RebaseDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "RebaseDlg.h"\r
7 #include "AppUtils.h"\r
8 #include "MessageBox.h"\r
9 #include "UnicodeUtils.h"\r
10 // CRebaseDlg dialog\r
11 \r
12 IMPLEMENT_DYNAMIC(CRebaseDlg, CResizableStandAloneDialog)\r
13 \r
14 CRebaseDlg::CRebaseDlg(CWnd* pParent /*=NULL*/)\r
15         : CResizableStandAloneDialog(CRebaseDlg::IDD, pParent)\r
16     , m_bPickAll(FALSE)\r
17     , m_bSquashAll(FALSE)\r
18     , m_bEditAll(FALSE)\r
19 {\r
20         m_RebaseStage=CHOOSE_BRANCH;\r
21         m_CurrentRebaseIndex=-1;\r
22         m_bThreadRunning =FALSE;\r
23 }\r
24 \r
25 CRebaseDlg::~CRebaseDlg()\r
26 {\r
27 }\r
28 \r
29 void CRebaseDlg::DoDataExchange(CDataExchange* pDX)\r
30 {\r
31     CDialog::DoDataExchange(pDX);\r
32     DDX_Control(pDX, IDC_REBASE_PROGRESS, m_ProgressBar);\r
33     DDX_Control(pDX, IDC_STATUS_STATIC, m_CtrlStatusText);\r
34     DDX_Check(pDX, IDC_PICK_ALL, m_bPickAll);\r
35     DDX_Check(pDX, IDC_SQUASH_ALL, m_bSquashAll);\r
36     DDX_Check(pDX, IDC_EDIT_ALL, m_bEditAll);\r
37         DDX_Control(pDX, IDC_REBASE_SPLIT, m_wndSplitter);\r
38         DDX_Control(pDX,IDC_COMMIT_LIST,m_CommitList);\r
39         DDX_Control(pDX,IDC_REBASE_COMBOXEX_BRANCH, this->m_BranchCtrl);\r
40         DDX_Control(pDX,IDC_REBASE_COMBOXEX_UPSTREAM,   this->m_UpstreamCtrl);\r
41 \r
42 }\r
43 \r
44 \r
45 BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog)\r
46     ON_BN_CLICKED(IDC_PICK_ALL, &CRebaseDlg::OnBnClickedPickAll)\r
47     ON_BN_CLICKED(IDC_SQUASH_ALL, &CRebaseDlg::OnBnClickedSquashAll)\r
48     ON_BN_CLICKED(IDC_EDIT_ALL, &CRebaseDlg::OnBnClickedEditAll)\r
49     ON_BN_CLICKED(IDC_REBASE_SPLIT, &CRebaseDlg::OnBnClickedRebaseSplit)\r
50         ON_BN_CLICKED(IDC_REBASE_CONTINUE,OnBnClickedContinue)\r
51         ON_BN_CLICKED(IDC_REBASE_ABORT,  OnBnClickedAbort)\r
52         ON_WM_SIZE()\r
53         ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH,   &CRebaseDlg::OnCbnSelchangeBranch)\r
54         ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM, &CRebaseDlg::OnCbnSelchangeUpstream)\r
55         ON_MESSAGE(MSG_REBASE_UPDATE_UI, OnRebaseUpdateUI)\r
56 END_MESSAGE_MAP()\r
57 \r
58 void CRebaseDlg::AddRebaseAnchor()\r
59 {\r
60         AddAnchor(IDC_REBASE_TAB,TOP_LEFT,BOTTOM_RIGHT);\r
61         AddAnchor(IDC_COMMIT_LIST,TOP_LEFT, TOP_RIGHT);\r
62         AddAnchor(IDC_REBASE_SPLIT,TOP_LEFT, TOP_RIGHT);\r
63         AddAnchor(IDC_STATUS_STATIC, BOTTOM_LEFT,BOTTOM_RIGHT);\r
64         AddAnchor(IDC_REBASE_CONTINUE,BOTTOM_RIGHT);\r
65         AddAnchor(IDC_REBASE_ABORT, BOTTOM_RIGHT);\r
66         AddAnchor(IDC_REBASE_PROGRESS,BOTTOM_LEFT, BOTTOM_RIGHT);\r
67         AddAnchor(IDC_PICK_ALL,TOP_LEFT);\r
68         AddAnchor(IDC_SQUASH_ALL,TOP_LEFT);\r
69         AddAnchor(IDC_EDIT_ALL,TOP_LEFT);       \r
70         AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM,TOP_LEFT);\r
71         AddAnchor(IDC_REBASE_COMBOXEX_BRANCH,TOP_LEFT);\r
72         AddAnchor(IDC_REBASE_STATIC_UPSTREAM,TOP_LEFT);\r
73         AddAnchor(IDC_REBASE_STATIC_BRANCH,TOP_LEFT);\r
74         \r
75 }\r
76 \r
77 BOOL CRebaseDlg::OnInitDialog()\r
78 {\r
79         CResizableStandAloneDialog::OnInitDialog();\r
80 \r
81         CRect rectDummy;\r
82         //IDC_REBASE_DUMY_TAB\r
83         \r
84         GetClientRect(m_DlgOrigRect);\r
85         m_CommitList.GetClientRect(m_CommitListOrigRect);\r
86 \r
87         CWnd *pwnd=this->GetDlgItem(IDC_REBASE_DUMY_TAB);\r
88         pwnd->GetWindowRect(&rectDummy);\r
89 \r
90         rectDummy.top-=20;\r
91         rectDummy.bottom-=20;\r
92 \r
93         rectDummy.left-=5;\r
94         rectDummy.right-=5;\r
95         \r
96         if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_REBASE_TAB))\r
97         {\r
98                 TRACE0("Failed to create output tab window\n");\r
99                 return FALSE;      // fail to create\r
100         }\r
101         m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);\r
102         // Create output panes:\r
103         //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;\r
104         DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
105 \r
106         if (! this->m_FileListCtrl.Create(dwStyle,rectDummy,&this->m_ctrlTabCtrl,0) )\r
107         {\r
108                 TRACE0("Failed to create output windows\n");\r
109                 return FALSE;      // fail to create\r
110         }\r
111 \r
112         if( ! this->m_LogMessageCtrl.Create(_T("Scintilla"),_T("source"),0,rectDummy,&m_ctrlTabCtrl,0,0) )\r
113         {\r
114                 TRACE0("Failed to create log message control");\r
115                 return FALSE;\r
116         }\r
117         m_LogMessageCtrl.Init(0);\r
118 \r
119         dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;\r
120 \r
121         if (!m_wndOutputRebase.Create(_T("Scintilla"),_T("source"),0,rectDummy, &m_ctrlTabCtrl, 0,0) )\r
122         {\r
123                 TRACE0("Failed to create output windows\n");\r
124                 return -1;      // fail to create\r
125         }\r
126         m_wndOutputRebase.Init(0);\r
127         m_wndOutputRebase.Call(SCI_SETREADONLY, TRUE);\r
128         \r
129         m_tooltips.Create(this);\r
130 \r
131         m_FileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |IDS_STATUSLIST_COLADD|IDS_STATUSLIST_COLDEL , _T("RebaseDlg"),(SVNSLC_POPALL ^ SVNSLC_POPCOMMIT),false);\r
132 \r
133         m_ctrlTabCtrl.AddTab(&m_FileListCtrl,_T("Conflict File"));\r
134         m_ctrlTabCtrl.AddTab(&m_LogMessageCtrl,_T("Commit Message"),1);\r
135         m_ctrlTabCtrl.AddTab(&m_wndOutputRebase,_T("Log"),2);\r
136         AddRebaseAnchor();\r
137 \r
138 \r
139         EnableSaveRestore(_T("RebaseDlg"));\r
140 \r
141         DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));\r
142         RECT rcDlg, rcLogMsg, rcFileList;\r
143         GetClientRect(&rcDlg);\r
144         m_CommitList.GetWindowRect(&rcLogMsg);\r
145         ScreenToClient(&rcLogMsg);\r
146         this->m_ctrlTabCtrl.GetWindowRect(&rcFileList);\r
147         ScreenToClient(&rcFileList);\r
148         if (yPos)\r
149         {\r
150                 RECT rectSplitter;\r
151                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
152                 ScreenToClient(&rectSplitter);\r
153                 int delta = yPos - rectSplitter.top;\r
154                 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))\r
155                 {\r
156                         m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);\r
157                         DoSize(delta);\r
158                 }\r
159         }\r
160 \r
161         if( this->m_RebaseStage == CHOOSE_BRANCH)\r
162         {\r
163                 this->LoadBranchInfo();\r
164 \r
165         }else\r
166         {\r
167                 this->m_BranchCtrl.EnableWindow(FALSE);\r
168                 this->m_UpstreamCtrl.EnableWindow(FALSE);\r
169         }\r
170 \r
171         m_CommitList.m_IsIDReplaceAction = TRUE;\r
172 //      m_CommitList.m_IsOldFirst = TRUE;\r
173         m_CommitList.m_IsRebaseReplaceGraph = TRUE;\r
174 \r
175         m_CommitList.DeleteAllItems();\r
176         m_CommitList.InsertGitColumn();\r
177 \r
178         FetchLogList();\r
179         SetContinueButtonText();\r
180         this->SetControlEnable();\r
181         return TRUE;\r
182 }\r
183 // CRebaseDlg message handlers\r
184 \r
185 void CRebaseDlg::OnBnClickedPickAll()\r
186 {\r
187     // TODO: Add your control notification handler code here\r
188         this->UpdateData();\r
189         if(this->m_bPickAll)\r
190                 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_PICK);\r
191 \r
192         this->m_bEditAll=FALSE;\r
193         this->m_bSquashAll=FALSE;\r
194         this->UpdateData(FALSE);\r
195         \r
196 }\r
197 \r
198 void CRebaseDlg::OnBnClickedSquashAll()\r
199 {\r
200     // TODO: Add your control notification handler code here\r
201         this->UpdateData();\r
202         if(this->m_bSquashAll)\r
203                 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_SQUASH);\r
204 \r
205         this->m_bEditAll=FALSE;\r
206         this->m_bPickAll=FALSE;\r
207         this->UpdateData(FALSE);\r
208 \r
209 }\r
210 \r
211 void CRebaseDlg::OnBnClickedEditAll()\r
212 {\r
213     // TODO: Add your control notification handler code here\r
214         this->UpdateData();\r
215         if( this->m_bEditAll )\r
216                 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_EDIT);\r
217 \r
218         this->m_bPickAll=FALSE;\r
219         this->m_bSquashAll=FALSE;\r
220         this->UpdateData(FALSE);\r
221 \r
222 }\r
223 \r
224 void CRebaseDlg::SetAllRebaseAction(int action)\r
225 {\r
226         for(int i=0;i<this->m_CommitList.m_logEntries.size();i++)\r
227         {\r
228                 m_CommitList.m_logEntries[i].m_Action=action;\r
229         }\r
230         m_CommitList.Invalidate();\r
231 }\r
232 \r
233 void CRebaseDlg::OnBnClickedRebaseSplit()\r
234 {\r
235         this->UpdateData();\r
236     // TODO: Add your control notification handler code here\r
237 }\r
238 \r
239 LRESULT CRebaseDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)\r
240 {\r
241         switch (message) {\r
242         case WM_NOTIFY:\r
243                 if (wParam == IDC_REBASE_SPLIT)\r
244                 { \r
245                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
246                         DoSize(pHdr->delta);\r
247                 }\r
248                 break;\r
249         }\r
250 \r
251         return __super::DefWindowProc(message, wParam, lParam);\r
252 }\r
253 \r
254 void CRebaseDlg::DoSize(int delta)\r
255 {\r
256         \r
257         this->RemoveAllAnchors();\r
258 \r
259         CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST), delta, CW_TOPALIGN);\r
260         //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);\r
261         CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB), -delta, CW_BOTTOMALIGN);\r
262         //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);\r
263         CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL),0,delta);\r
264         CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL),0,delta);\r
265         CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL),0,delta);\r
266         \r
267         this->AddRebaseAnchor();\r
268         // adjust the minimum size of the dialog to prevent the resizing from\r
269         // moving the list control too far down.\r
270         CRect rcLogMsg;\r
271         m_CommitList.GetClientRect(rcLogMsg);\r
272         SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_CommitListOrigRect.Height()+rcLogMsg.Height()));\r
273 \r
274         SetSplitterRange();\r
275 //      m_CommitList.Invalidate();\r
276 \r
277 //      GetDlgItem(IDC_LOGMESSAGE)->Invalidate();\r
278 \r
279         this->m_ctrlTabCtrl.Invalidate();\r
280         this->m_CommitList.Invalidate();\r
281         this->m_FileListCtrl.Invalidate();\r
282         this->m_LogMessageCtrl.Invalidate();\r
283 \r
284 }\r
285 \r
286 void CRebaseDlg::SetSplitterRange()\r
287 {\r
288         if ((m_CommitList)&&(m_ctrlTabCtrl))\r
289         {\r
290                 CRect rcTop;\r
291                 m_CommitList.GetWindowRect(rcTop);\r
292                 ScreenToClient(rcTop);\r
293                 CRect rcMiddle;\r
294                 m_ctrlTabCtrl.GetWindowRect(rcMiddle);\r
295                 ScreenToClient(rcMiddle);\r
296                 if (rcMiddle.Height() && rcMiddle.Width())\r
297                         m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);\r
298         }\r
299 }\r
300 \r
301 void CRebaseDlg::OnSize(UINT nType,int cx, int cy)\r
302 {\r
303          // first, let the resizing take place\r
304     __super::OnSize(nType, cx, cy);\r
305 \r
306     //set range\r
307     SetSplitterRange();\r
308 }\r
309 \r
310 void CRebaseDlg::SaveSplitterPos()\r
311 {\r
312         if (!IsIconic())\r
313         {\r
314                 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));\r
315                 RECT rectSplitter;\r
316                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
317                 ScreenToClient(&rectSplitter);\r
318                 regPos = rectSplitter.top;\r
319         }\r
320 }\r
321 \r
322 void CRebaseDlg::LoadBranchInfo()\r
323 {\r
324         m_BranchCtrl.SetMaxHistoryItems(0x7FFFFFFF);\r
325         m_UpstreamCtrl.SetMaxHistoryItems(0x7FFFFFFF);\r
326 \r
327         STRING_VECTOR list;\r
328         list.clear();\r
329         int current;\r
330         g_Git.GetBranchList(list,&current,CGit::BRANCH_ALL);\r
331         m_BranchCtrl.AddString(list);\r
332         m_UpstreamCtrl.AddString(list);\r
333 \r
334         m_BranchCtrl.SetCurSel(current);\r
335 \r
336         AddBranchToolTips(&m_BranchCtrl);\r
337         AddBranchToolTips(&m_UpstreamCtrl);\r
338 \r
339 }\r
340 \r
341 void CRebaseDlg::OnCbnSelchangeBranch()\r
342 {\r
343         FetchLogList();\r
344 }\r
345 \r
346 void CRebaseDlg::OnCbnSelchangeUpstream()\r
347 {\r
348         FetchLogList();\r
349 }\r
350 \r
351 void CRebaseDlg::FetchLogList()\r
352 {\r
353         m_CommitList.Clear();\r
354         this->m_CommitList.FillGitLog(NULL,0,&m_UpstreamCtrl.GetString(),&m_BranchCtrl.GetString());\r
355         if( m_CommitList.GetItemCount() == 0 )\r
356                 m_CommitList.ShowText(_T("Nothing Rebase"));\r
357 \r
358         CString hash=g_Git.GetHash(m_UpstreamCtrl.GetString());\r
359         \r
360 #if 0\r
361         if(m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash.size() >=0 )\r
362         {\r
363                 if(hash ==  m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash[0])\r
364                 {\r
365                         m_CommitList.Clear();\r
366                         m_CommitList.ShowText(_T("Nothing Rebase"));\r
367                 }\r
368         }\r
369 #endif\r
370 \r
371         m_tooltips.Pop();\r
372         AddBranchToolTips(&this->m_BranchCtrl);\r
373         AddBranchToolTips(&this->m_UpstreamCtrl);\r
374         \r
375         for(int i=0;i<m_CommitList.m_logEntries.size();i++)\r
376         {\r
377                 m_CommitList.m_logEntries[i].m_Action = CTGitPath::LOGACTIONS_REBASE_PICK;\r
378         }\r
379         \r
380         m_CommitList.Invalidate();\r
381 \r
382         if(m_CommitList.m_IsOldFirst)\r
383                 this->m_CurrentRebaseIndex = -1;\r
384         else\r
385                 this->m_CurrentRebaseIndex = m_CommitList.m_logEntries.size();\r
386         \r
387 }\r
388 \r
389 void CRebaseDlg::AddBranchToolTips(CHistoryCombo *pBranch)\r
390 {\r
391         if(pBranch)\r
392         {\r
393                 CString text=pBranch->GetString();\r
394                 CString tooltip;\r
395                 BYTE_VECTOR data;\r
396                 g_Git.GetLog(data,text,NULL,1,0);\r
397                 GitRev rev;\r
398                 rev.ParserFromLog(data);\r
399                 tooltip.Format(_T("CommitHash:%s\nCommit by: %s  %s\n <b>%s</b> \n %s"),\r
400                         rev.m_CommitHash,\r
401                         rev.m_AuthorName,\r
402                         CAppUtils::FormatDateAndTime(rev.m_AuthorDate,DATE_LONGDATE),\r
403                         rev.m_Subject,\r
404                         rev.m_Body);\r
405 \r
406                 pBranch->DisableTooltip();\r
407                 this->m_tooltips.AddTool(pBranch->GetComboBoxCtrl(),tooltip);\r
408         }\r
409 }\r
410 \r
411 BOOL CRebaseDlg::PreTranslateMessage(MSG*pMsg)\r
412 {\r
413         m_tooltips.RelayEvent(pMsg);\r
414         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
415 }\r
416 int CRebaseDlg::CheckRebaseCondition()\r
417 {\r
418         this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
419 \r
420         if( !g_Git.CheckCleanWorkTree()  )\r
421         {\r
422                 CMessageBox::Show(NULL,_T("Rebase Need Clean Working Tree"),_T("TortoiseGit"),MB_OK);\r
423                 return -1;\r
424         }\r
425         //Todo Check $REBASE_ROOT\r
426         //Todo Check $DOTEST\r
427 \r
428         CString cmd;\r
429         cmd=_T("git.exe var GIT_COMMITTER_IDENT");\r
430         if(g_Git.Run(cmd,NULL,CP_UTF8))\r
431                 return -1;\r
432 \r
433         //Todo call pre_rebase_hook\r
434 }\r
435 int CRebaseDlg::StartRebase()\r
436 {\r
437         CString cmd,out;\r
438         //Todo call comment_for_reflog\r
439         cmd.Format(_T("git.exe checkout %s"),this->m_BranchCtrl.GetString());\r
440         this->AddLogString(cmd);\r
441 \r
442         if(g_Git.Run(cmd,&out,CP_UTF8))\r
443                 return -1;\r
444 \r
445         this->AddLogString(out);\r
446 \r
447         cmd=_T("git.exe rev-parse --verify HEAD");\r
448         if(g_Git.Run(cmd,&out,CP_UTF8))\r
449         {\r
450                 AddLogString(_T("No Head"));\r
451                 return -1;\r
452         }\r
453         //Todo \r
454         //git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||\r
455         //              echo "detached HEAD" > "$DOTEST"/head-name\r
456 \r
457         cmd.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));\r
458         if(g_Git.Run(cmd,&out,CP_UTF8))\r
459         {\r
460                 AddLogString(_T("update ORIG_HEAD Fail"));\r
461                 return -1;\r
462         }\r
463         \r
464         cmd.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));\r
465 \r
466         cmd.Format(_T("git.exe checkout %s"),this->m_UpstreamCtrl.GetString());\r
467         this->AddLogString(cmd);\r
468 \r
469         out.Empty();\r
470         if(g_Git.Run(cmd,&out,CP_UTF8))\r
471         {\r
472                 return -1;\r
473         }\r
474         \r
475         cmd.Format(_T("git.exe rev-parse %s"),this->m_UpstreamCtrl.GetString());\r
476         if(g_Git.Run(cmd,&this->m_OrigUpstreamHash,CP_UTF8))\r
477         {\r
478                 this->AddLogString(m_OrigUpstreamHash);\r
479                 return -1;\r
480         }\r
481 \r
482         cmd.Format(_T("git.exe rev-parse %s"),this->m_BranchCtrl.GetString());\r
483         if(g_Git.Run(cmd,&this->m_OrigBranchHash,CP_UTF8))\r
484         {\r
485                 this->AddLogString(m_OrigBranchHash);\r
486                 return -1;\r
487         }\r
488 \r
489         this->AddLogString(_T("Start Rebase\r\n"));\r
490         return 0;\r
491 }\r
492 int  CRebaseDlg::VerifyNoConflict()\r
493 {\r
494         CTGitPathList list;\r
495         if(g_Git.ListConflictFile(list))\r
496         {\r
497                 AddLogString(_T("Get conflict files fail"));\r
498                 return -1;\r
499         }\r
500         if( list.GetCount() != 0 )\r
501         {\r
502                 CMessageBox::Show(NULL,_T("There are conflict file, you should mark it resolve"),_T("TortoiseGit"),MB_OK);\r
503                 return -1;\r
504         }\r
505         return 0;\r
506 \r
507 }\r
508 void CRebaseDlg::OnBnClickedContinue()\r
509 {\r
510         if( m_RebaseStage == CHOOSE_BRANCH|| m_RebaseStage == CHOOSE_COMMIT_PICK_MODE )\r
511         {\r
512                 if(CheckRebaseCondition())\r
513                         return ;\r
514                 m_RebaseStage = REBASE_START;\r
515         }\r
516 \r
517         if( m_RebaseStage == REBASE_FINISH )\r
518         {\r
519                 CString cmd,out;\r
520                 cmd.Format(_T("git branch -f %s"),this->m_BranchCtrl.GetString());\r
521                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
522                 {\r
523                         AddLogString(out);\r
524                         return ;\r
525                 }\r
526                 cmd.Format(_T("git reset --hard %s"),this->m_OrigUpstreamHash);\r
527                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
528                 {\r
529                         AddLogString(out);\r
530                         return ;\r
531                 }\r
532                 OnOK();\r
533         }\r
534 \r
535         if( m_RebaseStage == REBASE_SQUASH_CONFLICT)\r
536         {\r
537                 if(VerifyNoConflict())\r
538                         return;\r
539                 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
540                 if(this->CheckNextCommitIsSquash())\r
541                 {//next commit is not squash;\r
542                         m_RebaseStage = REBASE_SQUASH_EDIT;\r
543                         this->OnRebaseUpdateUI(0,0);\r
544                         this->UpdateCurrentStatus();\r
545                         return ;\r
546 \r
547                 }\r
548                 m_RebaseStage=REBASE_CONTINUE;\r
549                 curRev->m_Action|=CTGitPath::LOGACTIONS_REBASE_DONE;\r
550                 this->UpdateCurrentStatus();\r
551 \r
552         }\r
553 \r
554         if( m_RebaseStage == REBASE_CONFLICT )\r
555         {\r
556                 if(VerifyNoConflict())\r
557                         return;\r
558 \r
559                 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
560                 \r
561                 CString out =_T("");\r
562                 CString cmd;\r
563                 cmd.Format(_T("git.exe commit -C %s"), curRev->m_CommitHash);\r
564 \r
565                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
566                 {\r
567                         if(!g_Git.CheckCleanWorkTree())\r
568                         {\r
569                                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
570                                 return;\r
571                         }\r
572                 }\r
573 \r
574                 AddLogString(out);\r
575                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
576                 if( curRev->m_Action & CTGitPath::LOGACTIONS_REBASE_EDIT)\r
577                 {\r
578                         m_RebaseStage=REBASE_EDIT;\r
579                         this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);\r
580                         this->UpdateCurrentStatus();\r
581                         return;\r
582                 }\r
583                 else\r
584                 {\r
585                         m_RebaseStage=REBASE_CONTINUE;\r
586                         curRev->m_Action|=CTGitPath::LOGACTIONS_REBASE_DONE;\r
587                         this->UpdateCurrentStatus();\r
588                 }\r
589                 \r
590         }\r
591 \r
592         if( m_RebaseStage == REBASE_EDIT ||  m_RebaseStage == REBASE_SQUASH_EDIT )\r
593         {\r
594                 CString str;\r
595                 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
596         \r
597                 str=this->m_LogMessageCtrl.GetText();\r
598                 if(str.Trim().IsEmpty())\r
599                 {\r
600                         CMessageBox::Show(NULL,_T("Commit Message Is Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
601                                 return;\r
602                 }\r
603 \r
604                 CString tempfile=::GetTempFile();\r
605                 CFile file(tempfile,CFile::modeReadWrite|CFile::modeCreate );\r
606                 CStringA log=CUnicodeUtils::GetUTF8( str);\r
607                 file.Write(log,log.GetLength());\r
608                 //file.WriteString(m_sLogMessage);\r
609                 file.Close();\r
610         \r
611                 CString out,cmd;\r
612                 \r
613                 if(  m_RebaseStage == REBASE_SQUASH_EDIT )\r
614                         cmd.Format(_T("git.exe commit -F \"%s\""), tempfile);\r
615                 else\r
616                         cmd.Format(_T("git.exe commit --amend -F \"%s\""), tempfile);\r
617 \r
618                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
619                 {\r
620                         if(!g_Git.CheckCleanWorkTree())\r
621                         {\r
622                                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
623                                 return;\r
624                         }\r
625                 }\r
626 \r
627                 CFile::Remove(tempfile);\r
628                 AddLogString(out);\r
629                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
630                 m_RebaseStage=REBASE_CONTINUE;\r
631                 curRev->m_Action|=CTGitPath::LOGACTIONS_REBASE_DONE;\r
632                 this->UpdateCurrentStatus();\r
633         }\r
634 \r
635 \r
636         InterlockedExchange(&m_bThreadRunning, TRUE);\r
637         SetControlEnable();\r
638         \r
639         if (AfxBeginThread(RebaseThreadEntry, this)==NULL)\r
640         {\r
641                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
642                 CMessageBox::Show(NULL, _T("Create Rebase Thread Fail"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);\r
643                 SetControlEnable();\r
644         }\r
645 }\r
646 int CRebaseDlg::CheckNextCommitIsSquash()\r
647 {\r
648         int index;\r
649         if(m_CommitList.m_IsOldFirst)\r
650                 index=m_CurrentRebaseIndex+1;\r
651         else\r
652                 index=m_CurrentRebaseIndex-1;\r
653 \r
654         GitRev *curRev;\r
655         do\r
656         {\r
657                 curRev=(GitRev*)m_CommitList.m_arShownList[index];\r
658                 \r
659                 if( curRev->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH )\r
660                         return 0;\r
661                 if( curRev->m_Action&CTGitPath::LOGACTIONS_REBASE_SKIP)\r
662                 {\r
663                         if(m_CommitList.m_IsOldFirst)\r
664                                 index++;\r
665                         else\r
666                                 index--;\r
667                 }else\r
668                         return -1;\r
669 \r
670                 if(index<0)\r
671                         return -1;\r
672                 if(index>= m_CommitList.GetItemCount())\r
673                         return -1;\r
674 \r
675         }while(curRev->m_Action&CTGitPath::LOGACTIONS_REBASE_SKIP);\r
676         \r
677         return -1;\r
678 \r
679 }\r
680 int CRebaseDlg::GoNext()\r
681 {\r
682         if(m_CommitList.m_IsOldFirst)\r
683                 m_CurrentRebaseIndex++;\r
684         else\r
685                 m_CurrentRebaseIndex--; \r
686         return 0;\r
687 \r
688 }\r
689 int CRebaseDlg::StateAction()\r
690 {\r
691         switch(this->m_RebaseStage)\r
692         {\r
693         case CHOOSE_BRANCH:\r
694         case CHOOSE_COMMIT_PICK_MODE:\r
695                 if(StartRebase())\r
696                         return -1;\r
697                 m_RebaseStage = REBASE_START;\r
698                 GoNext();\r
699                 break;\r
700         }\r
701 \r
702         return 0;       \r
703 }\r
704 void CRebaseDlg::SetContinueButtonText()\r
705 {\r
706         CString Text;\r
707         switch(this->m_RebaseStage)\r
708         {\r
709         case CHOOSE_BRANCH:\r
710         case CHOOSE_COMMIT_PICK_MODE:\r
711                 Text = _T("Start");\r
712                 break;\r
713 \r
714         case REBASE_START:\r
715         case REBASE_CONTINUE:\r
716         case REBASE_SQUASH_CONFLICT:\r
717                 Text = _T("Continue");\r
718                 break;\r
719 \r
720         case REBASE_CONFLICT:\r
721                 Text = _T("Commit");\r
722                 break;\r
723         case REBASE_EDIT:\r
724                 Text = _T("Amend");\r
725                 break;\r
726 \r
727         case REBASE_SQUASH_EDIT:\r
728                 Text = _T("Commit");\r
729                 break;\r
730 \r
731         case REBASE_ABORT:\r
732         case REBASE_FINISH:\r
733                 Text = _T("Finish");\r
734                 break;\r
735         }\r
736         this->GetDlgItem(IDC_REBASE_CONTINUE)->SetWindowText(Text);\r
737 }\r
738 \r
739 void CRebaseDlg::SetControlEnable()\r
740 {\r
741         switch(this->m_RebaseStage)\r
742         {\r
743         case CHOOSE_BRANCH:\r
744         case CHOOSE_COMMIT_PICK_MODE:\r
745                 \r
746                 this->GetDlgItem(IDC_PICK_ALL)->EnableWindow(TRUE);\r
747                 this->GetDlgItem(IDC_EDIT_ALL)->EnableWindow(TRUE);\r
748                 this->GetDlgItem(IDC_SQUASH_ALL)->EnableWindow(TRUE);\r
749                 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH)->EnableWindow(TRUE);\r
750                 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM)->EnableWindow(TRUE);\r
751                 this->m_CommitList.m_IsEnableRebaseMenu=TRUE;\r
752                 break;\r
753 \r
754         case REBASE_START:\r
755         case REBASE_CONTINUE:\r
756         case REBASE_ABORT:\r
757         case REBASE_FINISH:\r
758         case REBASE_CONFLICT:\r
759         case REBASE_EDIT:\r
760         case REBASE_SQUASH_CONFLICT:\r
761                 this->GetDlgItem(IDC_PICK_ALL)->EnableWindow(FALSE);\r
762                 this->GetDlgItem(IDC_EDIT_ALL)->EnableWindow(FALSE);\r
763                 this->GetDlgItem(IDC_SQUASH_ALL)->EnableWindow(FALSE);\r
764                 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH)->EnableWindow(FALSE);\r
765                 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM)->EnableWindow(FALSE);\r
766                 this->m_CommitList.m_IsEnableRebaseMenu=FALSE;\r
767                 break;\r
768         }\r
769 \r
770         if(m_bThreadRunning)\r
771         {\r
772                 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(FALSE);\r
773                 this->GetDlgItem(IDC_REBASE_ABORT)->EnableWindow(FALSE);\r
774 \r
775         }else\r
776         {\r
777                 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(TRUE);\r
778                 this->GetDlgItem(IDC_REBASE_ABORT)->EnableWindow(TRUE);\r
779         }\r
780 }\r
781 \r
782 void CRebaseDlg::UpdateProgress()\r
783 {\r
784         int index;\r
785         CRect rect;\r
786 \r
787         if(m_CommitList.m_IsOldFirst)\r
788                 index = m_CurrentRebaseIndex+1;\r
789         else\r
790                 index = m_CommitList.GetItemCount()-m_CurrentRebaseIndex;\r
791 \r
792         m_ProgressBar.SetRange(1,m_CommitList.GetItemCount());\r
793         m_ProgressBar.SetPos(index);\r
794 \r
795         if(m_CurrentRebaseIndex>0 && m_CurrentRebaseIndex< m_CommitList.GetItemCount())\r
796         {\r
797                 CString text;\r
798                 text.Format(_T("Rebasing...(%d/%d)"),index,m_CommitList.GetItemCount());\r
799                 m_CtrlStatusText.SetWindowText(text);\r
800 \r
801         }\r
802 \r
803         GitRev *prevRev=NULL, *curRev=NULL;\r
804 \r
805         if( m_CurrentRebaseIndex >= 0 && m_CurrentRebaseIndex< m_CommitList.m_arShownList.GetSize())\r
806         {\r
807                 curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
808         }\r
809         \r
810         for(int i=0;i<m_CommitList.m_arShownList.GetSize();i++)\r
811         {\r
812                 prevRev=(GitRev*)m_CommitList.m_arShownList[i];\r
813                 if(prevRev->m_Action & CTGitPath::LOGACTIONS_REBASE_CURRENT)\r
814                 {       \r
815                         prevRev->m_Action &= ~ CTGitPath::LOGACTIONS_REBASE_CURRENT;\r
816                         m_CommitList.GetItemRect(i,&rect,LVIR_BOUNDS);\r
817                         m_CommitList.InvalidateRect(rect);\r
818                 }\r
819         }\r
820 \r
821         if(curRev)\r
822         {\r
823                 curRev->m_Action |= CTGitPath::LOGACTIONS_REBASE_CURRENT;\r
824                 m_CommitList.GetItemRect(m_CurrentRebaseIndex,&rect,LVIR_BOUNDS);\r
825                 m_CommitList.InvalidateRect(rect);\r
826         }\r
827         m_CommitList.EnsureVisible(m_CurrentRebaseIndex,FALSE);\r
828 \r
829 }\r
830 \r
831 void CRebaseDlg::UpdateCurrentStatus()\r
832 {\r
833         if( m_CurrentRebaseIndex < 0)\r
834         {\r
835                 if(m_CommitList.m_IsOldFirst)\r
836                         m_RebaseStage = CRebaseDlg::REBASE_START;\r
837                 else\r
838                         m_RebaseStage = CRebaseDlg::REBASE_FINISH;\r
839         }\r
840 \r
841         if( m_CurrentRebaseIndex == m_CommitList.m_arShownList.GetSize())\r
842         {\r
843                 if(m_CommitList.m_IsOldFirst)\r
844                         m_RebaseStage = CRebaseDlg::REBASE_FINISH;\r
845                 else\r
846                         m_RebaseStage = CRebaseDlg::REBASE_START;\r
847         }\r
848 \r
849         SetContinueButtonText();\r
850         SetControlEnable();\r
851         UpdateProgress();\r
852 }\r
853 \r
854 void CRebaseDlg::AddLogString(CString str)\r
855 {\r
856         this->m_wndOutputRebase.SendMessage(SCI_SETREADONLY, FALSE);\r
857         CStringA sTextA = m_wndOutputRebase.StringForControl(str);//CUnicodeUtils::GetUTF8(str);\r
858         this->m_wndOutputRebase.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)sTextA);\r
859         this->m_wndOutputRebase.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n");\r
860         this->m_wndOutputRebase.SendMessage(SCI_SETREADONLY, TRUE);\r
861 }\r
862 \r
863 int CRebaseDlg::GetCurrentCommitID()\r
864 {\r
865         if(m_CommitList.m_IsOldFirst)\r
866         {\r
867                 return this->m_CurrentRebaseIndex+1;\r
868 \r
869         }else\r
870         {\r
871                 return m_CommitList.GetItemCount()-m_CurrentRebaseIndex;\r
872         }\r
873 }\r
874 \r
875 int CRebaseDlg::DoRebase()\r
876 {       \r
877         CString cmd,out;\r
878         if(m_CurrentRebaseIndex <0)\r
879                 return 0;\r
880         if(m_CurrentRebaseIndex >= m_CommitList.GetItemCount() )\r
881                 return 0;\r
882 \r
883         GitRev *pRev = (GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
884         int mode=pRev->m_Action & CTGitPath::LOGACTIONS_REBASE_MODE_MASK;\r
885         CString nocommit;\r
886 \r
887         if( mode== CTGitPath::LOGACTIONS_REBASE_SKIP)\r
888         {\r
889                 pRev->m_Action|= CTGitPath::LOGACTIONS_REBASE_DONE;\r
890                 return 0;\r
891         }\r
892         \r
893         if( mode != CTGitPath::LOGACTIONS_REBASE_PICK )\r
894         {\r
895                 this->m_SquashMessage+= pRev->m_Subject;\r
896                 this->m_SquashMessage+= _T("\n");\r
897                 this->m_SquashMessage+= pRev->m_Body;\r
898         }\r
899         else\r
900                 this->m_SquashMessage.Empty();\r
901 \r
902         if(mode == CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
903                 nocommit=_T(" --no-commit ");\r
904 \r
905         CString log;\r
906         log.Format(_T("%s %d:%s"),CTGitPath::GetActionName(mode),this->GetCurrentCommitID(),pRev->m_CommitHash);\r
907         AddLogString(log);\r
908         AddLogString(pRev->m_Subject);\r
909         cmd.Format(_T("git.exe cherry-pick %s %s"),nocommit,pRev->m_CommitHash);\r
910 \r
911         if(g_Git.Run(cmd,&out,CP_UTF8))\r
912         {\r
913                 AddLogString(out);\r
914                 CTGitPathList list;\r
915                 if(g_Git.ListConflictFile(list))\r
916                 {\r
917                         AddLogString(_T("Get conflict files fail"));\r
918                         return -1;\r
919                 }\r
920                 if(list.GetCount() == 0 )\r
921                 {\r
922                         if(mode ==  CTGitPath::LOGACTIONS_REBASE_PICK)\r
923                         {\r
924                                 pRev->m_Action|= CTGitPath::LOGACTIONS_REBASE_DONE;\r
925                                 return 0;\r
926                         }\r
927                         if(mode == CTGitPath::LOGACTIONS_REBASE_EDIT)\r
928                                 return -1; // Edit return -1 to stop rebase. \r
929                         \r
930                         // Squash Case\r
931                         if(CheckNextCommitIsSquash())\r
932                         {   // no squash\r
933                                 // let user edit last commmit message\r
934                                 this->m_RebaseStage = REBASE_SQUASH_EDIT;\r
935                                 return -1;\r
936                         }\r
937                 }\r
938                 if(mode == CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
939                         m_RebaseStage = REBASE_SQUASH_CONFLICT;\r
940                 else\r
941                         m_RebaseStage = REBASE_CONFLICT;\r
942                 return -1;      \r
943 \r
944         }else\r
945         {\r
946                 AddLogString(out);\r
947                 if(mode ==  CTGitPath::LOGACTIONS_REBASE_PICK)\r
948                 {\r
949                         pRev->m_Action|= CTGitPath::LOGACTIONS_REBASE_DONE;\r
950                         return 0;\r
951                 }\r
952                 if(mode == CTGitPath::LOGACTIONS_REBASE_EDIT)\r
953                         return -1; // Edit return -1 to stop rebase. \r
954 \r
955                 // Squash Case\r
956                 if(CheckNextCommitIsSquash())\r
957                 {   // no squash\r
958                         // let user edit last commmit message\r
959                         this->m_RebaseStage = REBASE_SQUASH_EDIT;\r
960                         return -1;\r
961                 }\r
962         }\r
963         \r
964         return 0;\r
965 }\r
966 \r
967 BOOL CRebaseDlg::IsEnd()\r
968 {\r
969         if(m_CommitList.m_IsOldFirst)\r
970                 return m_CurrentRebaseIndex>= this->m_CommitList.GetItemCount();\r
971         else\r
972                 return m_CurrentRebaseIndex<0;\r
973 }\r
974 \r
975 int CRebaseDlg::RebaseThread()\r
976 {\r
977         int ret=0;\r
978         while(1)\r
979         {\r
980                 if( m_RebaseStage == REBASE_START )\r
981                 {\r
982                         if( this->StartRebase() )\r
983                         {\r
984                                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
985                                 ret = -1;\r
986                                 break;\r
987                         }\r
988                         m_RebaseStage = REBASE_CONTINUE;\r
989 \r
990                 }else if( m_RebaseStage == REBASE_CONTINUE )\r
991                 {\r
992                         this->GoNext(); \r
993                         if(IsEnd())\r
994                         {\r
995                                 ret = 0;\r
996                                 m_RebaseStage = REBASE_FINISH;\r
997                                 break;\r
998                         }\r
999 \r
1000                         ret = DoRebase();\r
1001 \r
1002                         if( ret )\r
1003                         {       \r
1004                                 break;\r
1005                         }\r
1006 \r
1007                 }else\r
1008                         break;\r
1009                 this->PostMessage(MSG_REBASE_UPDATE_UI);\r
1010                 //this->UpdateCurrentStatus();\r
1011         }\r
1012 \r
1013         InterlockedExchange(&m_bThreadRunning, FALSE);\r
1014         this->PostMessage(MSG_REBASE_UPDATE_UI);\r
1015         return ret;\r
1016 }\r
1017 \r
1018 void CRebaseDlg::ListConflictFile()\r
1019 {\r
1020         this->m_FileListCtrl.Clear();   \r
1021         CTGitPathList list;\r
1022         CTGitPath path;\r
1023         list.AddPath(path);\r
1024 \r
1025         this->m_FileListCtrl.GetStatus(list,true);\r
1026         this->m_FileListCtrl.Show(CTGitPath::LOGACTIONS_UNMERGED|CTGitPath::LOGACTIONS_MODIFIED,CTGitPath::LOGACTIONS_UNMERGED);\r
1027         if( this->m_FileListCtrl.GetItemCount() == 0 )\r
1028         {\r
1029                 \r
1030         }\r
1031 }\r
1032 \r
1033 LRESULT CRebaseDlg::OnRebaseUpdateUI(WPARAM,LPARAM)\r
1034 {\r
1035         UpdateCurrentStatus();\r
1036         if(m_CurrentRebaseIndex <0)\r
1037                 return 0;\r
1038         if(m_CurrentRebaseIndex >= m_CommitList.GetItemCount() )\r
1039                 return 0;\r
1040         GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
1041         \r
1042         switch(m_RebaseStage)\r
1043         {\r
1044         case REBASE_CONFLICT:\r
1045         case REBASE_SQUASH_CONFLICT:\r
1046                 ListConflictFile();                     \r
1047                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_CONFLICT);\r
1048                 this->m_LogMessageCtrl.SetText(curRev->m_Subject+_T("\n")+curRev->m_Body);\r
1049                 break;\r
1050         case REBASE_EDIT:\r
1051                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);\r
1052                 this->m_LogMessageCtrl.SetText(curRev->m_Subject+_T("\n")+curRev->m_Body);\r
1053                 break;\r
1054         case REBASE_SQUASH_EDIT:\r
1055                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);\r
1056                 this->m_LogMessageCtrl.SetText(this->m_SquashMessage);\r
1057                 break;\r
1058         default:\r
1059                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
1060         }       \r
1061         return 0;\r
1062 }\r
1063 \r
1064 void CRebaseDlg::OnBnClickedAbort()\r
1065 {\r
1066         CString cmd,out;\r
1067         if(m_OrigUpstreamHash.IsEmpty())\r
1068         {\r
1069                 this->OnCancel();\r
1070         }\r
1071         if(CMessageBox::Show(NULL,_T("Are you sure abort rebase"),_T("TortoiseGit"),MB_YESNO) != IDYES)\r
1072                 return;\r
1073 \r
1074         cmd.Format(_T("git.exe reset --hard  %s"),this->m_OrigUpstreamHash.Left(40));\r
1075         if(g_Git.Run(cmd,&out,CP_UTF8))\r
1076         {\r
1077                 AddLogString(out);\r
1078                 return ;\r
1079         }\r
1080         \r
1081         cmd.Format(_T("git checkout -f %s"),this->m_BranchCtrl.GetString());\r
1082         if(g_Git.Run(cmd,&out,CP_UTF8))\r
1083         {\r
1084                 AddLogString(out);\r
1085                 return ;\r
1086         }\r
1087         this->OnCancel();\r
1088 }\r