1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
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 // GitLogList.cpp : implementation file
23 #include "TortoiseProc.h"
24 #include "GitLogList.h"
26 //#include "VssStyle.h"
32 #include "SVNProgressDlg.h"
33 #include "ProgressDlg.h"
34 #include "SysProgressDlg.h"
35 //#include "RepositoryBrowser.h"
36 //#include "CopyDlg.h"
37 //#include "StatGraphDlg.h"
39 #include "MessageBox.h"
42 #include "PathUtils.h"
43 #include "StringUtils.h"
44 #include "UnicodeUtils.h"
46 //#include "GitInfo.h"
47 //#include "GitDiff.h"
48 //#include "RevisionRangeDlg.h"
49 //#include "BrowseFolder.h"
50 //#include "BlameDlg.h"
52 //#include "GitHelpers.h"
53 #include "GitStatus.h"
54 //#include "LogDlgHelper.h"
55 //#include "CachedLogInfo.h"
56 //#include "RepositoryInfo.h"
57 //#include "EditPropertiesDlg.h"
58 #include "FileDiffDlg.h"
59 #include "CommitDlg.h"
60 #include "RebaseDlg.h"
63 IMPLEMENT_DYNAMIC(CGitLogList
, CHintListCtrl
)
65 int CGitLogList::RevertSelectedCommits()
67 CSysProgressDlg progress
;
71 if(!g_Git
.CheckCleanWorkTree())
73 CMessageBox::Show(NULL
,_T("Revert requires a clean working tree"),_T("TortoiseGit"),MB_OK
);
78 if (progress
.IsValid() && (this->GetSelectedCount() > 1) )
80 progress
.SetTitle(_T("Revert Commit"));
81 progress
.SetAnimation(IDR_MOVEANI
);
82 progress
.SetTime(true);
83 progress
.ShowModeless(this);
86 POSITION pos
= GetFirstSelectedItemPosition();
90 int index
= GetNextSelectedItem(pos
);
91 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(index
));
93 if (progress
.IsValid() && (this->GetSelectedCount() > 1) )
95 progress
.FormatPathLine(1, _T("Revert %s"), r1
->m_CommitHash
.ToString());
96 progress
.FormatPathLine(2, _T("%s"), r1
->GetSubject());
97 progress
.SetProgress(i
, this->GetSelectedCount());
101 if(r1
->m_CommitHash
.IsEmpty())
105 cmd
.Format(_T("git.exe revert --no-edit --no-commit %s"), r1
->m_CommitHash
.ToString());
106 if(g_Git
.Run(cmd
, &output
, CP_ACP
))
109 str
=_T("Revert fail\n");
111 str
+= _T("\n")+output
;
112 if( GetSelectedCount() == 1)
113 CMessageBox::Show(NULL
,str
, _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
116 if(CMessageBox::Show(NULL
, str
, _T("TortoiseGit"),2 , IDI_ERROR
, _T("&Skip"), _T("&Abort")) == 2)
127 if ((progress
.IsValid())&&(progress
.HasUserCancelled()))
132 int CGitLogList::CherryPickFrom(CString from
, CString to
)
134 CLogDataVector
logs(&m_LogCache
);
135 if(logs
.ParserFromLog(NULL
,-1,0,&from
,&to
))
141 CSysProgressDlg progress
;
142 if (progress
.IsValid())
144 progress
.SetTitle(_T("Cherry Pick"));
145 progress
.SetAnimation(IDR_MOVEANI
);
146 progress
.SetTime(true);
147 progress
.ShowModeless(this);
150 for(int i
=logs
.size()-1;i
>=0;i
--)
152 if (progress
.IsValid())
154 progress
.FormatPathLine(1, _T("Pick up %s"), logs
.GetGitRevAt(i
).m_CommitHash
.ToString());
155 progress
.FormatPathLine(2, _T("%s"), logs
.GetGitRevAt(i
).GetSubject());
156 progress
.SetProgress(logs
.size()-i
, logs
.size());
158 if ((progress
.IsValid())&&(progress
.HasUserCancelled()))
160 //CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
161 throw std::exception(CUnicodeUtils::GetUTF8(_T("User canceled\r\n\r\n")));
165 cmd
.Format(_T("git.exe cherry-pick %s"),logs
.GetGitRevAt(i
).m_CommitHash
.ToString());
167 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
169 throw std::exception(CUnicodeUtils::GetUTF8(CString(_T("Cherry Pick Failure\r\n\r\n"))+out
));
177 void CGitLogList::ContextMenuAction(int cmd
,int FirstSelect
, int LastSelect
, CMenu
*popmenu
)
179 POSITION pos
= GetFirstSelectedItemPosition();
180 int indexNext
= GetNextSelectedItem(pos
);
184 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(indexNext
));
186 theApp
.DoWaitCursor(1);
191 CTGitPathList pathlist
;
192 CTGitPathList selectedlist
;
193 pathlist
.AddPath(this->m_Path
);
194 bool bSelectFilesForCommit
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
196 CAppUtils::Commit(CString(),false,str
,
197 pathlist
,selectedlist
,bSelectFilesForCommit
);
199 this->GetParent()->PostMessage(WM_COMMAND
,ID_LOGDLG_REFRESH
,0);
204 CString tempfile
=GetTempFile();
206 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
207 if(!r1
->m_CommitHash
.IsEmpty())
212 if( (cmd
&0xFFFF) == 0xFFFF)
216 else if((cmd
&0xFFFF) == 0xFFFE)
222 if(cmd
> r1
->m_ParentHash
.size())
225 str
.Format(_T("Parent %d does not exist"), cmd
);
226 CMessageBox::Show(NULL
,str
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
232 hash2
= r1
->m_ParentHash
[cmd
-1].ToString();
235 command
.Format(_T("git.exe diff-tree %s -r -p --stat %s %s"), merge
, hash2
, r1
->m_CommitHash
.ToString());
238 command
.Format(_T("git.exe diff -r -p --stat"));
240 g_Git
.RunLogFile(command
,tempfile
);
241 CAppUtils::StartUnifiedDiffViewer(tempfile
,r1
->m_CommitHash
.ToString().Left(6)+_T(":")+r1
->GetSubject());
247 CString tempfile
=GetTempFile();
249 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
250 GitRev
* r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
252 if( r1
->m_CommitHash
.IsEmpty()) {
253 cmd
.Format(_T("git.exe diff -r -p --stat %s"),r2
->m_CommitHash
.ToString());
255 else if( r2
->m_CommitHash
.IsEmpty()) {
256 cmd
.Format(_T("git.exe diff -r -p --stat %s"),r1
->m_CommitHash
.ToString());
260 cmd
.Format(_T("git.exe diff-tree -r -p --stat %s %s"),r2
->m_CommitHash
.ToString(),r1
->m_CommitHash
.ToString());
263 g_Git
.RunLogFile(cmd
,tempfile
);
264 CAppUtils::StartUnifiedDiffViewer(tempfile
,r2
->m_CommitHash
.ToString().Left(6)+_T(":")+r1
->m_CommitHash
.ToString().Left(6));
271 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
272 GitRev
* r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
273 CGitDiff::DiffCommit(this->m_Path
, r1
,r2
);
280 GitRev
* r1
= &m_wcRev
;
281 GitRev
* r2
= pSelLogEntry
;
283 CGitDiff::DiffCommit(this->m_Path
, r1
,r2
);
285 //user clicked on the menu item "compare with working copy"
288 // GitDiff diff(this, m_hWnd, true);
289 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
290 // diff.SetHEADPeg(m_LogRevision);
291 // diff.ShowCompare(m_path, GitRev::REV_WC, m_path, revSelected);
294 // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
298 case ID_COMPAREWITHPREVIOUS
:
303 if(pSelLogEntry
->m_ParentHash
.size()>0)
304 //if(m_logEntries.m_HashMap[pSelLogEntry->m_ParentHash[0]]>=0)
312 CGitDiff::DiffCommit(this->m_Path
, pSelLogEntry
->m_CommitHash
.ToString(),pSelLogEntry
->m_ParentHash
[cmd
-1].ToString());
317 CMessageBox::Show(NULL
,_T("No previous version"),_T("TortoiseGit"),MB_OK
);
321 // GitDiff diff(this, m_hWnd, true);
322 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
323 // diff.SetHEADPeg(m_LogRevision);
324 // diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected);
327 // CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
330 case ID_COPYCLIPBOARD
:
332 CopySelectionToClipBoard();
337 CopySelectionToClipBoard(TRUE
);
342 CString str
=pSelLogEntry
->m_CommitHash
.ToString();
343 CAppUtils::Export(&str
);
346 case ID_CREATE_BRANCH
:
348 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
349 CAppUtils::CreateBranchTag(FALSE
,&str
);
356 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
357 CAppUtils::CreateBranchTag(TRUE
,&str
);
360 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
365 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
366 CAppUtils::Switch(&str
);
370 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
372 case ID_SWITCHBRANCH
:
375 CString
*branch
= (CString
*)((CIconMenu
*)popmenu
)->GetMenuItemData(cmd
);
379 CProgressDlg progress
;
381 if(branch
->Find(_T("refs/heads/")) ==0 )
382 name
= branch
->Mid(11);
386 progress
.m_GitCmd
.Format(_T("git.exe checkout %s"), name
.GetString());
391 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
396 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
397 CAppUtils::GitReset(&str
);
403 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
406 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
408 case ID_REBASE_SQUASH
:
409 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
412 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP
);
414 case ID_COMBINE_COMMIT
:
418 CGitHash hashFirst
,hashLast
;
420 int headindex
=GetHeadIndex();
421 if(headindex
>=0) //incase show all branch, head is not the first commits.
423 head
.Format(_T("HEAD~%d"),FirstSelect
-headindex
);
424 hashFirst
=g_Git
.GetHash(head
);
426 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
427 hashLast
=g_Git
.GetHash(head
);
430 GitRev
* pFirstEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
431 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
432 if(pFirstEntry
->m_CommitHash
!= hashFirst
|| pLastEntry
->m_CommitHash
!= hashLast
)
434 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
);
438 headhash
=g_Git
.GetHash(_T("HEAD"));
440 if(!g_Git
.CheckCleanWorkTree())
442 CMessageBox::Show(NULL
,_T("Combine needs a clean work tree"),_T("TortoiseGit"),MB_OK
);
447 //Use throw to abort this process (reset back to original HEAD)
450 cmd
.Format(_T("git.exe reset --hard %s"),pFirstEntry
->m_CommitHash
.ToString());
451 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
453 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
454 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to first commit (first step) aborting...\r\n\r\n")+out
));
456 cmd
.Format(_T("git.exe reset --mixed %s"),hashLast
.ToString());
457 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
459 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
460 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to last commit (second step) aborting...\r\n\r\n")+out
));
463 CTGitPathList PathList
;
464 /* don't why must add --stat to get action status*/
465 /* first -z will be omitted by gitdll*/
466 if(g_Git
.GetDiffPath(&PathList
,&pFirstEntry
->m_CommitHash
,&hashLast
,"-z --stat -r"))
468 CMessageBox::Show(NULL
,_T("Get Diff file list error"),_T("TortoiseGit"),MB_OK
);
469 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not get changed file list aborting...\r\n\r\n")+out
));
472 for(int i
=0;i
<PathList
.GetCount();i
++)
474 if(PathList
[i
].m_Action
& CTGitPath::LOGACTIONS_ADDED
)
476 cmd
.Format(_T("git.exe add -- \"%s\""), PathList
[i
].GetGitPathString());
477 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
479 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
480 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not add new file aborting...\r\n\r\n")+out
));
484 if(PathList
[i
].m_Action
& CTGitPath::LOGACTIONS_DELETED
)
486 cmd
.Format(_T("git.exe rm -- \"%s\""), PathList
[i
].GetGitPathString());
487 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
489 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
490 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not rm file aborting...\r\n\r\n")+out
));
496 for(int i
=FirstSelect
;i
<=LastSelect
;i
++)
498 GitRev
* pRev
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(i
));
499 dlg
.m_sLogMessage
+=pRev
->GetSubject()+_T("\n")+pRev
->GetBody();
500 dlg
.m_sLogMessage
+=_T("\n");
502 dlg
.m_bWholeProject
=true;
503 dlg
.m_bSelectFilesForCommit
= true;
504 dlg
.m_bCommitAmend
=true;
505 dlg
.m_bNoPostActions
=true;
506 dlg
.m_AmendStr
=dlg
.m_sLogMessage
;
508 if (dlg
.DoModal() == IDOK
)
510 if(pFirstEntry
->m_CommitHash
!=headhash
)
512 //Commitrange firstEntry..headhash (from top of combine to original head) needs to be 'cherry-picked'
513 //on top of new commit.
514 //Use the rebase --onto command for it.
516 //All this can be done in one step using the following command:
517 //cmd.Format(_T("git.exe format-patch --stdout --binary --full-index -k %s..%s | git am -k -3"),
518 // pFirstEntry->m_CommitHash,
520 //But I am not sure if a '|' is going to work in a CreateProcess() call.
522 //Later the progress dialog could be used to execute these steps.
524 if(CherryPickFrom(pFirstEntry
->m_CommitHash
.ToString(),headhash
))
527 msg
.Format(_T("Error while cherry pick commits on top of combined commits. Aborting.\r\n\r\n"));
528 throw std::exception(CUnicodeUtils::GetUTF8(msg
));
531 CString currentBranch
=g_Git
.GetCurrentBranch();
532 cmd
.Format(_T("git.exe rebase --onto \"%s\" %s %s"),
534 pFirstEntry
->m_CommitHash
,
536 if(g_Git
.Run(cmd
,&out
,CP_UTF8
)!=0)
539 msg
.Format(_T("Error while rebasing commits on top of combined commits. Aborting.\r\n\r\n%s"),out
);
540 // CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK);
541 g_Git
.Run(_T("git.exe rebase --abort"),&out
,CP_UTF8
);
542 throw std::exception(CUnicodeUtils::GetUTF8(msg
));
545 //HEAD is now on <no branch>.
546 //The following steps are to get HEAD back on the original branch and reset the branch to the new HEAD
547 //To avoid 2 working copy changes, we could use git branch -f <original branch> <hash new head>
548 //And then git checkout <original branch>
549 //But I don't know if 'git branch -f' removes tracking options. So for now, do a checkout and a reset.
552 CString newHead
=g_Git
.GetHash(CString(_T("HEAD")));
554 //Checkout working branch
555 cmd
.Format(_T("git.exe checkout -f \"%s\""),currentBranch
);
556 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
557 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not checkout original branch. Aborting...\r\n\r\n")+out
));
560 cmd
.Format(_T("git.exe reset --hard %s"),newHead
);
561 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
562 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to new head. Aborting...\r\n\r\n")+out
));
567 throw std::exception("User aborted the combine process");
569 catch(std::exception
& e
)
571 CMessageBox::Show(NULL
,CUnicodeUtils::GetUnicode(CStringA(e
.what())),_T("TortoiseGit: Combine error"),MB_OK
|MB_ICONERROR
);
572 cmd
.Format(_T("git.exe reset --hard %s"),headhash
.ToString());
574 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
576 CMessageBox::Show(NULL
,_T("Could not reset to original HEAD\r\n\r\n")+out
,_T("TortoiseGit"),MB_OK
);
584 if(!g_Git
.CheckCleanWorkTree())
586 CMessageBox::Show(NULL
,_T("Cherry Pick requires a clean working tree"),_T("TortoiseGit"),MB_OK
);
592 dlg
.m_IsCherryPick
= TRUE
;
593 dlg
.m_Upstream
= this->m_CurrentBranch
;
594 POSITION pos
= GetFirstSelectedItemPosition();
597 int indexNext
= GetNextSelectedItem(pos
);
598 dlg
.m_CommitList
.m_logEntries
.push_back( ((GitRev
*)m_arShownList
[indexNext
])->m_CommitHash
);
599 dlg
.m_CommitList
.m_LogCache
.m_HashMap
[((GitRev
*)m_arShownList
[indexNext
])->m_CommitHash
]=*(GitRev
*)m_arShownList
[indexNext
];
600 dlg
.m_CommitList
.m_logEntries
.GetGitRevAt(dlg
.m_CommitList
.m_logEntries
.size()-1).GetAction(this) |= CTGitPath::LOGACTIONS_REBASE_PICK
;
603 if(dlg
.DoModal() == IDOK
)
609 case ID_REBASE_TO_VERSION
:
610 if(!g_Git
.CheckCleanWorkTree())
612 CMessageBox::Show(NULL
,_T("Rebase requires a clean working tree"),_T("TortoiseGit"),MB_OK
);
618 dlg
.m_Upstream
= pSelLogEntry
->m_CommitHash
;
620 if(dlg
.DoModal() == IDOK
)
629 CAppUtils::StashApply(pSelLogEntry
->m_Ref
);
635 str
.Format(_T("Warning: %s will be permanently deleted. It can <ct=0x0000FF><b>NOT</b></ct> be recovered!\r\n\r\nDo you really want to continue?"),pSelLogEntry
->m_Ref
);
636 if(CMessageBox::Show(NULL
, str
, _T("TortoiseGit"), 1, IDI_QUESTION
, _T("&Delete"), _T("&Abort")) == 1)
639 cmd
.Format(_T("git.exe reflog delete %s"),pSelLogEntry
->m_Ref
);
640 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
642 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
644 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
651 cmd
= CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
652 cmd
+= _T(" /command:log");
653 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\" ");
654 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
655 cmd
+= _T(" /endrev:")+r1
->m_CommitHash
.ToString();
656 CAppUtils::LaunchApplication(cmd
,IDS_ERR_PROC
,false);
659 case ID_CREATE_PATCH
:
661 int select
=this->GetSelectedCount();
663 cmd
= CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
664 cmd
+= _T(" /command:formatpatch");
666 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\" ");
668 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
672 cmd
+= _T(" /startrev:")+r1
->m_CommitHash
.ToString();
676 r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
677 if( this->m_IsOldFirst
)
679 cmd
+= _T(" /startrev:")+r1
->m_CommitHash
.ToString()+_T("~1");
680 cmd
+= _T(" /endrev:")+r2
->m_CommitHash
.ToString();
685 cmd
+= _T(" /startrev:")+r2
->m_CommitHash
.ToString()+_T("~1");
686 cmd
+= _T(" /endrev:")+r1
->m_CommitHash
.ToString();
691 CAppUtils::LaunchApplication(cmd
,IDS_ERR_PROC
,false);
696 CString guessAssociatedBranch
;
697 if (m_HashMap
[pSelLogEntry
->m_CommitHash
].size() > 0)
698 guessAssociatedBranch
= m_HashMap
[pSelLogEntry
->m_CommitHash
].at(0);
699 if (CAppUtils::Push(guessAssociatedBranch
))
706 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) == m_HashMap
.end() )
708 CMessageBox::Show(NULL
,IDS_ERROR_NOREF
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
711 if( index
>= m_HashMap
[pSelLogEntry
->m_CommitHash
].size())
713 CMessageBox::Show(NULL
,IDS_ERROR_INDEX
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
717 ref
=m_HashMap
[pSelLogEntry
->m_CommitHash
][index
];
719 msg
=CString(_T("Do you really want to <ct=0x0000FF>delete</ct> <b>"))+ref
;
721 if( CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, _T("&Delete"), _T("&Abort")) == 1 )
725 if(this->GetShortName(ref
,shortname
,_T("refs/heads/")))
727 cmd
.Format(_T("git.exe branch -D -- %s"),shortname
);
730 if(this->GetShortName(ref
,shortname
,_T("refs/remotes/")))
732 cmd
.Format(_T("git.exe branch -r -D -- %s"),shortname
);
735 if(this->GetShortName(ref
,shortname
,_T("refs/tags/")))
737 cmd
.Format(_T("git.exe tag -d -- %s"),shortname
);
740 if(this->GetShortName(ref
,shortname
,_T("refs/stash")))
742 if(CMessageBox::Show(NULL
, _T("<ct=0x0000FF>Do you really want to delete <b>ALL</b> stash?</ct>"),
743 _T("TortoiseGit"), 2, IDI_QUESTION
, _T("&Delete"), _T("&Abort")) == 1)
744 cmd
.Format(_T("git.exe stash clear"));
750 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
752 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
754 this->ReloadHashMap();
756 this->GetItemRect(FirstSelect
,&rect
,LVIR_BOUNDS
);
757 this->InvalidateRect(rect
);
764 m_nSearchIndex
= GetSelectionMark();
765 if (m_nSearchIndex
< 0)
773 m_pFindDialog
= new CFindDlg();
774 m_pFindDialog
->Create(this);
780 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
781 if (m_HashMap
[pSelLogEntry
->m_CommitHash
].size() > 0)
782 str
= m_HashMap
[pSelLogEntry
->m_CommitHash
].at(0);
783 // we need an URL to complete this command, so error out if we can't get an URL
784 if(CAppUtils::Merge(&str
))
792 if(!this->RevertSelectedCommits())
798 CAppUtils::EditNote(pSelLogEntry
);
799 this->SetItemState(FirstSelect
, 0, LVIS_SELECTED
);
800 this->SetItemState(FirstSelect
, LVIS_SELECTED
, LVIS_SELECTED
);
804 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
808 case ID_BLAMECOMPARE
:
810 //user clicked on the menu item "compare with working copy"
811 //now first get the revision which is selected
814 GitDiff
diff(this, this->m_hWnd
, true);
815 diff
.SetHEADPeg(m_LogRevision
);
816 diff
.ShowCompare(m_path
, GitRev::REV_BASE
, m_path
, revSelected
, GitRev(), false, true);
819 CAppUtils::StartShowCompare(m_hWnd
, m_path
, GitRev::REV_BASE
, m_path
, revSelected
, GitRev(), m_LogRevision
, false, false, true);
824 //user clicked on the menu item "compare and blame revisions"
827 GitDiff
diff(this, this->m_hWnd
, true);
828 diff
.SetHEADPeg(m_LogRevision
);
829 diff
.ShowCompare(CTGitPath(pathURL
), revSelected2
, CTGitPath(pathURL
), revSelected
, GitRev(), false, true);
832 CAppUtils::StartShowCompare(m_hWnd
, CTGitPath(pathURL
), revSelected2
, CTGitPath(pathURL
), revSelected
, GitRev(), m_LogRevision
, false, false, true);
835 case ID_BLAMEWITHPREVIOUS
:
837 //user clicked on the menu item "Compare and Blame with previous revision"
840 GitDiff
diff(this, this->m_hWnd
, true);
841 diff
.SetHEADPeg(m_LogRevision
);
842 diff
.ShowCompare(CTGitPath(pathURL
), revPrevious
, CTGitPath(pathURL
), revSelected
, GitRev(), false, true);
845 CAppUtils::StartShowCompare(m_hWnd
, CTGitPath(pathURL
), revPrevious
, CTGitPath(pathURL
), revSelected
, GitRev(), m_LogRevision
, false, false, true);
853 CProgressDlg progDlg
;
854 progDlg
.SetTitle(IDS_APPNAME
);
855 progDlg
.SetAnimation(IDR_DOWNLOAD
);
857 sInfoLine
.Format(IDS_PROGRESSGETFILEREVISION
, m_path
.GetWinPath(), (LPCTSTR
)revSelected
.ToString());
858 progDlg
.SetLine(1, sInfoLine
, true);
859 SetAndClearProgressInfo(&progDlg
);
860 progDlg
.ShowModeless(m_hWnd
);
861 CTGitPath tempfile
= CTempFiles::Instance().GetTempFilePath(false, m_path
, revSelected
);
862 bool bSuccess
= true;
863 if (!Cat(m_path
, GitRev(GitRev::REV_HEAD
), revSelected
, tempfile
))
866 // try again, but with the selected revision as the peg revision
867 if (!Cat(m_path
, revSelected
, revSelected
, tempfile
))
870 SetAndClearProgressInfo((HWND
)NULL
);
871 CMessageBox::Show(this->m_hWnd
, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
880 SetAndClearProgressInfo((HWND
)NULL
);
881 SetFileAttributes(tempfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
884 ret
= (int)ShellExecute(this->m_hWnd
, NULL
, tempfile
.GetWinPath(), NULL
, NULL
, SW_SHOWNORMAL
);
885 if ((ret
<= HINSTANCE_ERROR
)||bOpenWith
)
887 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
888 cmd
+= tempfile
.GetWinPathString() + _T(" ");
889 CAppUtils::LaunchApplication(cmd
, NULL
, false);
897 dlg
.EndRev
= revSelected
;
898 if (dlg
.DoModal() == IDOK
)
903 tempfile
= blame
.BlameToTempFile(m_path
, dlg
.StartRev
, dlg
.EndRev
, dlg
.EndRev
, logfile
, _T(""), dlg
.m_bIncludeMerge
, TRUE
, TRUE
);
904 if (!tempfile
.IsEmpty())
908 //open the default text editor for the result file
909 CAppUtils::StartTextViewer(tempfile
);
913 CString sParams
= _T("/path:\"") + m_path
.GetGitPathString() + _T("\" ");
914 if(!CAppUtils::LaunchTortoiseBlame(tempfile
, logfile
, CPathUtils::GetFileNameFromPath(m_path
.GetFileOrDirectoryName()),sParams
))
922 CMessageBox::Show(this->m_hWnd
, blame
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
930 CString url
= _T("tgit:")+pathURL
;
931 sCmd
.Format(_T("%s /command:update /path:\"%s\" /rev:%ld"),
932 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
933 (LPCTSTR
)m_path
.GetWinPath(), (LONG
)revSelected
);
934 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
940 EditLogMessage(selIndex
);
945 EditAuthor(selEntries
);
950 CEditPropertiesDlg dlg
;
951 dlg
.SetProjectProperties(&m_ProjectProperties
);
952 CTGitPathList escapedlist
;
953 dlg
.SetPathList(CTGitPathList(CTGitPath(pathURL
)));
954 dlg
.SetRevision(revSelected
);
963 sCmd
.Format(_T("%s /command:export /path:\"%s\" /revision:%ld"),
964 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
965 (LPCTSTR
)pathURL
, (LONG
)revSelected
);
966 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
971 CString url
= m_ProjectProperties
.sWebViewerRev
;
972 url
= GetAbsoluteUrlFromRelativeUrl(url
);
973 url
.Replace(_T("%REVISION%"), revSelected
.ToString());
975 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
980 CString relurl
= pathURL
;
981 CString sRoot
= GetRepositoryRoot(CTGitPath(relurl
));
982 relurl
= relurl
.Mid(sRoot
.GetLength());
983 CString url
= m_ProjectProperties
.sWebViewerPathRev
;
984 url
= GetAbsoluteUrlFromRelativeUrl(url
);
985 url
.Replace(_T("%REVISION%"), revSelected
.ToString());
986 url
.Replace(_T("%PATH%"), relurl
);
988 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
995 theApp
.DoWaitCursor(-1);
998 void CGitLogList::SetSelectedAction(int action
)
1000 POSITION pos
= GetFirstSelectedItemPosition();
1004 index
= GetNextSelectedItem(pos
);
1005 ((GitRev
*)m_arShownList
[index
])->GetAction(this) = action
;
1007 this->GetItemRect(index
,&rect
,LVIR_BOUNDS
);
1008 this->InvalidateRect(rect
);
1012 void CGitLogList::ShiftSelectedAction()
1014 POSITION pos
= GetFirstSelectedItemPosition();
1018 index
= GetNextSelectedItem(pos
);
1019 int action
= ((GitRev
*)m_arShownList
[index
])->GetAction(this);
1022 case CTGitPath::LOGACTIONS_REBASE_PICK
:
1023 action
= CTGitPath::LOGACTIONS_REBASE_SKIP
;
1025 case CTGitPath::LOGACTIONS_REBASE_SKIP
:
1026 action
= CTGitPath::LOGACTIONS_REBASE_EDIT
;
1028 case CTGitPath::LOGACTIONS_REBASE_EDIT
:
1029 action
= CTGitPath::LOGACTIONS_REBASE_SQUASH
;
1031 case CTGitPath::LOGACTIONS_REBASE_SQUASH
:
1032 action
= CTGitPath::LOGACTIONS_REBASE_PICK
;
1035 ((GitRev
*)m_arShownList
[index
])->GetAction(this) = action
;
1037 this->GetItemRect(index
, &rect
, LVIR_BOUNDS
);
1038 this->InvalidateRect(rect
);