1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2011-2012 - Sven Strickroth <email@cs-ware.de>
5 // Copyright (C) 2005-2007 Marco Costalba
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // GitLogList.cpp : implementation file
24 #include "TortoiseProc.h"
25 #include "GitLogList.h"
27 //#include "VssStyle.h"
32 #include "GITProgressDlg.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"
62 #include "../TGitCache/CacheInterface.h"
64 IMPLEMENT_DYNAMIC(CGitLogList
, CHintListCtrl
)
66 int CGitLogList::RevertSelectedCommits(int parent
)
68 CSysProgressDlg progress
;
72 if(!g_Git
.CheckCleanWorkTree())
74 CMessageBox::Show(NULL
, IDS_PROC_NOCLEAN
, IDS_APPNAME
, MB_OK
);
79 if (progress
.IsValid() && (this->GetSelectedCount() > 1) )
81 progress
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_REVERTCOMMIT
)));
82 progress
.SetAnimation(IDR_MOVEANI
);
83 progress
.SetTime(true);
84 progress
.ShowModeless(this);
87 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
89 POSITION pos
= GetFirstSelectedItemPosition();
93 int index
= GetNextSelectedItem(pos
);
94 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(index
));
96 if (progress
.IsValid() && (this->GetSelectedCount() > 1) )
98 progress
.FormatNonPathLine(1, IDS_PROC_REVERTCOMMIT
, r1
->m_CommitHash
.ToString());
99 progress
.FormatNonPathLine(2, _T("%s"), r1
->GetSubject());
100 progress
.SetProgress(i
, this->GetSelectedCount());
104 if(r1
->m_CommitHash
.IsEmpty())
107 CString cmd
, output
, merge
;
109 merge
.Format(_T("-m %d "), parent
);
110 cmd
.Format(_T("git.exe revert --no-edit --no-commit %s%s"), merge
, r1
->m_CommitHash
.ToString());
111 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
114 str
.LoadString(IDS_SVNACTION_FAILEDREVERT
);
117 str
+= _T("\n")+output
;
118 if( GetSelectedCount() == 1)
119 CMessageBox::Show(NULL
, str
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
122 if(CMessageBox::Show(NULL
, str
, _T("TortoiseGit"),2 , IDI_ERROR
, CString(MAKEINTRESOURCE(IDS_SKIPBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
133 if ((progress
.IsValid())&&(progress
.HasUserCancelled()))
138 int CGitLogList::CherryPickFrom(CString from
, CString to
)
140 CLogDataVector
logs(&m_LogCache
);
141 if(logs
.ParserFromLog(NULL
,-1,0,&from
,&to
))
147 CSysProgressDlg progress
;
148 if (progress
.IsValid())
150 progress
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CHERRYPICK
)));
151 progress
.SetAnimation(IDR_MOVEANI
);
152 progress
.SetTime(true);
153 progress
.ShowModeless(this);
156 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
158 for (int i
= (int)logs
.size() - 1; i
>= 0; i
--)
160 if (progress
.IsValid())
163 temp
.Format(IDS_PROC_PICK
, logs
.GetGitRevAt(i
).m_CommitHash
.ToString());
164 progress
.FormatPathLine(1, temp
);
165 progress
.FormatPathLine(2, _T("%s"), logs
.GetGitRevAt(i
).GetSubject());
166 progress
.SetProgress(logs
.size()-i
, logs
.size());
168 if ((progress
.IsValid())&&(progress
.HasUserCancelled()))
170 throw std::exception(CUnicodeUtils::GetUTF8(CString(MAKEINTRESOURCE(IDS_SVN_USERCANCELLED
))));
174 cmd
.Format(_T("git.exe cherry-pick %s"),logs
.GetGitRevAt(i
).m_CommitHash
.ToString());
176 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
178 throw std::exception(CUnicodeUtils::GetUTF8(CString(MAKEINTRESOURCE(IDS_PROC_CHERRYPICKFAILED
)) + _T(":\r\n\r\n") + out
));
186 void CGitLogList::ContextMenuAction(int cmd
,int FirstSelect
, int LastSelect
, CMenu
*popmenu
)
188 POSITION pos
= GetFirstSelectedItemPosition();
189 int indexNext
= GetNextSelectedItem(pos
);
193 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(indexNext
));
195 theApp
.DoWaitCursor(1);
200 CTGitPathList pathlist
;
201 CTGitPathList selectedlist
;
202 pathlist
.AddPath(this->m_Path
);
203 bool bSelectFilesForCommit
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
205 CAppUtils::Commit(CString(),false,str
,
206 pathlist
,selectedlist
,bSelectFilesForCommit
);
208 this->GetParent()->PostMessage(WM_COMMAND
,ID_LOGDLG_REFRESH
,0);
211 case ID_GNUDIFF1
: // compare with WC, unified
213 CString tempfile
=GetTempFile();
215 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
216 if(!r1
->m_CommitHash
.IsEmpty())
221 if( (cmd
&0xFFFF) == 0xFFFF)
225 else if((cmd
&0xFFFF) == 0xFFFE)
231 if(cmd
> r1
->m_ParentHash
.size())
234 str
.Format(IDS_PROC_NOPARENT
, cmd
);
235 MessageBox(str
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
241 hash2
= r1
->m_ParentHash
[cmd
-1].ToString();
244 command
.Format(_T("git.exe diff-tree %s -r -p --stat %s %s"), merge
, hash2
, r1
->m_CommitHash
.ToString());
247 command
.Format(_T("git.exe diff -r -p --stat"));
249 g_Git
.RunLogFile(command
,tempfile
);
250 CAppUtils::StartUnifiedDiffViewer(tempfile
, r1
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength()) + _T(":") + r1
->GetSubject());
254 case ID_GNUDIFF2
: // compare two revisions, unified
256 CString tempfile
=GetTempFile();
258 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
259 GitRev
* r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
261 if( r1
->m_CommitHash
.IsEmpty()) {
262 cmd
.Format(_T("git.exe diff -r -p --stat %s"),r2
->m_CommitHash
.ToString());
264 else if( r2
->m_CommitHash
.IsEmpty()) {
265 cmd
.Format(_T("git.exe diff -r -p --stat %s"),r1
->m_CommitHash
.ToString());
269 cmd
.Format(_T("git.exe diff-tree -r -p --stat %s %s"),r2
->m_CommitHash
.ToString(),r1
->m_CommitHash
.ToString());
272 g_Git
.RunLogFile(cmd
,tempfile
);
273 CAppUtils::StartUnifiedDiffViewer(tempfile
, r2
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength()) + _T(":") + r1
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength()));
278 case ID_COMPARETWO
: // compare two revisions
280 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
281 GitRev
* r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
282 if (m_Path
.IsDirectory() || !(m_ShowMask
& CGit::LOG_INFO_FOLLOW
))
283 CGitDiff::DiffCommit(this->m_Path
, r1
,r2
);
286 CString path1
= m_Path
.GetGitPathString();
287 // start with 1 (0 = working copy changes)
288 for (int i
= 1; i
< FirstSelect
; i
++)
290 GitRev
* first
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(i
));
291 CTGitPathList list
= first
->GetFiles(NULL
);
292 CTGitPath
* file
= list
.LookForGitPath(path1
);
293 if (file
&& !file
->GetGitOldPathString().IsEmpty())
294 path1
= file
->GetGitOldPathString();
296 CString path2
= path1
;
297 for (int i
= FirstSelect
; i
< LastSelect
; i
++)
299 GitRev
* first
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(i
));
300 CTGitPathList list
= first
->GetFiles(NULL
);
301 CTGitPath
* file
= list
.LookForGitPath(path2
);
302 if (file
&& !file
->GetGitOldPathString().IsEmpty())
303 path2
= file
->GetGitOldPathString();
305 CGitDiff::DiffCommit(CTGitPath(path1
), CTGitPath(path2
), r1
, r2
);
311 case ID_COMPARE
: // compare revision with WC
313 GitRev
* r1
= &m_wcRev
;
314 GitRev
* r2
= pSelLogEntry
;
316 if (m_Path
.IsDirectory() || !(m_ShowMask
& CGit::LOG_INFO_FOLLOW
))
317 CGitDiff::DiffCommit(this->m_Path
, r1
,r2
);
320 CString path1
= m_Path
.GetGitPathString();
321 // start with 1 (0 = working copy changes)
322 for (int i
= 1; i
< FirstSelect
; i
++)
324 GitRev
* first
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(i
));
325 CTGitPathList list
= first
->GetFiles(NULL
);
326 CTGitPath
* file
= list
.LookForGitPath(path1
);
327 if (file
&& !file
->GetGitOldPathString().IsEmpty())
328 path1
= file
->GetGitOldPathString();
330 CGitDiff::DiffCommit(m_Path
, CTGitPath(path1
), r1
, r2
);
333 //user clicked on the menu item "compare with working copy"
336 // GitDiff diff(this, m_hWnd, true);
337 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
338 // diff.SetHEADPeg(m_LogRevision);
339 // diff.ShowCompare(m_path, GitRev::REV_WC, m_path, revSelected);
342 // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
346 case ID_COMPAREWITHPREVIOUS
:
350 if (!pSelLogEntry
->m_ParentHash
.empty())
351 //if(m_logEntries.m_HashMap[pSelLogEntry->m_ParentHash[0]]>=0)
359 if (m_Path
.IsDirectory() || !(m_ShowMask
& CGit::LOG_INFO_FOLLOW
))
360 CGitDiff::DiffCommit(m_Path
, pSelLogEntry
->m_CommitHash
.ToString(), pSelLogEntry
->m_ParentHash
[cmd
- 1].ToString());
363 CString path1
= m_Path
.GetGitPathString();
364 // start with 1 (0 = working copy changes)
365 for (int i
= 1; i
< indexNext
; i
++)
367 GitRev
* first
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(i
));
368 CTGitPathList list
= first
->GetFiles(NULL
);
369 CTGitPath
* file
= list
.LookForGitPath(path1
);
370 if (file
&& !file
->GetGitOldPathString().IsEmpty())
371 path1
= file
->GetGitOldPathString();
373 CString path2
= path1
;
374 GitRev
* first
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(indexNext
));
375 CTGitPathList list
= first
->GetFiles(NULL
);
376 CTGitPath
* file
= list
.LookForGitPath(path2
);
377 if (file
&& !file
->GetGitOldPathString().IsEmpty())
378 path2
= file
->GetGitOldPathString();
380 CGitDiff::DiffCommit(CTGitPath(path1
), CTGitPath(path2
), pSelLogEntry
->m_CommitHash
.ToString(), pSelLogEntry
->m_ParentHash
[cmd
- 1].ToString());
385 CMessageBox::Show(NULL
, IDS_PROC_NOPREVIOUSVERSION
, IDS_APPNAME
, MB_OK
);
389 // GitDiff diff(this, m_hWnd, true);
390 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
391 // diff.SetHEADPeg(m_LogRevision);
392 // diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected);
395 // CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
398 case ID_COPYCLIPBOARD
:
400 CopySelectionToClipBoard();
403 case ID_COPYCLIPBOARDMESSAGES
:
405 if ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0)
406 CopySelectionToClipBoard(ID_COPY_SUBJECT
);
408 CopySelectionToClipBoard(ID_COPY_MESSAGE
);
413 CopySelectionToClipBoard(ID_COPY_HASH
);
418 CString str
=pSelLogEntry
->m_CommitHash
.ToString();
419 CAppUtils::Export(&str
);
422 case ID_CREATE_BRANCH
:
425 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
426 // try to guess remote branch in order to enable tracking
427 for (int i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
429 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/remotes/")) == 0)
431 str
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
435 CAppUtils::CreateBranchTag((cmd
&0xFFFF) == ID_CREATE_TAG
, &str
);
438 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
443 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
444 // try to guess remote branch in order to recommend good branch name and tracking
445 for (int i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
447 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/remotes/")) == 0)
449 str
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
453 CAppUtils::Switch(str
);
457 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
459 case ID_SWITCHBRANCH
:
462 CString
*branch
= (CString
*)((CIconMenu
*)popmenu
)->GetMenuItemData(cmd
);
466 if(branch
->Find(_T("refs/heads/")) ==0 )
467 name
= branch
->Mid(11);
471 CAppUtils::PerformSwitch(name
);
475 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
480 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
481 if (CAppUtils::GitReset(&str
))
490 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
493 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
495 case ID_REBASE_SQUASH
:
496 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
499 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP
);
501 case ID_COMBINE_COMMIT
:
505 CGitHash hashFirst
,hashLast
;
507 int headindex
=GetHeadIndex();
508 if(headindex
>=0) //incase show all branch, head is not the first commits.
510 head
.Format(_T("HEAD~%d"),FirstSelect
-headindex
);
511 hashFirst
=g_Git
.GetHash(head
);
513 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
514 hashLast
=g_Git
.GetHash(head
);
517 GitRev
* pFirstEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
518 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
519 if(pFirstEntry
->m_CommitHash
!= hashFirst
|| pLastEntry
->m_CommitHash
!= hashLast
)
521 CMessageBox::Show(NULL
, IDS_PROC_CANNOTCOMBINE
, IDS_APPNAME
, MB_OK
);
528 lastRevision
.GetParentFromHash(hashLast
);
533 MessageBox(_T("Could not get parent(s) of ") + hashLast
.ToString() + _T(".\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
537 headhash
=g_Git
.GetHash(_T("HEAD"));
539 if(!g_Git
.CheckCleanWorkTree())
541 CMessageBox::Show(NULL
, IDS_PROC_NOCLEAN
, IDS_APPNAME
, MB_OK
);
546 //Use throw to abort this process (reset back to original HEAD)
549 cmd
.Format(_T("git.exe reset --hard %s"),pFirstEntry
->m_CommitHash
.ToString());
550 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
552 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
553 throw std::exception(CUnicodeUtils::GetUTF8(CString(MAKEINTRESOURCE(IDS_PROC_COMBINE_ERRORSTEP1
)) + _T("\r\n\r\n") + out
));
555 cmd
.Format(_T("git.exe reset --mixed %s"),hashLast
.ToString());
556 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
558 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
559 throw std::exception(CUnicodeUtils::GetUTF8(CString(MAKEINTRESOURCE(IDS_PROC_COMBINE_ERRORSTEP2
)) + _T("\r\n\r\n")+out
));
562 CTGitPathList PathList
;
563 /* don't why must add --stat to get action status*/
564 /* first -z will be omitted by gitdll*/
565 if(g_Git
.GetDiffPath(&PathList
,&pFirstEntry
->m_CommitHash
,&hashLast
,"-z --stat -r"))
567 CMessageBox::Show(NULL
,_T("Get Diff file list error"),_T("TortoiseGit"),MB_OK
);
568 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not get changed file list aborting...\r\n\r\n")+out
));
571 for(int i
=0;i
<PathList
.GetCount();i
++)
573 if(PathList
[i
].m_Action
& CTGitPath::LOGACTIONS_ADDED
)
575 cmd
.Format(_T("git.exe add -- \"%s\""), PathList
[i
].GetGitPathString());
576 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
578 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
579 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not add new file aborting...\r\n\r\n")+out
));
583 if(PathList
[i
].m_Action
& CTGitPath::LOGACTIONS_DELETED
)
585 cmd
.Format(_T("git.exe rm -- \"%s\""), PathList
[i
].GetGitPathString());
586 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
588 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
589 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not rm file aborting...\r\n\r\n")+out
));
595 for(int i
=FirstSelect
;i
<=LastSelect
;i
++)
597 GitRev
* pRev
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(i
));
598 dlg
.m_sLogMessage
+=pRev
->GetSubject()+_T("\n")+pRev
->GetBody();
599 dlg
.m_sLogMessage
+=_T("\n");
601 dlg
.m_bWholeProject
=true;
602 dlg
.m_bSelectFilesForCommit
= true;
603 dlg
.m_bForceCommitAmend
=true;
604 if (lastRevision
.ParentsCount() != 1)
606 CMessageBox::Show(NULL
, _T("The following commit dialog can only show changes of oldest commit if it has exactly one parent. This is not the case right now."), _T("TortoiseGit"),MB_OK
);
607 dlg
.m_bAmendDiffToLastCommit
= TRUE
;
610 dlg
.m_bAmendDiffToLastCommit
= FALSE
;
611 dlg
.m_bNoPostActions
=true;
612 dlg
.m_AmendStr
=dlg
.m_sLogMessage
;
614 if (dlg
.DoModal() == IDOK
)
616 if(pFirstEntry
->m_CommitHash
!=headhash
)
618 //Commitrange firstEntry..headhash (from top of combine to original head) needs to be 'cherry-picked'
619 //on top of new commit.
620 //Use the rebase --onto command for it.
622 //All this can be done in one step using the following command:
623 //cmd.Format(_T("git.exe format-patch --stdout --binary --full-index -k %s..%s | git am -k -3"),
624 // pFirstEntry->m_CommitHash,
626 //But I am not sure if a '|' is going to work in a CreateProcess() call.
628 //Later the progress dialog could be used to execute these steps.
630 if(CherryPickFrom(pFirstEntry
->m_CommitHash
.ToString(),headhash
))
633 msg
.Format(_T("Error while cherry pick commits on top of combined commits. Aborting.\r\n\r\n"));
634 throw std::exception(CUnicodeUtils::GetUTF8(msg
));
637 CString currentBranch
=g_Git
.GetCurrentBranch();
638 cmd
.Format(_T("git.exe rebase --onto \"%s\" %s %s"),
640 pFirstEntry
->m_CommitHash
,
642 if(g_Git
.Run(cmd
,&out
,CP_UTF8
)!=0)
645 msg
.Format(_T("Error while rebasing commits on top of combined commits. Aborting.\r\n\r\n%s"),out
);
646 // CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK);
647 g_Git
.Run(_T("git.exe rebase --abort"),&out
,CP_UTF8
);
648 throw std::exception(CUnicodeUtils::GetUTF8(msg
));
651 //HEAD is now on <no branch>.
652 //The following steps are to get HEAD back on the original branch and reset the branch to the new HEAD
653 //To avoid 2 working copy changes, we could use git branch -f <original branch> <hash new head>
654 //And then git checkout <original branch>
655 //But I don't know if 'git branch -f' removes tracking options. So for now, do a checkout and a reset.
658 CString newHead
=g_Git
.GetHash(CString(_T("HEAD")));
660 //Checkout working branch
661 cmd
.Format(_T("git.exe checkout -f \"%s\""),currentBranch
);
662 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
663 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not checkout original branch. Aborting...\r\n\r\n")+out
));
666 cmd
.Format(_T("git.exe reset --hard %s"),newHead
);
667 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
668 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to new head. Aborting...\r\n\r\n")+out
));
673 throw std::exception(CUnicodeUtils::GetUTF8(CString(MAKEINTRESOURCE(IDS_SVN_USERCANCELLED
))));
675 catch(std::exception
& e
)
677 CMessageBox::Show(NULL
, CUnicodeUtils::GetUnicode(CStringA(e
.what())), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
678 cmd
.Format(_T("git.exe reset --hard %s"),headhash
.ToString());
680 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
682 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_COMBINE_ERRORRESETHEAD
)) + _T("\r\n\r\n") + out
, _T("TortoiseGit"), MB_OK
);
690 if(!g_Git
.CheckCleanWorkTree())
692 CMessageBox::Show(NULL
, IDS_PROC_NOCLEAN
, IDS_APPNAME
, MB_OK
);
698 dlg
.m_IsCherryPick
= TRUE
;
699 dlg
.m_Upstream
= this->m_CurrentBranch
;
700 POSITION pos
= GetFirstSelectedItemPosition();
703 int indexNext
= GetNextSelectedItem(pos
);
704 dlg
.m_CommitList
.m_logEntries
.push_back( ((GitRev
*)m_arShownList
[indexNext
])->m_CommitHash
);
705 dlg
.m_CommitList
.m_LogCache
.m_HashMap
[((GitRev
*)m_arShownList
[indexNext
])->m_CommitHash
]=*(GitRev
*)m_arShownList
[indexNext
];
706 dlg
.m_CommitList
.m_logEntries
.GetGitRevAt(dlg
.m_CommitList
.m_logEntries
.size()-1).GetAction(this) |= CTGitPath::LOGACTIONS_REBASE_PICK
;
709 if(dlg
.DoModal() == IDOK
)
715 case ID_REBASE_TO_VERSION
:
716 if(!g_Git
.CheckCleanWorkTree())
718 CMessageBox::Show(NULL
, IDS_PROC_NOCLEAN
, IDS_APPNAME
, MB_OK
);
724 dlg
.m_Upstream
= pSelLogEntry
->m_CommitHash
;
726 if(dlg
.DoModal() == IDOK
)
735 if (CAppUtils::StashSave())
740 if (CAppUtils::StashPop())
745 CAppUtils::RunTortoiseProc(_T("/command:reflog /ref:refs/stash"));
748 case ID_REFLOG_STASH_APPLY
:
749 if (CAppUtils::StashApply(pSelLogEntry
->m_Ref
))
756 if (GetSelectedCount() > 1)
757 str
.Format(IDS_PROC_DELETENREFS
, GetSelectedCount());
759 str
.Format(IDS_PROC_DELETEREF
, pSelLogEntry
->m_Ref
);
761 if (CMessageBox::Show(NULL
, str
, _T("TortoiseGit"), 1, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
764 POSITION pos
= GetFirstSelectedItemPosition();
767 CString ref
= ((GitRev
*)m_arShownList
[GetNextSelectedItem(pos
)])->m_Ref
;
768 if (ref
.Find(_T("refs/")) == 0)
770 int refpos
= ref
.ReverseFind('{');
771 if (refpos
> 0 && ref
.Mid(refpos
, 2) != _T("@{"))
772 ref
= ref
.Left(refpos
) + _T("@")+ ref
.Mid(refpos
);
775 if (ref
.Find(_T("stash")) == 0)
776 cmd
.Format(_T("git.exe stash drop %s"), ref
);
778 cmd
.Format(_T("git.exe reflog delete %s"), ref
);
780 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
781 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
783 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
789 CString cmd
= _T("/command:log");
790 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\" ");
791 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
792 cmd
+= _T(" /endrev:")+r1
->m_CommitHash
.ToString();
793 CAppUtils::RunTortoiseProc(cmd
);
796 case ID_CREATE_PATCH
:
798 int select
=this->GetSelectedCount();
799 CString cmd
= _T("/command:formatpatch");
800 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\" ");
802 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
806 cmd
+= _T(" /startrev:")+r1
->m_CommitHash
.ToString();
810 r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
811 if( this->m_IsOldFirst
)
813 cmd
+= _T(" /startrev:")+r1
->m_CommitHash
.ToString()+_T("~1");
814 cmd
+= _T(" /endrev:")+r2
->m_CommitHash
.ToString();
819 cmd
+= _T(" /startrev:")+r2
->m_CommitHash
.ToString()+_T("~1");
820 cmd
+= _T(" /endrev:")+r1
->m_CommitHash
.ToString();
825 CAppUtils::RunTortoiseProc(cmd
);
830 GitRev
* first
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
831 GitRev
* last
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
832 ASSERT(first
!= NULL
&& last
!= NULL
);
834 CString firstBad
= first
->m_CommitHash
.ToString();
835 if (!m_HashMap
[first
->m_CommitHash
].empty())
836 firstBad
= m_HashMap
[first
->m_CommitHash
].at(0);
837 CString lastGood
= last
->m_CommitHash
.ToString();
838 if (!m_HashMap
[last
->m_CommitHash
].empty())
839 lastGood
= m_HashMap
[last
->m_CommitHash
].at(0);
841 if (CAppUtils::BisectStart(lastGood
, firstBad
))
848 sCmd
.Format(_T("/command:repobrowser /path:\"%s\" /rev:%s"), g_Git
.m_CurrentDir
, pSelLogEntry
->m_CommitHash
.ToString());
849 CAppUtils::RunTortoiseProc(sCmd
);
854 CString guessAssociatedBranch
;
855 if (!m_HashMap
[pSelLogEntry
->m_CommitHash
].empty())
856 guessAssociatedBranch
= m_HashMap
[pSelLogEntry
->m_CommitHash
].at(0);
857 if (CAppUtils::Push(guessAssociatedBranch
))
863 if (CAppUtils::Fetch(_T(""), true))
867 case ID_SHOWBRANCHES
:
870 cmd
.Format(_T("git.exe branch -a --contains %s"), pSelLogEntry
->m_CommitHash
.ToString());
871 CProgressDlg progress
;
872 progress
.m_GitCmd
= cmd
;
878 CString
*branch
= (CString
*)((CIconMenu
*)popmenu
)->GetMenuItemData(cmd
);
881 CMessageBox::Show(NULL
,IDS_ERROR_NOREF
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
886 if (this->GetShortName(*branch
, shortname
, _T("refs/remotes/")))
889 msg
.Format(IDS_PROC_DELETEREMOTEBRANCH
, *branch
);
890 int result
= CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 3, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_PROC_DELETEREMOTEBRANCH_LOCALREMOTE
)), CString(MAKEINTRESOURCE(IDS_PROC_DELETEREMOTEBRANCH_LOCAL
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
)));
893 CString remoteName
= shortname
.Left(shortname
.Find('/'));
894 shortname
= shortname
.Mid(shortname
.Find('/') + 1);
895 if(CAppUtils::IsSSHPutty())
896 CAppUtils::LaunchPAgent(NULL
, &remoteName
);
898 cmd
.Format(L
"git.exe push \"%s\" :refs/heads/%s", remoteName
, shortname
);
900 else if (result
== 2)
901 cmd
.Format(_T("git.exe branch -r -D -- %s"), shortname
);
905 else if (this->GetShortName(*branch
, shortname
, _T("refs/stash")))
907 if (CMessageBox::Show(NULL
, IDS_PROC_DELETEALLSTASH
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_DELETEBUTTON
, IDS_ABORTBUTTON
) == 1)
908 cmd
.Format(_T("git.exe stash clear"));
915 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, *branch
);
916 if (CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
918 if(this->GetShortName(*branch
,shortname
,_T("refs/heads/")))
920 cmd
.Format(_T("git.exe branch -D -- %s"),shortname
);
923 if(this->GetShortName(*branch
,shortname
,_T("refs/tags/")))
925 cmd
.Format(_T("git.exe tag -d -- %s"),shortname
);
932 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
934 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
936 this->ReloadHashMap();
938 this->GetItemRect(FirstSelect
,&rect
,LVIR_BOUNDS
);
939 this->InvalidateRect(rect
);
946 m_nSearchIndex
= GetSelectionMark();
947 if (m_nSearchIndex
< 0)
955 m_pFindDialog
= new CFindDlg();
956 m_pFindDialog
->Create(this);
962 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
963 if (!m_HashMap
[pSelLogEntry
->m_CommitHash
].empty())
964 str
= m_HashMap
[pSelLogEntry
->m_CommitHash
].at(0);
965 // we need an URL to complete this command, so error out if we can't get an URL
966 if(CAppUtils::Merge(&str
))
975 if (GetSelectedCount() == 1)
978 if (parent
> pSelLogEntry
->m_ParentHash
.size())
981 str
.Format(IDS_PROC_NOPARENT
, parent
);
982 MessageBox(str
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
987 if (!this->RevertSelectedCommits(parent
))
989 if (CMessageBox::Show(m_hWnd
, IDS_REVREVERTED
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_OKBUTTON
, IDS_COMMITBUTTON
) == 2)
991 CTGitPathList pathlist
;
992 CTGitPathList selectedlist
;
993 pathlist
.AddPath(this->m_Path
);
994 bool bSelectFilesForCommit
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
996 CAppUtils::Commit(CString(), false, str
, pathlist
, selectedlist
, bSelectFilesForCommit
);
1004 CAppUtils::EditNote(pSelLogEntry
);
1005 this->SetItemState(FirstSelect
, 0, LVIS_SELECTED
);
1006 this->SetItemState(FirstSelect
, LVIS_SELECTED
, LVIS_SELECTED
);
1010 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
1014 case ID_BLAMECOMPARE
:
1016 //user clicked on the menu item "compare with working copy"
1017 //now first get the revision which is selected
1020 GitDiff
diff(this, this->m_hWnd
, true);
1021 diff
.SetHEADPeg(m_LogRevision
);
1022 diff
.ShowCompare(m_path
, GitRev::REV_BASE
, m_path
, revSelected
, GitRev(), false, true);
1025 CAppUtils::StartShowCompare(m_hWnd
, m_path
, GitRev::REV_BASE
, m_path
, revSelected
, GitRev(), m_LogRevision
, false, false, true);
1028 case ID_BLAMEWITHPREVIOUS
:
1030 //user clicked on the menu item "Compare and Blame with previous revision"
1033 GitDiff
diff(this, this->m_hWnd
, true);
1034 diff
.SetHEADPeg(m_LogRevision
);
1035 diff
.ShowCompare(CTGitPath(pathURL
), revPrevious
, CTGitPath(pathURL
), revSelected
, GitRev(), false, true);
1038 CAppUtils::StartShowCompare(m_hWnd
, CTGitPath(pathURL
), revPrevious
, CTGitPath(pathURL
), revSelected
, GitRev(), m_LogRevision
, false, false, true);
1046 CProgressDlg progDlg
;
1047 progDlg
.SetTitle(IDS_APPNAME
);
1048 progDlg
.SetAnimation(IDR_DOWNLOAD
);
1050 sInfoLine
.Format(IDS_PROGRESSGETFILEREVISION
, m_path
.GetWinPath(), (LPCTSTR
)revSelected
.ToString());
1051 progDlg
.SetLine(1, sInfoLine
, true);
1052 SetAndClearProgressInfo(&progDlg
);
1053 progDlg
.ShowModeless(m_hWnd
);
1054 CTGitPath tempfile
= CTempFiles::Instance().GetTempFilePath(false, m_path
, revSelected
);
1055 bool bSuccess
= true;
1056 if (!Cat(m_path
, GitRev(GitRev::REV_HEAD
), revSelected
, tempfile
))
1059 // try again, but with the selected revision as the peg revision
1060 if (!Cat(m_path
, revSelected
, revSelected
, tempfile
))
1063 SetAndClearProgressInfo((HWND
)NULL
);
1064 CMessageBox::Show(this->m_hWnd
, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1073 SetAndClearProgressInfo((HWND
)NULL
);
1074 SetFileAttributes(tempfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1077 ret
= (int)ShellExecute(this->m_hWnd
, NULL
, tempfile
.GetWinPath(), NULL
, NULL
, SW_SHOWNORMAL
);
1078 if ((ret
<= HINSTANCE_ERROR
)||bOpenWith
)
1080 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1081 cmd
+= tempfile
.GetWinPathString() + _T(" ");
1082 CAppUtils::LaunchApplication(cmd
, NULL
, false);
1090 dlg
.EndRev
= revSelected
;
1091 if (dlg
.DoModal() == IDOK
)
1096 tempfile
= blame
.BlameToTempFile(m_path
, dlg
.StartRev
, dlg
.EndRev
, dlg
.EndRev
, logfile
, _T(""), dlg
.m_bIncludeMerge
, TRUE
, TRUE
);
1097 if (!tempfile
.IsEmpty())
1099 if (dlg
.m_bTextView
)
1101 //open the default text editor for the result file
1102 CAppUtils::StartTextViewer(tempfile
);
1106 CString sParams
= _T("/path:\"") + m_path
.GetGitPathString() + _T("\" ");
1107 if(!CAppUtils::LaunchTortoiseBlame(tempfile
, logfile
, CPathUtils::GetFileNameFromPath(m_path
.GetFileOrDirectoryName()),sParams
))
1115 CMessageBox::Show(this->m_hWnd
, blame
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1123 sCmd
.Format(_T("%s /command:export /path:\"%s\" /revision:%ld"),
1124 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
1125 (LPCTSTR
)pathURL
, (LONG
)revSelected
);
1126 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
1131 CString url
= m_ProjectProperties
.sWebViewerRev
;
1132 url
= GetAbsoluteUrlFromRelativeUrl(url
);
1133 url
.Replace(_T("%REVISION%"), revSelected
.ToString());
1135 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
1138 case ID_VIEWPATHREV
:
1140 CString relurl
= pathURL
;
1141 CString sRoot
= GetRepositoryRoot(CTGitPath(relurl
));
1142 relurl
= relurl
.Mid(sRoot
.GetLength());
1143 CString url
= m_ProjectProperties
.sWebViewerPathRev
;
1144 url
= GetAbsoluteUrlFromRelativeUrl(url
);
1145 url
.Replace(_T("%REVISION%"), revSelected
.ToString());
1146 url
.Replace(_T("%PATH%"), relurl
);
1148 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
1155 theApp
.DoWaitCursor(-1);
1158 void CGitLogList::SetSelectedAction(int action
)
1160 POSITION pos
= GetFirstSelectedItemPosition();
1164 index
= GetNextSelectedItem(pos
);
1165 ((GitRev
*)m_arShownList
[index
])->GetAction(this) = action
;
1167 this->GetItemRect(index
,&rect
,LVIR_BOUNDS
);
1168 this->InvalidateRect(rect
);
1172 void CGitLogList::ShiftSelectedAction()
1174 POSITION pos
= GetFirstSelectedItemPosition();
1178 index
= GetNextSelectedItem(pos
);
1179 int action
= ((GitRev
*)m_arShownList
[index
])->GetAction(this);
1182 case CTGitPath::LOGACTIONS_REBASE_PICK
:
1183 action
= CTGitPath::LOGACTIONS_REBASE_SKIP
;
1185 case CTGitPath::LOGACTIONS_REBASE_SKIP
:
1186 action
= CTGitPath::LOGACTIONS_REBASE_EDIT
;
1188 case CTGitPath::LOGACTIONS_REBASE_EDIT
:
1189 action
= CTGitPath::LOGACTIONS_REBASE_SQUASH
;
1191 case CTGitPath::LOGACTIONS_REBASE_SQUASH
:
1192 action
= CTGitPath::LOGACTIONS_REBASE_PICK
;
1195 ((GitRev
*)m_arShownList
[index
])->GetAction(this) = action
;
1197 this->GetItemRect(index
, &rect
, LVIR_BOUNDS
);
1198 this->InvalidateRect(rect
);