improve displayed error message
[TortoiseGit.git] / src / TortoiseProc / GitLogListAction.cpp
blob42fd3b05ef5a9173d61f121f8ab8fd270f7c537e
1 // GitLogList.cpp : implementation file
2 //
3 /*
4 Description: qgit revision list view
6 Author: Marco Costalba (C) 2005-2007
8 Copyright: See COPYING file that comes with this distribution
11 #include "stdafx.h"
12 #include "TortoiseProc.h"
13 #include "GitLogList.h"
14 #include "GitRev.h"
15 //#include "VssStyle.h"
16 #include "IconMenu.h"
17 // CGitLogList
18 #include "cursor.h"
19 #include "InputDlg.h"
20 #include "PropDlg.h"
21 #include "SVNProgressDlg.h"
22 #include "ProgressDlg.h"
23 #include "SysProgressDlg.h"
24 //#include "RepositoryBrowser.h"
25 //#include "CopyDlg.h"
26 //#include "StatGraphDlg.h"
27 #include "Logdlg.h"
28 #include "MessageBox.h"
29 #include "Registry.h"
30 #include "AppUtils.h"
31 #include "PathUtils.h"
32 #include "StringUtils.h"
33 #include "UnicodeUtils.h"
34 #include "TempFile.h"
35 //#include "GitInfo.h"
36 //#include "GitDiff.h"
37 #include "IconMenu.h"
38 //#include "RevisionRangeDlg.h"
39 //#include "BrowseFolder.h"
40 //#include "BlameDlg.h"
41 //#include "Blame.h"
42 //#include "GitHelpers.h"
43 #include "GitStatus.h"
44 //#include "LogDlgHelper.h"
45 //#include "CachedLogInfo.h"
46 //#include "RepositoryInfo.h"
47 //#include "EditPropertiesDlg.h"
48 #include "FileDiffDlg.h"
49 #include "CommitDlg.h"
50 #include "RebaseDlg.h"
51 #include "GitDiff.h"
53 IMPLEMENT_DYNAMIC(CGitLogList, CHintListCtrl)
55 int CGitLogList::RevertSelectedCommits()
57 CSysProgressDlg progress;
58 int ret = -1;
60 #if 0
61 if(!g_Git.CheckCleanWorkTree())
63 CMessageBox::Show(NULL,_T("Revert requires a clean working tree"),_T("TortoiseGit"),MB_OK);
66 #endif
68 if (progress.IsValid() && (this->GetSelectedCount() > 1) )
70 progress.SetTitle(_T("Revert Commit"));
71 progress.SetAnimation(IDR_MOVEANI);
72 progress.SetTime(true);
73 progress.ShowModeless(this);
76 POSITION pos = GetFirstSelectedItemPosition();
77 int i=0;
78 while(pos)
80 int index = GetNextSelectedItem(pos);
81 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(index));
83 if (progress.IsValid() && (this->GetSelectedCount() > 1) )
85 progress.FormatPathLine(1, _T("Revert %s"), r1->m_CommitHash.ToString());
86 progress.FormatPathLine(2, _T("%s"), r1->GetSubject());
87 progress.SetProgress(i, this->GetSelectedCount());
89 i++;
91 if(r1->m_CommitHash.IsEmpty())
92 continue;
94 CString cmd, output;
95 cmd.Format(_T("git.exe revert --no-edit --no-commit %s"), r1->m_CommitHash.ToString());
96 if(g_Git.Run(cmd, &output, CP_ACP))
98 CString str;
99 str=_T("Revert fail\n");
100 str+= cmd;
101 str+= _T("\n")+output;
102 if( GetSelectedCount() == 1)
103 CMessageBox::Show(NULL,str, _T("TortoiseGit"),MB_OK|MB_ICONERROR);
104 else
106 if(CMessageBox::Show(NULL, str, _T("TortoiseGit"),2, IDI_ERROR, _T("Skip"), _T("Abort")) ==2)
108 return ret;
112 else
114 ret =0;
117 if ((progress.IsValid())&&(progress.HasUserCancelled()))
118 break;
120 return ret;
122 int CGitLogList::CherryPickFrom(CString from, CString to)
124 CLogDataVector logs(&m_LogCache);
125 if(logs.ParserFromLog(NULL,-1,0,&from,&to))
126 return -1;
128 if(logs.size() == 0)
129 return 0;
131 CSysProgressDlg progress;
132 if (progress.IsValid())
134 progress.SetTitle(_T("Cherry Pick"));
135 progress.SetAnimation(IDR_MOVEANI);
136 progress.SetTime(true);
137 progress.ShowModeless(this);
140 for(int i=logs.size()-1;i>=0;i--)
142 if (progress.IsValid())
144 progress.FormatPathLine(1, _T("Pick up %s"), logs.GetGitRevAt(i).m_CommitHash.ToString());
145 progress.FormatPathLine(2, _T("%s"), logs.GetGitRevAt(i).GetSubject());
146 progress.SetProgress(logs.size()-i, logs.size());
148 if ((progress.IsValid())&&(progress.HasUserCancelled()))
150 //CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
151 throw std::exception(CUnicodeUtils::GetUTF8(_T("User canceled\r\n\r\n")));
152 return -1;
154 CString cmd,out;
155 cmd.Format(_T("git.exe cherry-pick %s"),logs.GetGitRevAt(i).m_CommitHash.ToString());
156 out.Empty();
157 if(g_Git.Run(cmd,&out,CP_UTF8))
159 throw std::exception(CUnicodeUtils::GetUTF8(CString(_T("Cherry Pick Failure\r\n\r\n"))+out));
160 return -1;
164 return 0;
167 void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMenu *popmenu)
169 POSITION pos = GetFirstSelectedItemPosition();
170 int indexNext = GetNextSelectedItem(pos);
171 if (indexNext < 0)
172 return;
174 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));
176 theApp.DoWaitCursor(1);
177 switch (cmd&0xFFFF)
179 case ID_COMMIT:
181 CTGitPathList pathlist;
182 CTGitPathList selectedlist;
183 pathlist.AddPath(this->m_Path);
184 bool bSelectFilesForCommit = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE));
185 CAppUtils::Commit(CString(),false,CString(),
186 pathlist,selectedlist,bSelectFilesForCommit);
187 //this->Refresh();
188 this->GetParent()->PostMessage(WM_COMMAND,ID_LOGDLG_REFRESH,0);
190 break;
191 case ID_GNUDIFF1:
193 CString tempfile=GetTempFile();
194 CString command;
195 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
196 if(!r1->m_CommitHash.IsEmpty())
198 CString merge;
199 CString hash2;
200 cmd >>= 16;
201 if( (cmd&0xFFFF) == 0xFFFF)
203 merge=_T("-m");
204 } else if((cmd&0xFFFF) == 0xFFFE)
206 merge=_T("-c");
207 }else
209 if(cmd > r1->m_ParentHash.size())
211 CString str;
212 str.Format(_T("%d parent does not exist"), cmd);
213 CMessageBox::Show(NULL,str,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
214 return;
215 }else
217 if(cmd>0)
218 hash2 = r1->m_ParentHash[cmd-1].ToString();
221 command.Format(_T("git.exe diff-tree %s -r -p --stat %s %s"),merge, r1->m_CommitHash.ToString(), hash2);
222 }else
223 command.Format(_T("git.exe diff -r -p --stat"));
225 g_Git.RunLogFile(command,tempfile);
226 CAppUtils::StartUnifiedDiffViewer(tempfile,r1->m_CommitHash.ToString().Left(6)+_T(":")+r1->GetSubject());
228 break;
230 case ID_GNUDIFF2:
232 CString tempfile=GetTempFile();
233 CString cmd;
234 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
235 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
237 if( r1->m_CommitHash.IsEmpty()) {
238 cmd.Format(_T("git.exe diff -r -p --stat %s"),r2->m_CommitHash.ToString());
239 }else if( r2->m_CommitHash.IsEmpty()) {
240 cmd.Format(_T("git.exe diff -r -p --stat %s"),r1->m_CommitHash.ToString());
241 }else {
242 cmd.Format(_T("git.exe diff-tree -r -p --stat %s %s"),r2->m_CommitHash.ToString(),r1->m_CommitHash.ToString());
245 g_Git.RunLogFile(cmd,tempfile);
246 CAppUtils::StartUnifiedDiffViewer(tempfile,r2->m_CommitHash.ToString().Left(6)+_T(":")+r1->m_CommitHash.ToString().Left(6));
249 break;
251 case ID_COMPARETWO:
253 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
254 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
255 CGitDiff::DiffCommit(this->m_Path, r1,r2);
258 break;
261 case ID_COMPARE:
263 GitRev * r1 = &m_wcRev;
264 GitRev * r2 = pSelLogEntry;
266 CGitDiff::DiffCommit(this->m_Path, r1,r2);
268 //user clicked on the menu item "compare with working copy"
269 //if (PromptShown())
271 // GitDiff diff(this, m_hWnd, true);
272 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
273 // diff.SetHEADPeg(m_LogRevision);
274 // diff.ShowCompare(m_path, GitRev::REV_WC, m_path, revSelected);
276 //else
277 // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
279 break;
281 case ID_COMPAREWITHPREVIOUS:
284 CFileDiffDlg dlg;
286 if(pSelLogEntry->m_ParentHash.size()>0)
287 //if(m_logEntries.m_HashMap[pSelLogEntry->m_ParentHash[0]]>=0)
289 cmd>>=16;
290 cmd&=0xFFFF;
292 if(cmd == 0)
293 cmd=1;
295 CGitDiff::DiffCommit(this->m_Path, pSelLogEntry->m_CommitHash.ToString(),pSelLogEntry->m_ParentHash[cmd-1].ToString());
297 }else
299 CMessageBox::Show(NULL,_T("No previous version"),_T("TortoiseGit"),MB_OK);
301 //if (PromptShown())
303 // GitDiff diff(this, m_hWnd, true);
304 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
305 // diff.SetHEADPeg(m_LogRevision);
306 // diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected);
308 //else
309 // CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
311 break;
312 case ID_COPYCLIPBOARD:
314 CopySelectionToClipBoard();
316 break;
317 case ID_COPYHASH:
319 CopySelectionToClipBoard(TRUE);
321 break;
322 case ID_EXPORT:
323 CAppUtils::Export(&pSelLogEntry->m_CommitHash.ToString());
324 break;
325 case ID_CREATE_BRANCH:
326 CAppUtils::CreateBranchTag(FALSE,&pSelLogEntry->m_CommitHash.ToString());
327 ReloadHashMap();
328 Invalidate();
329 break;
330 case ID_CREATE_TAG:
331 CAppUtils::CreateBranchTag(TRUE,&pSelLogEntry->m_CommitHash.ToString());
332 ReloadHashMap();
333 Invalidate();
334 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
335 break;
336 case ID_SWITCHTOREV:
337 CAppUtils::Switch(&pSelLogEntry->m_CommitHash.ToString());
338 ReloadHashMap();
339 Invalidate();
340 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
341 break;
342 case ID_SWITCHBRANCH:
343 if(popmenu)
345 CString *branch = (CString*)((CIconMenu*)popmenu)->GetMenuItemData(cmd);
346 if(branch)
349 CProgressDlg progress;
350 CString name;
351 if(branch->Find(_T("refs/heads/")) ==0 )
352 name = branch->Mid(11);
353 else
354 name = *branch;
356 progress.m_GitCmd.Format(_T("git.exe checkout %s"), name.GetString());
357 progress.DoModal();
359 ReloadHashMap();
360 Invalidate();
361 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
363 break;
364 case ID_RESET:
365 CAppUtils::GitReset(&pSelLogEntry->m_CommitHash.ToString());
366 ReloadHashMap();
367 Invalidate();
368 break;
369 case ID_REBASE_PICK:
370 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK);
371 break;
372 case ID_REBASE_EDIT:
373 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT);
374 break;
375 case ID_REBASE_SQUASH:
376 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH);
377 break;
378 case ID_REBASE_SKIP:
379 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP);
380 break;
381 case ID_COMBINE_COMMIT:
383 CString head;
384 CGitHash headhash;
385 CGitHash hashFirst,hashLast;
387 int headindex=GetHeadIndex();
388 if(headindex>=0) //incase show all branch, head is not the first commits.
390 head.Format(_T("HEAD~%d"),FirstSelect-headindex);
391 hashFirst=g_Git.GetHash(head);
393 head.Format(_T("HEAD~%d"),LastSelect-headindex);
394 hashLast=g_Git.GetHash(head);
397 GitRev* pFirstEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
398 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
399 if(pFirstEntry->m_CommitHash != hashFirst || pLastEntry->m_CommitHash != hashLast)
401 CMessageBox::Show(NULL,_T("Cannot combine commits now.\r\nMake sure you are viewing the log of your current branch and no filters are applied."),_T("TortoiseGit"),MB_OK);
402 break;
405 headhash=g_Git.GetHash(_T("HEAD"));
407 if(!g_Git.CheckCleanWorkTree())
409 CMessageBox::Show(NULL,_T("Combine needs a clean work tree"),_T("TortoiseGit"),MB_OK);
410 break;
412 CString cmd,out;
414 //Use throw to abort this process (reset back to original HEAD)
417 cmd.Format(_T("git.exe reset --hard %s"),pFirstEntry->m_CommitHash.ToString());
418 if(g_Git.Run(cmd,&out,CP_UTF8))
420 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
421 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to first commit (first step) aborting...\r\n\r\n")+out));
423 cmd.Format(_T("git.exe reset --mixed %s"),hashLast.ToString());
424 if(g_Git.Run(cmd,&out,CP_UTF8))
426 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
427 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to last commit (second step) aborting...\r\n\r\n")+out));
429 CCommitDlg dlg;
430 for(int i=FirstSelect;i<=LastSelect;i++)
432 GitRev* pRev = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));
433 dlg.m_sLogMessage+=pRev->GetSubject()+_T("\n")+pRev->GetBody();
434 dlg.m_sLogMessage+=_T("\n");
436 dlg.m_bWholeProject=true;
437 dlg.m_bSelectFilesForCommit = true;
438 dlg.m_bCommitAmend=true;
439 dlg.m_AmendStr=dlg.m_sLogMessage;
441 if (dlg.DoModal() == IDOK)
443 if(pFirstEntry->m_CommitHash!=headhash)
445 //Commitrange firstEntry..headhash (from top of combine to original head) needs to be 'cherry-picked'
446 //on top of new commit.
447 //Use the rebase --onto command for it.
449 //All this can be done in one step using the following command:
450 //cmd.Format(_T("git.exe format-patch --stdout --binary --full-index -k %s..%s | git am -k -3"),
451 // pFirstEntry->m_CommitHash,
452 // headhash);
453 //But I am not sure if a '|' is going to work in a CreateProcess() call.
455 //Later the progress dialog could be used to execute these steps.
457 if(CherryPickFrom(pFirstEntry->m_CommitHash.ToString(),headhash))
459 CString msg;
460 msg.Format(_T("Error while cherry pick commits on top of combined commits. Aborting.\r\n\r\n"));
461 throw std::exception(CUnicodeUtils::GetUTF8(msg));
463 #if 0
464 CString currentBranch=g_Git.GetCurrentBranch();
465 cmd.Format(_T("git.exe rebase --onto \"%s\" %s %s"),
466 currentBranch,
467 pFirstEntry->m_CommitHash,
468 headhash);
469 if(g_Git.Run(cmd,&out,CP_UTF8)!=0)
471 CString msg;
472 msg.Format(_T("Error while rebasing commits on top of combined commits. Aborting.\r\n\r\n%s"),out);
473 // CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK);
474 g_Git.Run(_T("git.exe rebase --abort"),&out,CP_UTF8);
475 throw std::exception(CUnicodeUtils::GetUTF8(msg));
478 //HEAD is now on <no branch>.
479 //The following steps are to get HEAD back on the original branch and reset the branch to the new HEAD
480 //To avoid 2 working copy changes, we could use git branch -f <original branch> <hash new head>
481 //And then git checkout <original branch>
482 //But I don't know if 'git branch -f' removes tracking options. So for now, do a checkout and a reset.
484 //Store new HEAD
485 CString newHead=g_Git.GetHash(CString(_T("HEAD")));
487 //Checkout working branch
488 cmd.Format(_T("git.exe checkout -f \"%s\""),currentBranch);
489 if(g_Git.Run(cmd,&out,CP_UTF8))
490 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not checkout original branch. Aborting...\r\n\r\n")+out));
492 //Reset to new HEAD
493 cmd.Format(_T("git.exe reset --hard %s"),newHead);
494 if(g_Git.Run(cmd,&out,CP_UTF8))
495 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to new head. Aborting...\r\n\r\n")+out));
496 #endif
499 else
500 throw std::exception("User aborted the combine process");
502 catch(std::exception& e)
504 CMessageBox::Show(NULL,CUnicodeUtils::GetUnicode(CStringA(e.what())),_T("TortoiseGit: Combine error"),MB_OK|MB_ICONERROR);
505 cmd.Format(_T("git.exe reset --hard %s"),headhash.ToString());
506 out.Empty();
507 if(g_Git.Run(cmd,&out,CP_UTF8))
509 CMessageBox::Show(NULL,_T("Could not reset to original HEAD\r\n\r\n")+out,_T("TortoiseGit"),MB_OK);
512 Refresh();
514 break;
516 case ID_CHERRY_PICK:
517 if(!g_Git.CheckCleanWorkTree())
519 CMessageBox::Show(NULL,_T("Cherry Pick requires a clean working tree"),_T("TortoiseGit"),MB_OK);
521 }else
523 CRebaseDlg dlg;
524 dlg.m_IsCherryPick = TRUE;
525 dlg.m_Upstream = this->m_CurrentBranch;
526 POSITION pos = GetFirstSelectedItemPosition();
527 while(pos)
529 int indexNext = GetNextSelectedItem(pos);
530 dlg.m_CommitList.m_logEntries.push_back( ((GitRev*)m_arShownList[indexNext])->m_CommitHash );
531 dlg.m_CommitList.m_LogCache.m_HashMap[((GitRev*)m_arShownList[indexNext])->m_CommitHash]=*(GitRev*)m_arShownList[indexNext];
532 dlg.m_CommitList.m_logEntries.GetGitRevAt(dlg.m_CommitList.m_logEntries.size()-1).GetAction(this) |= CTGitPath::LOGACTIONS_REBASE_PICK;
535 if(dlg.DoModal() == IDOK)
537 Refresh();
540 break;
541 case ID_REBASE_TO_VERSION:
542 if(!g_Git.CheckCleanWorkTree())
544 CMessageBox::Show(NULL,_T("Rebase requires a clean working tree"),_T("TortoiseGit"),MB_OK);
546 }else
548 CRebaseDlg dlg;
549 dlg.m_Upstream = pSelLogEntry->m_CommitHash;
551 if(dlg.DoModal() == IDOK)
553 Refresh();
557 break;
559 case ID_STASH_APPLY:
560 CAppUtils::StashApply(pSelLogEntry->m_Ref);
561 break;
563 case ID_REFLOG_DEL:
565 CString str;
566 str.Format(_T("Warning: %s will be permanently deleted. It can <ct=0x0000FF><b>NOT</b></ct> be recovered!\r\n \r\n Are you sure you want to continue?"),pSelLogEntry->m_Ref);
567 if(CMessageBox::Show(NULL,str,_T("TortoiseGit"),MB_YESNO|MB_ICONWARNING) == IDYES)
569 CString cmd,out;
570 cmd.Format(_T("git.exe reflog delete %s"),pSelLogEntry->m_Ref);
571 if(g_Git.Run(cmd,&out,CP_ACP))
573 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
575 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
578 break;
579 case ID_LOG:
581 CString cmd;
582 cmd = CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
583 cmd += _T(" /command:log");
584 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\" ");
585 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
586 cmd += _T(" /endrev:")+r1->m_CommitHash.ToString();
587 CAppUtils::LaunchApplication(cmd,IDS_ERR_PROC,false);
589 break;
590 case ID_CREATE_PATCH:
592 int select=this->GetSelectedCount();
593 CString cmd;
594 cmd = CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
595 cmd += _T(" /command:formatpatch");
597 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\" ");
599 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
600 GitRev * r2 = NULL;
601 if(select == 1)
603 cmd += _T(" /startrev:")+r1->m_CommitHash.ToString();
605 else
607 r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
608 if( this->m_IsOldFirst )
610 cmd += _T(" /startrev:")+r1->m_CommitHash.ToString()+_T("~1");
611 cmd += _T(" /endrev:")+r2->m_CommitHash.ToString();
613 }else
615 cmd += _T(" /startrev:")+r2->m_CommitHash.ToString()+_T("~1");
616 cmd += _T(" /endrev:")+r1->m_CommitHash.ToString();
621 CAppUtils::LaunchApplication(cmd,IDS_ERR_PROC,false);
623 break;
624 case ID_DELETE:
626 int index = cmd>>16;
627 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) == m_HashMap.end() )
629 CMessageBox::Show(NULL,IDS_ERROR_NOREF,IDS_APPNAME,MB_OK|MB_ICONERROR);
630 return;
632 if( index >= m_HashMap[pSelLogEntry->m_CommitHash].size())
634 CMessageBox::Show(NULL,IDS_ERROR_INDEX,IDS_APPNAME,MB_OK|MB_ICONERROR);
635 return;
637 CString ref,msg;
638 ref=m_HashMap[pSelLogEntry->m_CommitHash][index];
640 msg=CString(_T("<ct=0x0000FF>Delete</ct> <b>"))+ref;
641 msg+=_T("</b>\n\n Are you sure?");
642 if( CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_YESNO) == IDYES )
644 CString shortname;
645 CString cmd;
646 if(this->GetShortName(ref,shortname,_T("refs/heads/")))
648 cmd.Format(_T("git.exe branch -D %s"),shortname);
651 if(this->GetShortName(ref,shortname,_T("refs/remotes/")))
653 cmd.Format(_T("git.exe branch -r -D %s"),shortname);
656 if(this->GetShortName(ref,shortname,_T("refs/tags/")))
658 cmd.Format(_T("git.exe tag -d %s"),shortname);
661 if(this->GetShortName(ref,shortname,_T("refs/stash")))
663 if(CMessageBox::Show(NULL,_T("<ct=0x0000FF>Are you sure remove <b>ALL</b> stash?</ct>"),
664 _T("TortoiseGit"),MB_YESNO)==IDYES)
665 cmd.Format(_T("git.exe stash clear"));
666 else
667 return;
670 CString out;
671 if(g_Git.Run(cmd,&out,CP_UTF8))
673 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
675 this->ReloadHashMap();
676 CRect rect;
677 this->GetItemRect(FirstSelect,&rect,LVIR_BOUNDS);
678 this->InvalidateRect(rect);
681 break;
683 case ID_FINDENTRY:
685 m_nSearchIndex = GetSelectionMark();
686 if (m_nSearchIndex < 0)
687 m_nSearchIndex = 0;
688 if (m_pFindDialog)
690 break;
692 else
694 m_pFindDialog = new CFindDlg();
695 m_pFindDialog->Create(this);
698 break;
699 case ID_MERGEREV:
701 // we need an URL to complete this command, so error out if we can't get an URL
702 if(CAppUtils::Merge(&pSelLogEntry->m_CommitHash.ToString()))
704 this->Refresh();
707 break;
708 case ID_REVERTREV:
710 if(!this->RevertSelectedCommits())
711 this->Refresh();
713 break;
714 case ID_EDITNOTE:
716 CAppUtils::EditNote(pSelLogEntry);
717 this->SetItemState(FirstSelect, 0, LVIS_SELECTED);
718 this->SetItemState(FirstSelect, LVIS_SELECTED, LVIS_SELECTED);
720 break;
721 default:
722 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
723 break;
724 #if 0
726 case ID_BLAMECOMPARE:
728 //user clicked on the menu item "compare with working copy"
729 //now first get the revision which is selected
730 if (PromptShown())
732 GitDiff diff(this, this->m_hWnd, true);
733 diff.SetHEADPeg(m_LogRevision);
734 diff.ShowCompare(m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), false, true);
736 else
737 CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), m_LogRevision, false, false, true);
739 break;
740 case ID_BLAMETWO:
742 //user clicked on the menu item "compare and blame revisions"
743 if (PromptShown())
745 GitDiff diff(this, this->m_hWnd, true);
746 diff.SetHEADPeg(m_LogRevision);
747 diff.ShowCompare(CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), false, true);
749 else
750 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
752 break;
753 case ID_BLAMEWITHPREVIOUS:
755 //user clicked on the menu item "Compare and Blame with previous revision"
756 if (PromptShown())
758 GitDiff diff(this, this->m_hWnd, true);
759 diff.SetHEADPeg(m_LogRevision);
760 diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), false, true);
762 else
763 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
765 break;
767 case ID_OPENWITH:
768 bOpenWith = true;
769 case ID_OPEN:
771 CProgressDlg progDlg;
772 progDlg.SetTitle(IDS_APPNAME);
773 progDlg.SetAnimation(IDR_DOWNLOAD);
774 CString sInfoLine;
775 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, m_path.GetWinPath(), (LPCTSTR)revSelected.ToString());
776 progDlg.SetLine(1, sInfoLine, true);
777 SetAndClearProgressInfo(&progDlg);
778 progDlg.ShowModeless(m_hWnd);
779 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, m_path, revSelected);
780 bool bSuccess = true;
781 if (!Cat(m_path, GitRev(GitRev::REV_HEAD), revSelected, tempfile))
783 bSuccess = false;
784 // try again, but with the selected revision as the peg revision
785 if (!Cat(m_path, revSelected, revSelected, tempfile))
787 progDlg.Stop();
788 SetAndClearProgressInfo((HWND)NULL);
789 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
790 EnableOKButton();
791 break;
793 bSuccess = true;
795 if (bSuccess)
797 progDlg.Stop();
798 SetAndClearProgressInfo((HWND)NULL);
799 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
800 int ret = 0;
801 if (!bOpenWith)
802 ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
803 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
805 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
806 cmd += tempfile.GetWinPathString() + _T(" ");
807 CAppUtils::LaunchApplication(cmd, NULL, false);
811 break;
812 case ID_BLAME:
814 CBlameDlg dlg;
815 dlg.EndRev = revSelected;
816 if (dlg.DoModal() == IDOK)
818 CBlame blame;
819 CString tempfile;
820 CString logfile;
821 tempfile = blame.BlameToTempFile(m_path, dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
822 if (!tempfile.IsEmpty())
824 if (dlg.m_bTextView)
826 //open the default text editor for the result file
827 CAppUtils::StartTextViewer(tempfile);
829 else
831 CString sParams = _T("/path:\"") + m_path.GetGitPathString() + _T("\" ");
832 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(m_path.GetFileOrDirectoryName()),sParams))
834 break;
838 else
840 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
844 break;
845 case ID_UPDATE:
847 CString sCmd;
848 CString url = _T("tgit:")+pathURL;
849 sCmd.Format(_T("%s /command:update /path:\"%s\" /rev:%ld"),
850 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
851 (LPCTSTR)m_path.GetWinPath(), (LONG)revSelected);
852 CAppUtils::LaunchApplication(sCmd, NULL, false);
854 break;
856 case ID_REPOBROWSE:
858 CString sCmd;
859 sCmd.Format(_T("%s /command:repobrowser /path:\"%s\" /rev:%s"),
860 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
861 (LPCTSTR)pathURL, (LPCTSTR)revSelected.ToString());
863 CAppUtils::LaunchApplication(sCmd, NULL, false);
865 break;
866 case ID_EDITLOG:
868 EditLogMessage(selIndex);
870 break;
871 case ID_EDITAUTHOR:
873 EditAuthor(selEntries);
875 break;
876 case ID_REVPROPS:
878 CEditPropertiesDlg dlg;
879 dlg.SetProjectProperties(&m_ProjectProperties);
880 CTGitPathList escapedlist;
881 dlg.SetPathList(CTGitPathList(CTGitPath(pathURL)));
882 dlg.SetRevision(revSelected);
883 dlg.RevProps(true);
884 dlg.DoModal();
886 break;
888 case ID_EXPORT:
890 CString sCmd;
891 sCmd.Format(_T("%s /command:export /path:\"%s\" /revision:%ld"),
892 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
893 (LPCTSTR)pathURL, (LONG)revSelected);
894 CAppUtils::LaunchApplication(sCmd, NULL, false);
896 break;
897 case ID_CHECKOUT:
899 CString sCmd;
900 CString url = _T("tgit:")+pathURL;
901 sCmd.Format(_T("%s /command:checkout /url:\"%s\" /revision:%ld"),
902 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
903 (LPCTSTR)url, (LONG)revSelected);
904 CAppUtils::LaunchApplication(sCmd, NULL, false);
906 break;
907 case ID_VIEWREV:
909 CString url = m_ProjectProperties.sWebViewerRev;
910 url = GetAbsoluteUrlFromRelativeUrl(url);
911 url.Replace(_T("%REVISION%"), revSelected.ToString());
912 if (!url.IsEmpty())
913 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
915 break;
916 case ID_VIEWPATHREV:
918 CString relurl = pathURL;
919 CString sRoot = GetRepositoryRoot(CTGitPath(relurl));
920 relurl = relurl.Mid(sRoot.GetLength());
921 CString url = m_ProjectProperties.sWebViewerPathRev;
922 url = GetAbsoluteUrlFromRelativeUrl(url);
923 url.Replace(_T("%REVISION%"), revSelected.ToString());
924 url.Replace(_T("%PATH%"), relurl);
925 if (!url.IsEmpty())
926 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
928 break;
929 #endif
931 } // switch (cmd)
933 theApp.DoWaitCursor(-1);
936 void CGitLogList::SetSelectedAction(int action)
938 POSITION pos = GetFirstSelectedItemPosition();
939 int index;
940 while(pos)
942 index = GetNextSelectedItem(pos);
943 ((GitRev*)m_arShownList[index])->GetAction(this) = action;
944 CRect rect;
945 this->GetItemRect(index,&rect,LVIR_BOUNDS);
946 this->InvalidateRect(rect);