1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - 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"
28 #include "GitProgressDlg.h"
29 #include "ProgressDlg.h"
30 #include "SysProgressDlg.h"
32 #include "MessageBox.h"
35 #include "StringUtils.h"
36 #include "UnicodeUtils.h"
38 #include "FileDiffDlg.h"
39 #include "CommitDlg.h"
40 #include "RebaseDlg.h"
42 #include "../TGitCache/CacheInterface.h"
44 IMPLEMENT_DYNAMIC(CGitLogList
, CHintListCtrl
)
46 int CGitLogList::RevertSelectedCommits(int parent
)
48 CSysProgressDlg progress
;
52 if(!g_Git
.CheckCleanWorkTree())
54 CMessageBox::Show(NULL
, IDS_PROC_NOCLEAN
, IDS_APPNAME
, MB_OK
);
59 if (this->GetSelectedCount() > 1)
61 progress
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_REVERTCOMMIT
)));
62 progress
.SetAnimation(IDR_MOVEANI
);
63 progress
.SetTime(true);
64 progress
.ShowModeless(this);
67 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
69 POSITION pos
= GetFirstSelectedItemPosition();
73 int index
= GetNextSelectedItem(pos
);
74 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(index
));
76 if (progress
.IsVisible())
78 progress
.FormatNonPathLine(1, IDS_PROC_REVERTCOMMIT
, r1
->m_CommitHash
.ToString());
79 progress
.FormatNonPathLine(2, _T("%s"), r1
->GetSubject());
80 progress
.SetProgress(i
, this->GetSelectedCount());
84 if(r1
->m_CommitHash
.IsEmpty())
87 if (g_Git
.GitRevert(parent
, r1
->m_CommitHash
))
90 str
.LoadString(IDS_SVNACTION_FAILEDREVERT
);
91 str
= g_Git
.GetGitLastErr(str
, CGit::GIT_CMD_REVERT
);
92 if( GetSelectedCount() == 1)
93 CMessageBox::Show(NULL
, str
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
96 if(CMessageBox::Show(NULL
, str
, _T("TortoiseGit"),2 , IDI_ERROR
, CString(MAKEINTRESOURCE(IDS_SKIPBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
107 if (progress
.HasUserCancelled())
112 int CGitLogList::CherryPickFrom(CString from
, CString to
)
114 CLogDataVector
logs(&m_LogCache
);
116 range
.Format(_T("%s..%s"), from
, to
);
117 if (logs
.ParserFromLog(nullptr, -1, 0, &range
))
123 CSysProgressDlg progress
;
124 progress
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CHERRYPICK
)));
125 progress
.SetAnimation(IDR_MOVEANI
);
126 progress
.SetTime(true);
127 progress
.ShowModeless(this);
129 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
131 for (int i
= (int)logs
.size() - 1; i
>= 0; i
--)
133 if (progress
.IsVisible())
135 progress
.FormatNonPathLine(1, IDS_PROC_PICK
, logs
.GetGitRevAt(i
).m_CommitHash
.ToString());
136 progress
.FormatNonPathLine(2, _T("%s"), logs
.GetGitRevAt(i
).GetSubject());
137 progress
.SetProgress64(logs
.size() - i
, logs
.size());
139 if (progress
.HasUserCancelled())
141 throw std::exception(CUnicodeUtils::GetUTF8(CString(MAKEINTRESOURCE(IDS_SVN_USERCANCELLED
))));
144 cmd
.Format(_T("git.exe cherry-pick %s"),logs
.GetGitRevAt(i
).m_CommitHash
.ToString());
146 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
148 throw std::exception(CUnicodeUtils::GetUTF8(CString(MAKEINTRESOURCE(IDS_PROC_CHERRYPICKFAILED
)) + _T(":\r\n\r\n") + out
));
155 void CGitLogList::ContextMenuAction(int cmd
,int FirstSelect
, int LastSelect
, CMenu
*popmenu
)
157 POSITION pos
= GetFirstSelectedItemPosition();
158 int indexNext
= GetNextSelectedItem(pos
);
162 GitRevLoglist
* pSelLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.GetAt(indexNext
));
164 theApp
.DoWaitCursor(1);
169 CTGitPathList pathlist
;
170 CTGitPathList selectedlist
;
171 pathlist
.AddPath(this->m_Path
);
172 bool bSelectFilesForCommit
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
174 CAppUtils::Commit(CString(),false,str
,
175 pathlist
,selectedlist
,bSelectFilesForCommit
);
177 this->GetParent()->PostMessage(WM_COMMAND
,ID_LOGDLG_REFRESH
,0);
182 if (CAppUtils::MergeAbort())
183 this->GetParent()->PostMessage(WM_COMMAND
,ID_LOGDLG_REFRESH
, 0);
186 case ID_GNUDIFF1
: // compare with WC, unified
188 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
189 bool bMerge
= false, bCombine
= false;
191 if(!r1
->m_CommitHash
.IsEmpty())
195 if( (cmd
&0xFFFF) == 0xFFFF)
198 else if((cmd
&0xFFFF) == 0xFFFE)
202 if(cmd
> r1
->m_ParentHash
.size())
205 str
.Format(IDS_PROC_NOPARENT
, cmd
);
206 MessageBox(str
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
212 hash2
= r1
->m_ParentHash
[cmd
-1].ToString();
215 CAppUtils::StartShowUnifiedDiff(nullptr, CTGitPath(), hash2
, CTGitPath(), r1
->m_CommitHash
.ToString(), false, false, false, bMerge
, bCombine
);
218 CAppUtils::StartShowUnifiedDiff(nullptr, CTGitPath(), _T("HEAD"), CTGitPath(), GitRev::GetWorkingCopy(), false, false, false, bMerge
, bCombine
);
222 case ID_GNUDIFF2
: // compare two revisions, unified
224 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
225 GitRev
* r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
226 CAppUtils::StartShowUnifiedDiff(nullptr, CTGitPath(), r2
->m_CommitHash
.ToString(), CTGitPath(), r1
->m_CommitHash
.ToString());
230 case ID_COMPARETWO
: // compare two revisions
232 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
233 GitRev
* r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
234 if (m_Path
.IsDirectory() || !(m_ShowMask
& CGit::LOG_INFO_FOLLOW
))
235 CGitDiff::DiffCommit(this->m_Path
, r1
,r2
);
238 CString path1
= m_Path
.GetGitPathString();
239 // start with 1 (0 = working copy changes)
240 for (int i
= 1; i
< FirstSelect
; ++i
)
242 GitRevLoglist
* first
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.GetAt(i
));
243 CTGitPathList list
= first
->GetFiles(NULL
);
244 CTGitPath
* file
= list
.LookForGitPath(path1
);
245 if (file
&& !file
->GetGitOldPathString().IsEmpty())
246 path1
= file
->GetGitOldPathString();
248 CString path2
= path1
;
249 for (int i
= FirstSelect
; i
< LastSelect
; ++i
)
251 GitRevLoglist
* first
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.GetAt(i
));
252 CTGitPathList list
= first
->GetFiles(NULL
);
253 CTGitPath
* file
= list
.LookForGitPath(path2
);
254 if (file
&& !file
->GetGitOldPathString().IsEmpty())
255 path2
= file
->GetGitOldPathString();
257 CGitDiff::DiffCommit(CTGitPath(path1
), CTGitPath(path2
), r1
, r2
);
263 case ID_COMPARE
: // compare revision with WC
265 GitRevLoglist
* r1
= &m_wcRev
;
266 GitRevLoglist
* r2
= pSelLogEntry
;
268 if (m_Path
.IsDirectory() || !(m_ShowMask
& CGit::LOG_INFO_FOLLOW
))
269 CGitDiff::DiffCommit(this->m_Path
, r1
,r2
);
272 CString path1
= m_Path
.GetGitPathString();
273 // start with 1 (0 = working copy changes)
274 for (int i
= 1; i
< FirstSelect
; ++i
)
276 GitRevLoglist
* first
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.GetAt(i
));
277 CTGitPathList list
= first
->GetFiles(NULL
);
278 CTGitPath
* file
= list
.LookForGitPath(path1
);
279 if (file
&& !file
->GetGitOldPathString().IsEmpty())
280 path1
= file
->GetGitOldPathString();
282 CGitDiff::DiffCommit(m_Path
, CTGitPath(path1
), 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
:
302 if (pSelLogEntry
->m_ParentHash
.empty())
304 if (pSelLogEntry
->GetParentFromHash(pSelLogEntry
->m_CommitHash
))
305 MessageBox(pSelLogEntry
->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
308 if (!pSelLogEntry
->m_ParentHash
.empty())
309 //if(m_logEntries.m_HashMap[pSelLogEntry->m_ParentHash[0]]>=0)
317 if (m_Path
.IsDirectory() || !(m_ShowMask
& CGit::LOG_INFO_FOLLOW
))
318 CGitDiff::DiffCommit(m_Path
, pSelLogEntry
->m_CommitHash
.ToString(), pSelLogEntry
->m_ParentHash
[cmd
- 1].ToString());
321 CString path1
= m_Path
.GetGitPathString();
322 // start with 1 (0 = working copy changes)
323 for (int i
= 1; i
< indexNext
; ++i
)
325 GitRevLoglist
* first
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.GetAt(i
));
326 CTGitPathList list
= first
->GetFiles(NULL
);
327 CTGitPath
* file
= list
.LookForGitPath(path1
);
328 if (file
&& !file
->GetGitOldPathString().IsEmpty())
329 path1
= file
->GetGitOldPathString();
331 CString path2
= path1
;
332 GitRevLoglist
* first
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.GetAt(indexNext
));
333 CTGitPathList list
= first
->GetFiles(NULL
);
334 CTGitPath
* file
= list
.LookForGitPath(path2
);
335 if (file
&& !file
->GetGitOldPathString().IsEmpty())
336 path2
= file
->GetGitOldPathString();
338 CGitDiff::DiffCommit(CTGitPath(path1
), CTGitPath(path2
), pSelLogEntry
->m_CommitHash
.ToString(), pSelLogEntry
->m_ParentHash
[cmd
- 1].ToString());
343 CMessageBox::Show(NULL
, IDS_PROC_NOPREVIOUSVERSION
, IDS_APPNAME
, MB_OK
);
347 // GitDiff diff(this, m_hWnd, true);
348 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
349 // diff.SetHEADPeg(m_LogRevision);
350 // diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected);
353 // CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
356 case ID_LOG_VIEWRANGE
:
357 case ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
:
359 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
361 CString sep
= _T("..");
362 if ((cmd
& 0xFFFF) == ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
)
366 cmdline
.Format(_T("/command:log /path:\"%s\" /range:\"%s%s%s\""),
367 g_Git
.CombinePath(m_Path
), pLastEntry
->m_CommitHash
.ToString(), sep
, pSelLogEntry
->m_CommitHash
.ToString());
368 CAppUtils::RunTortoiseGitProc(cmdline
);
371 case ID_COPYCLIPBOARD
:
373 CopySelectionToClipBoard();
376 case ID_COPYCLIPBOARDMESSAGES
:
378 if ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0)
379 CopySelectionToClipBoard(ID_COPY_SUBJECT
);
381 CopySelectionToClipBoard(ID_COPY_MESSAGE
);
386 CopySelectionToClipBoard(ID_COPY_HASH
);
391 CString str
=pSelLogEntry
->m_CommitHash
.ToString();
392 // try to get the tag
393 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
395 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/tags/")) == 0)
397 str
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
401 CAppUtils::Export(&str
, &m_Path
);
404 case ID_CREATE_BRANCH
:
407 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
408 // try to guess remote branch in order to enable tracking
409 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
411 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/remotes/")) == 0)
413 str
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
417 CAppUtils::CreateBranchTag((cmd
&0xFFFF) == ID_CREATE_TAG
, &str
);
420 m_pFindDialog
->RefreshList();
422 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
427 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
428 // try to guess remote branch in order to recommend good branch name and tracking
429 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
431 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/remotes/")) == 0)
433 str
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
437 CAppUtils::Switch(str
);
441 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
443 case ID_SWITCHBRANCH
:
446 CString
*branch
= (CString
*)((CIconMenu
*)popmenu
)->GetMenuItemData(cmd
);
450 if(branch
->Find(_T("refs/heads/")) ==0 )
451 name
= branch
->Mid(11);
455 CAppUtils::PerformSwitch(name
);
459 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
464 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
465 if (CAppUtils::GitReset(&str
))
474 SetSelectedRebaseAction(LOGACTIONS_REBASE_PICK
);
477 SetSelectedRebaseAction(LOGACTIONS_REBASE_EDIT
);
479 case ID_REBASE_SQUASH
:
480 SetSelectedRebaseAction(LOGACTIONS_REBASE_SQUASH
);
483 SetSelectedRebaseAction(LOGACTIONS_REBASE_SKIP
);
485 case ID_COMBINE_COMMIT
:
489 CGitHash hashFirst
,hashLast
;
491 int headindex
=GetHeadIndex();
492 if(headindex
>=0) //incase show all branch, head is not the first commits.
494 head
.Format(_T("HEAD~%d"),FirstSelect
-headindex
);
495 if (g_Git
.GetHash(hashFirst
, head
))
497 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of first selected revision.")), _T("TortoiseGit"), MB_ICONERROR
);
501 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
502 if (g_Git
.GetHash(hashLast
, head
))
504 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of last selected revision.")), _T("TortoiseGit"), MB_ICONERROR
);
509 GitRev
* pFirstEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
510 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
511 if(pFirstEntry
->m_CommitHash
!= hashFirst
|| pLastEntry
->m_CommitHash
!= hashLast
)
513 CMessageBox::Show(NULL
, IDS_PROC_CANNOTCOMBINE
, IDS_APPNAME
, MB_OK
);
518 if (lastRevision
.GetParentFromHash(hashLast
))
520 MessageBox(lastRevision
.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
524 if (g_Git
.GetHash(headhash
, _T("HEAD")))
526 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
530 if(!g_Git
.CheckCleanWorkTree())
532 CMessageBox::Show(NULL
, IDS_PROC_NOCLEAN
, IDS_APPNAME
, MB_OK
);
537 //Use throw to abort this process (reset back to original HEAD)
540 cmd
.Format(_T("git.exe reset --hard %s --"), pFirstEntry
->m_CommitHash
.ToString());
541 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
543 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
544 throw std::exception(CUnicodeUtils::GetUTF8(CString(MAKEINTRESOURCE(IDS_PROC_COMBINE_ERRORSTEP1
)) + _T("\r\n\r\n") + out
));
546 cmd
.Format(_T("git.exe reset --mixed %s --"), hashLast
.ToString());
547 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
549 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
550 throw std::exception(CUnicodeUtils::GetUTF8(CString(MAKEINTRESOURCE(IDS_PROC_COMBINE_ERRORSTEP2
)) + _T("\r\n\r\n")+out
));
553 CTGitPathList PathList
;
554 /* don't why must add --stat to get action status*/
555 /* first -z will be omitted by gitdll*/
556 if(g_Git
.GetDiffPath(&PathList
,&pFirstEntry
->m_CommitHash
,&hashLast
,"-z --stat -r"))
558 CMessageBox::Show(NULL
,_T("Get Diff file list error"),_T("TortoiseGit"),MB_OK
);
559 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not get changed file list aborting...\r\n\r\n")+out
));
562 for (int i
= 0; i
< PathList
.GetCount(); ++i
)
564 if(PathList
[i
].m_Action
& CTGitPath::LOGACTIONS_ADDED
)
566 cmd
.Format(_T("git.exe add -- \"%s\""), PathList
[i
].GetGitPathString());
567 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
569 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
570 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not add new file aborting...\r\n\r\n")+out
));
574 if(PathList
[i
].m_Action
& CTGitPath::LOGACTIONS_DELETED
)
576 cmd
.Format(_T("git.exe rm -- \"%s\""), PathList
[i
].GetGitPathString());
577 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
579 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
580 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not rm file aborting...\r\n\r\n")+out
));
586 for (int i
= FirstSelect
; i
<= LastSelect
; ++i
)
588 GitRev
* pRev
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(i
));
589 dlg
.m_sLogMessage
+=pRev
->GetSubject()+_T("\n")+pRev
->GetBody();
590 dlg
.m_sLogMessage
+=_T("\n");
592 dlg
.m_bWholeProject
=true;
593 dlg
.m_bSelectFilesForCommit
= true;
594 dlg
.m_bForceCommitAmend
=true;
596 gpl
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
597 dlg
.m_pathList
= gpl
;
598 if (lastRevision
.ParentsCount() != 1)
600 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
);
601 dlg
.m_bAmendDiffToLastCommit
= TRUE
;
604 dlg
.m_bAmendDiffToLastCommit
= FALSE
;
605 dlg
.m_bNoPostActions
=true;
606 dlg
.m_AmendStr
=dlg
.m_sLogMessage
;
608 if (dlg
.DoModal() == IDOK
)
610 if(pFirstEntry
->m_CommitHash
!=headhash
)
612 if(CherryPickFrom(pFirstEntry
->m_CommitHash
.ToString(),headhash
))
615 msg
.Format(_T("Error while cherry pick commits on top of combined commits. Aborting.\r\n\r\n"));
616 throw std::exception(CUnicodeUtils::GetUTF8(msg
));
621 throw std::exception(CUnicodeUtils::GetUTF8(CString(MAKEINTRESOURCE(IDS_SVN_USERCANCELLED
))));
623 catch(std::exception
& e
)
625 CMessageBox::Show(NULL
, CUnicodeUtils::GetUnicode(CStringA(e
.what())), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
626 cmd
.Format(_T("git.exe reset --hard %s --"), headhash
.ToString());
628 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
630 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_COMBINE_ERRORRESETHEAD
)) + _T("\r\n\r\n") + out
, _T("TortoiseGit"), MB_OK
);
639 if (m_bThreadRunning
)
641 MessageBox(_T("This operation cannot be started while the log dialog is still loading commits."), _T("TortoiseGit"), MB_ICONEXCLAMATION
);
645 dlg
.m_IsCherryPick
= TRUE
;
646 dlg
.m_Upstream
= this->m_CurrentBranch
;
647 POSITION pos
= GetFirstSelectedItemPosition();
650 int indexNext
= GetNextSelectedItem(pos
);
651 dlg
.m_CommitList
.m_logEntries
.push_back(((GitRevLoglist
*)m_arShownList
[indexNext
])->m_CommitHash
);
652 dlg
.m_CommitList
.m_LogCache
.m_HashMap
[((GitRevLoglist
*)m_arShownList
[indexNext
])->m_CommitHash
] = *(GitRevLoglist
*)m_arShownList
[indexNext
];
653 dlg
.m_CommitList
.m_logEntries
.GetGitRevAt(dlg
.m_CommitList
.m_logEntries
.size() - 1).GetRebaseAction() |= LOGACTIONS_REBASE_PICK
;
656 if(dlg
.DoModal() == IDOK
)
662 case ID_REBASE_TO_VERSION
:
664 if (m_bThreadRunning
)
666 MessageBox(_T("This operation cannot be started while the log dialog is still loading commits."), _T("TortoiseGit"), MB_ICONEXCLAMATION
);
670 auto refList
= m_HashMap
[pSelLogEntry
->m_CommitHash
];
671 dlg
.m_Upstream
= refList
.empty() ? pSelLogEntry
->m_CommitHash
.ToString() : refList
.front();
672 for (auto ref
: refList
)
674 if (ref
.Left(11) == _T("refs/heads/"))
676 // 11=len("refs/heads/")
677 dlg
.m_Upstream
= ref
.Mid(11);
682 if(dlg
.DoModal() == IDOK
)
691 if (CAppUtils::StashSave())
696 if (CAppUtils::StashPop())
701 CAppUtils::RunTortoiseGitProc(_T("/command:reflog /ref:refs/stash"));
704 case ID_REFLOG_STASH_APPLY
:
705 CAppUtils::StashApply(pSelLogEntry
->m_Ref
);
711 if (GetSelectedCount() > 1)
712 str
.Format(IDS_PROC_DELETENREFS
, GetSelectedCount());
714 str
.Format(IDS_PROC_DELETEREF
, pSelLogEntry
->m_Ref
);
716 if (CMessageBox::Show(NULL
, str
, _T("TortoiseGit"), 1, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
719 std::vector
<CString
> refsToDelete
;
720 POSITION pos
= GetFirstSelectedItemPosition();
723 CString ref
= ((GitRevLoglist
*)m_arShownList
[GetNextSelectedItem(pos
)])->m_Ref
;
724 if (ref
.Find(_T("refs/")) == 0)
726 int refpos
= ref
.ReverseFind('{');
727 if (refpos
> 0 && ref
.Mid(refpos
- 1, 2) != _T("@{"))
728 ref
= ref
.Left(refpos
) + _T("@")+ ref
.Mid(refpos
);
729 refsToDelete
.push_back(ref
);
732 for (auto revIt
= refsToDelete
.rbegin(); revIt
!= refsToDelete
.rend(); ++revIt
)
734 CString ref
= *revIt
;
736 if (ref
.Find(_T("stash")) == 0)
737 cmd
.Format(_T("git.exe stash drop %s"), ref
);
739 cmd
.Format(_T("git.exe reflog delete %s"), ref
);
741 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
742 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
744 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
750 CString cmd
= _T("/command:log");
751 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\" ");
752 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
753 cmd
+= _T(" /endrev:")+r1
->m_CommitHash
.ToString();
754 CAppUtils::RunTortoiseGitProc(cmd
);
757 case ID_CREATE_PATCH
:
759 int select
=this->GetSelectedCount();
760 CString cmd
= _T("/command:formatpatch");
761 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\" ");
763 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
767 cmd
+= _T(" /startrev:")+r1
->m_CommitHash
.ToString();
771 r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
772 if( this->m_IsOldFirst
)
774 cmd
+= _T(" /startrev:")+r1
->m_CommitHash
.ToString()+_T("~1");
775 cmd
+= _T(" /endrev:")+r2
->m_CommitHash
.ToString();
780 cmd
+= _T(" /startrev:")+r2
->m_CommitHash
.ToString()+_T("~1");
781 cmd
+= _T(" /endrev:")+r1
->m_CommitHash
.ToString();
786 CAppUtils::RunTortoiseGitProc(cmd
);
791 GitRev
* first
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
792 GitRev
* last
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
793 ASSERT(first
!= NULL
&& last
!= NULL
);
795 CString firstBad
= first
->m_CommitHash
.ToString();
796 if (!m_HashMap
[first
->m_CommitHash
].empty())
797 firstBad
= m_HashMap
[first
->m_CommitHash
].at(0);
798 CString lastGood
= last
->m_CommitHash
.ToString();
799 if (!m_HashMap
[last
->m_CommitHash
].empty())
800 lastGood
= m_HashMap
[last
->m_CommitHash
].at(0);
802 if (CAppUtils::BisectStart(lastGood
, firstBad
))
809 sCmd
.Format(_T("/command:repobrowser /path:\"%s\" /rev:%s"), g_Git
.m_CurrentDir
, pSelLogEntry
->m_CommitHash
.ToString());
810 CAppUtils::RunTortoiseGitProc(sCmd
);
815 CString guessAssociatedBranch
= pSelLogEntry
->m_CommitHash
;
816 if (!m_HashMap
[pSelLogEntry
->m_CommitHash
].empty() && m_HashMap
[pSelLogEntry
->m_CommitHash
].at(0).Find(_T("refs/heads/")) == 0)
817 guessAssociatedBranch
= m_HashMap
[pSelLogEntry
->m_CommitHash
].at(0);
818 if (CAppUtils::Push(guessAssociatedBranch
))
824 if (CAppUtils::Pull())
830 if (CAppUtils::Fetch())
837 sCmd
.Format(_T("/command:cleanup /path:\"%s\""), g_Git
.m_CurrentDir
);
838 CAppUtils::RunTortoiseGitProc(sCmd
);
841 case ID_SUBMODULE_UPDATE
:
844 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
845 CAppUtils::RunTortoiseGitProc(sCmd
);
848 case ID_SHOWBRANCHES
:
851 cmd
.Format(_T("git.exe branch -a --contains %s"), pSelLogEntry
->m_CommitHash
.ToString());
852 CProgressDlg progress
;
853 progress
.m_AutoClose
= AUTOCLOSE_NO
;
854 progress
.m_GitCmd
= cmd
;
860 CString
*branch
= (CString
*)((CIconMenu
*)popmenu
)->GetMenuItemData(cmd
);
863 CMessageBox::Show(NULL
,IDS_ERROR_NOREF
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
867 if (CGit::GetShortName(*branch
, shortname
, _T("refs/remotes/")))
870 msg
.Format(IDS_PROC_DELETEREMOTEBRANCH
, *branch
);
871 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
)));
874 CString remoteName
= shortname
.Left(shortname
.Find('/'));
875 shortname
= shortname
.Mid(shortname
.Find('/') + 1);
876 if(CAppUtils::IsSSHPutty())
877 CAppUtils::LaunchPAgent(NULL
, &remoteName
);
879 CSysProgressDlg sysProgressDlg
;
880 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
881 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_DELETING_REMOTE_REFS
)));
882 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
883 sysProgressDlg
.SetShowProgressBar(false);
884 sysProgressDlg
.ShowModal(this, true);
886 list
.push_back(_T("refs/heads/") + shortname
);
887 if (g_Git
.DeleteRemoteRefs(remoteName
, list
))
888 CMessageBox::Show(NULL
, g_Git
.GetGitLastErr(_T("Could not delete remote ref."), CGit::GIT_CMD_PUSH
), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
889 sysProgressDlg
.Stop();
891 else if (result
== 2)
893 if (g_Git
.DeleteRef(*branch
))
895 CMessageBox::Show(nullptr, g_Git
.GetGitLastErr(L
"Could not delete reference.", CGit::GIT_CMD_DELETETAGBRANCH
), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
902 else if (CGit::GetShortName(*branch
, shortname
, _T("refs/stash")))
904 if (CMessageBox::Show(NULL
, IDS_PROC_DELETEALLSTASH
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_DELETEBUTTON
, IDS_ABORTBUTTON
) == 1)
907 cmd
.Format(_T("git.exe stash clear"));
909 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
910 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
918 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, *branch
);
919 if (CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
921 if (g_Git
.DeleteRef(*branch
))
923 CMessageBox::Show(nullptr, g_Git
.GetGitLastErr(L
"Could not delete reference.", CGit::GIT_CMD_DELETETAGBRANCH
), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
928 this->ReloadHashMap();
930 m_pFindDialog
->RefreshList();
932 this->GetItemRect(FirstSelect
,&rect
,LVIR_BOUNDS
);
933 this->InvalidateRect(rect
);
939 m_nSearchIndex
= GetSelectionMark();
940 if (m_nSearchIndex
< 0)
948 m_pFindDialog
= new CFindDlg();
949 m_pFindDialog
->Create(this);
955 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
956 if (!m_HashMap
[pSelLogEntry
->m_CommitHash
].empty())
957 str
= m_HashMap
[pSelLogEntry
->m_CommitHash
].at(0);
958 // we need an URL to complete this command, so error out if we can't get an URL
959 if(CAppUtils::Merge(&str
))
968 if (GetSelectedCount() == 1)
971 if (parent
> pSelLogEntry
->m_ParentHash
.size())
974 str
.Format(IDS_PROC_NOPARENT
, parent
);
975 MessageBox(str
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
980 if (!this->RevertSelectedCommits(parent
))
982 if (CMessageBox::Show(m_hWnd
, IDS_REVREVERTED
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_OKBUTTON
, IDS_COMMITBUTTON
) == 2)
984 CTGitPathList pathlist
;
985 CTGitPathList selectedlist
;
986 pathlist
.AddPath(this->m_Path
);
987 bool bSelectFilesForCommit
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
989 CAppUtils::Commit(CString(), false, str
, pathlist
, selectedlist
, bSelectFilesForCommit
);
997 CAppUtils::EditNote(pSelLogEntry
);
998 this->SetItemState(FirstSelect
, 0, LVIS_SELECTED
);
999 this->SetItemState(FirstSelect
, LVIS_SELECTED
, LVIS_SELECTED
);
1003 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
1007 case ID_BLAMECOMPARE
:
1009 //user clicked on the menu item "compare with working copy"
1010 //now first get the revision which is selected
1013 GitDiff
diff(this, this->m_hWnd
, true);
1014 diff
.SetHEADPeg(m_LogRevision
);
1015 diff
.ShowCompare(m_path
, GitRev::REV_BASE
, m_path
, revSelected
, GitRev(), false, true);
1018 CAppUtils::StartShowCompare(m_hWnd
, m_path
, GitRev::REV_BASE
, m_path
, revSelected
, GitRev(), m_LogRevision
, false, false, true);
1021 case ID_BLAMEWITHPREVIOUS
:
1023 //user clicked on the menu item "Compare and Blame with previous revision"
1026 GitDiff
diff(this, this->m_hWnd
, true);
1027 diff
.SetHEADPeg(m_LogRevision
);
1028 diff
.ShowCompare(CTGitPath(pathURL
), revPrevious
, CTGitPath(pathURL
), revSelected
, GitRev(), false, true);
1031 CAppUtils::StartShowCompare(m_hWnd
, CTGitPath(pathURL
), revPrevious
, CTGitPath(pathURL
), revSelected
, GitRev(), m_LogRevision
, false, false, true);
1039 CProgressDlg progDlg
;
1040 progDlg
.SetTitle(IDS_APPNAME
);
1041 progDlg
.SetAnimation(IDR_DOWNLOAD
);
1043 sInfoLine
.Format(IDS_PROGRESSGETFILEREVISION
, m_path
.GetWinPath(), (LPCTSTR
)revSelected
.ToString());
1044 progDlg
.SetLine(1, sInfoLine
, true);
1045 SetAndClearProgressInfo(&progDlg
);
1046 progDlg
.ShowModeless(m_hWnd
);
1047 CTGitPath tempfile
= CTempFiles::Instance().GetTempFilePath(false, m_path
, revSelected
);
1048 bool bSuccess
= true;
1049 if (!Cat(m_path
, GitRev(GitRev::REV_HEAD
), revSelected
, tempfile
))
1052 // try again, but with the selected revision as the peg revision
1053 if (!Cat(m_path
, revSelected
, revSelected
, tempfile
))
1056 SetAndClearProgressInfo((HWND
)NULL
);
1057 CMessageBox::Show(this->m_hWnd
, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1066 SetAndClearProgressInfo((HWND
)NULL
);
1067 SetFileAttributes(tempfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1069 CAppUtils::ShellOpen(tempfile
.GetWinPath(), GetSafeHwnd());
1071 CAppUtils::ShowOpenWithDialog(tempfile
.GetWinPathString(), GetSafeHwnd());
1078 dlg
.EndRev
= revSelected
;
1079 if (dlg
.DoModal() == IDOK
)
1084 tempfile
= blame
.BlameToTempFile(m_path
, dlg
.StartRev
, dlg
.EndRev
, dlg
.EndRev
, logfile
, _T(""), dlg
.m_bIncludeMerge
, TRUE
, TRUE
);
1085 if (!tempfile
.IsEmpty())
1087 if (dlg
.m_bTextView
)
1089 //open the default text editor for the result file
1090 CAppUtils::StartTextViewer(tempfile
);
1094 CString sParams
= _T("/path:\"") + m_path
.GetGitPathString() + _T("\" ");
1095 if(!CAppUtils::LaunchTortoiseBlame(tempfile
, logfile
, CPathUtils::GetFileNameFromPath(m_path
.GetFileOrDirectoryName()),sParams
))
1103 CMessageBox::Show(this->m_hWnd
, blame
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1111 sCmd
.Format(_T("%s /command:export /path:\"%s\" /revision:%ld"),
1112 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseGitProc.exe")),
1113 (LPCTSTR
)pathURL
, (LONG
)revSelected
);
1114 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
1119 CString url
= m_ProjectProperties
.sWebViewerRev
;
1120 url
= GetAbsoluteUrlFromRelativeUrl(url
);
1121 url
.Replace(_T("%REVISION%"), revSelected
.ToString());
1123 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
1126 case ID_VIEWPATHREV
:
1128 CString relurl
= pathURL
;
1129 CString sRoot
= GetRepositoryRoot(CTGitPath(relurl
));
1130 relurl
= relurl
.Mid(sRoot
.GetLength());
1131 CString url
= m_ProjectProperties
.sWebViewerPathRev
;
1132 url
= GetAbsoluteUrlFromRelativeUrl(url
);
1133 url
.Replace(_T("%REVISION%"), revSelected
.ToString());
1134 url
.Replace(_T("%PATH%"), relurl
);
1136 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
1143 theApp
.DoWaitCursor(-1);
1146 void CGitLogList::SetSelectedRebaseAction(int action
)
1148 POSITION pos
= GetFirstSelectedItemPosition();
1153 index
= GetNextSelectedItem(pos
);
1154 if (((GitRevLoglist
*)m_arShownList
[index
])->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
))
1156 ((GitRevLoglist
*)m_arShownList
[index
])->GetRebaseAction() = action
;
1158 this->GetItemRect(index
,&rect
,LVIR_BOUNDS
);
1159 this->InvalidateRect(rect
);
1162 GetParent()->PostMessage(CGitLogListBase::m_RebaseActionMessage
);
1164 void CGitLogList::ShiftSelectedRebaseAction()
1166 POSITION pos
= GetFirstSelectedItemPosition();
1170 index
= GetNextSelectedItem(pos
);
1171 int dummyAction
= 0;
1172 int *action
= &dummyAction
;
1173 action
= &((GitRevLoglist
*)m_arShownList
[index
])->GetRebaseAction();
1176 case LOGACTIONS_REBASE_PICK
:
1177 *action
= LOGACTIONS_REBASE_SKIP
;
1179 case LOGACTIONS_REBASE_SKIP
:
1180 *action
= LOGACTIONS_REBASE_EDIT
;
1182 case LOGACTIONS_REBASE_EDIT
:
1183 *action
= LOGACTIONS_REBASE_SQUASH
;
1185 case LOGACTIONS_REBASE_SQUASH
:
1186 *action
= LOGACTIONS_REBASE_PICK
;
1190 this->GetItemRect(index
, &rect
, LVIR_BOUNDS
);
1191 this->InvalidateRect(rect
);