1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // SyncDlg.cpp : implementation file
24 #include "TortoiseProc.h"
27 #include "ProgressDlg.h"
28 #include "MessageBox.h"
29 #include "ImportPatchDlg.h"
30 #include "RebaseDlg.h"
32 #include "SmartHandle.h"
33 #include "ProgressCommands/FetchProgressCommand.h"
37 IMPLEMENT_DYNAMIC(CSyncDlg
, CResizableStandAloneDialog
)
39 CSyncDlg::CSyncDlg(CWnd
* pParent
/*=NULL*/)
40 : CResizableStandAloneDialog(CSyncDlg::IDD
, pParent
)
43 m_pTooltip
=&this->m_tooltips
;
46 m_bAutoLoadPuttyKey
= CAppUtils::IsSSHPutty();
54 m_bWantToExit
= false;
56 m_startTick
= GetTickCount();
64 void CSyncDlg::DoDataExchange(CDataExchange
* pDX
)
66 CDialog::DoDataExchange(pDX
);
67 DDX_Check(pDX
, IDC_CHECK_PUTTY_KEY
, m_bAutoLoadPuttyKey
);
68 DDX_Check(pDX
, IDC_CHECK_FORCE
,m_bForce
);
69 DDX_Control(pDX
, IDC_COMBOBOXEX_URL
, m_ctrlURL
);
70 DDX_Control(pDX
, IDC_BUTTON_TABCTRL
, m_ctrlDumyButton
);
71 DDX_Control(pDX
, IDC_BUTTON_PULL
, m_ctrlPull
);
72 DDX_Control(pDX
, IDC_BUTTON_PUSH
, m_ctrlPush
);
73 DDX_Control(pDX
, IDC_STATIC_STATUS
, m_ctrlStatus
);
74 DDX_Control(pDX
, IDC_PROGRESS_SYNC
, m_ctrlProgress
);
75 DDX_Control(pDX
, IDC_ANIMATE_SYNC
, m_ctrlAnimate
);
76 DDX_Control(pDX
, IDC_BUTTON_SUBMODULE
,m_ctrlSubmodule
);
77 DDX_Control(pDX
, IDC_BUTTON_STASH
, m_ctrlStash
);
78 DDX_Control(pDX
, IDC_PROG_LABEL
, m_ctrlProgLabel
);
83 BEGIN_MESSAGE_MAP(CSyncDlg
, CResizableStandAloneDialog
)
84 ON_BN_CLICKED(IDC_BUTTON_PULL
, &CSyncDlg::OnBnClickedButtonPull
)
85 ON_BN_CLICKED(IDC_BUTTON_PUSH
, &CSyncDlg::OnBnClickedButtonPush
)
86 ON_BN_CLICKED(IDC_BUTTON_APPLY
, &CSyncDlg::OnBnClickedButtonApply
)
87 ON_BN_CLICKED(IDC_BUTTON_EMAIL
, &CSyncDlg::OnBnClickedButtonEmail
)
88 ON_BN_CLICKED(IDC_BUTTON_MANAGE
, &CSyncDlg::OnBnClickedButtonManage
)
90 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL
, &CSyncDlg::OnCbnEditchangeComboboxex
)
91 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH
, &CSyncDlg::OnCbnEditchangeComboboxex
)
92 ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI
, OnProgressUpdateUI
)
93 ON_MESSAGE(WM_PROG_CMD_FINISH
, OnProgCmdFinish
)
94 ON_NOTIFY(LVN_COLUMNCLICK
, IDC_IN_LOGLIST
, OnLvnInLogListColumnClick
)
95 ON_BN_CLICKED(IDC_BUTTON_COMMIT
, &CSyncDlg::OnBnClickedButtonCommit
)
96 ON_BN_CLICKED(IDC_BUTTON_SUBMODULE
, &CSyncDlg::OnBnClickedButtonSubmodule
)
97 ON_BN_CLICKED(IDC_BUTTON_STASH
, &CSyncDlg::OnBnClickedButtonStash
)
99 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
100 ON_BN_CLICKED(IDC_CHECK_FORCE
, &CSyncDlg::OnBnClickedCheckForce
)
101 ON_BN_CLICKED(IDC_LOG
, &CSyncDlg::OnBnClickedLog
)
106 void CSyncDlg::EnableControlButton(bool bEnabled
)
108 GetDlgItem(IDC_BUTTON_PULL
)->EnableWindow(bEnabled
);
109 GetDlgItem(IDC_BUTTON_PUSH
)->EnableWindow(bEnabled
);
110 GetDlgItem(IDC_BUTTON_APPLY
)->EnableWindow(bEnabled
);
111 GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(bEnabled
);
112 GetDlgItem(IDOK
)->EnableWindow(bEnabled
);
113 GetDlgItem(IDC_BUTTON_SUBMODULE
)->EnableWindow(bEnabled
);
114 GetDlgItem(IDC_BUTTON_STASH
)->EnableWindow(bEnabled
);
116 // CSyncDlg message handlers
118 void CSyncDlg::OnBnClickedButtonPull()
121 CurrentEntry
= (int)this->m_ctrlPull
.GetCurrentEntry();
122 this->m_regPullButton
= CurrentEntry
;
124 this->m_bAbort
=false;
125 this->m_GitCmdList
.clear();
126 m_ctrlCmdOut
.SetWindowTextW(_T(""));
132 if (g_Git
.GetHash(m_oldHash
, _T("HEAD")))
134 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
139 m_newHashMap
.clear();
140 m_oldHashMap
.clear();
142 if( CurrentEntry
== 0)
144 CGitHash localBranchHash
;
145 if (g_Git
.GetHash(localBranchHash
, m_strLocalBranch
))
147 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_strLocalBranch
+ _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
150 if (localBranchHash
!= m_oldHash
)
152 CMessageBox::Show(NULL
, IDS_PROC_SYNC_PULLWRONGBRANCH
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
157 if(this->m_strURL
.IsEmpty())
159 CMessageBox::Show(NULL
, IDS_PROC_GITCONFIG_URLEMPTY
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
163 if (m_bAutoLoadPuttyKey
&& CurrentEntry
!= 3) // CurrentEntry (Remote Update) handles this on its own)
165 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
169 if (g_Git
.GetMapHashToFriendName(m_oldHashMap
))
170 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
174 force
= _T(" --force ");
178 ShowTab(IDC_CMD_LOG
);
180 this->m_ctrlTabCtrl
.ShowTab(IDC_REFLIST
-1,true);
181 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
182 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
183 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
186 if(CurrentEntry
== 0) //Pull
188 CString remotebranch
;
189 remotebranch
= m_strRemoteBranch
;
193 CString pullRemote
, pullBranch
;
194 g_Git
.GetRemoteTrackedBranch(m_strLocalBranch
, pullRemote
, pullBranch
);
195 if(pullBranch
== remotebranch
&& pullRemote
== this->m_strURL
)
196 remotebranch
.Empty();
199 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
200 force
+= _T("--progress ");
202 cmd
.Format(_T("git.exe pull -v %s \"%s\" %s"),
207 m_CurrentCmd
= GIT_COMMAND_PULL
;
208 m_GitCmdList
.push_back(cmd
);
210 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
213 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
217 m_pThread
->m_bAutoDelete
= TRUE
;
218 m_pThread
->ResumeThread();
224 if(CurrentEntry
== 1 || CurrentEntry
==2 ) //Fetch
226 CString remotebranch
;
227 if(this->IsURL() || m_strRemoteBranch
.IsEmpty())
229 remotebranch
=this->m_strRemoteBranch
;
234 remotebranch
.Format(_T("remotes/%s/%s"),
235 m_strURL
,m_strRemoteBranch
);
236 CGitHash remoteBranchHash
;
237 g_Git
.GetHash(remoteBranchHash
, remotebranch
);
238 if (remoteBranchHash
.IsEmpty())
239 remotebranch
=m_strRemoteBranch
;
241 remotebranch
=m_strRemoteBranch
+_T(":")+remotebranch
;
244 if(CurrentEntry
== 1)
245 m_CurrentCmd
= GIT_COMMAND_FETCH
;
247 m_CurrentCmd
= GIT_COMMAND_FETCHANDREBASE
;
249 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
252 // current libgit2 only supports well formated refspec
253 refspec
.Format(_T("refs/heads/%s:refs/remotes/%s/%s"), m_strRemoteBranch
, m_strURL
, m_strRemoteBranch
);
255 FetchProgressCommand fetchProgressCommand
;
256 fetchProgressCommand
.SetUrl(m_strURL
);
257 fetchProgressCommand
.SetRefSpec(refspec
);
258 m_GitProgressList
.SetCommand(&fetchProgressCommand
);
259 m_GitProgressList
.Init();
260 ShowTab(IDC_CMD_GIT_PROG
);
264 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
265 force
+= _T("--progress ");
267 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"),
272 m_GitCmdList
.push_back(cmd
);
274 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
277 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
281 m_pThread
->m_bAutoDelete
= TRUE
;
282 m_pThread
->ResumeThread();
288 if(CurrentEntry
== 3)
290 if (m_bAutoLoadPuttyKey
)
293 if (!g_Git
.GetRemoteList(list
))
295 for (size_t i
= 0; i
< list
.size(); ++i
)
296 CAppUtils::LaunchPAgent(NULL
, &list
[i
]);
300 m_CurrentCmd
= GIT_COMMAND_REMOTE
;
301 cmd
=_T("git.exe remote update");
302 m_GitCmdList
.push_back(cmd
);
304 InterlockedExchange(&m_bBlock
, TRUE
);
306 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
309 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
310 InterlockedExchange(&m_bBlock
, FALSE
);
314 m_pThread
->m_bAutoDelete
= TRUE
;
315 m_pThread
->ResumeThread();
319 ///Cleanup stale remote banches
320 if(CurrentEntry
== 4)
322 m_CurrentCmd
= GIT_COMMAND_REMOTE
;
323 cmd
.Format(_T("git.exe remote prune \"%s\""), m_strURL
);
324 m_GitCmdList
.push_back(cmd
);
326 InterlockedExchange(&m_bBlock
, TRUE
);
328 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
331 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
332 InterlockedExchange(&m_bBlock
, FALSE
);
336 m_pThread
->m_bAutoDelete
= TRUE
;
337 m_pThread
->ResumeThread();
342 void CSyncDlg::PullComplete()
344 EnableControlButton(true);
346 this->FetchOutList(true);
349 if (g_Git
.GetHash(newhash
, _T("HEAD")))
350 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash after pulling.")), _T("TortoiseGit"), MB_ICONERROR
);
352 if( this ->m_GitCmdStatus
)
354 int hasConflicts
= g_Git
.HasWorkingTreeConflicts();
355 if (hasConflicts
< 0)
357 this->m_ctrlCmdOut
.SetSel(-1,-1);
358 this->m_ctrlCmdOut
.ReplaceSel(g_Git
.GetGitLastErr(L
"Checking for conflicts failed.", CGit::GIT_CMD_CHECKCONFLICTS
));
360 this->ShowTab(IDC_CMD_LOG
);
366 this->m_ConflictFileList
.Clear();
371 this->m_ConflictFileList
.GetStatus(&list
,true);
372 this->m_ConflictFileList
.Show(CTGitPath::LOGACTIONS_UNMERGED
,
373 CTGitPath::LOGACTIONS_UNMERGED
);
375 this->ShowTab(IDC_IN_CONFLICT
);
378 this->ShowTab(IDC_CMD_LOG
);
383 if(newhash
== this->m_oldHash
)
385 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
386 this->m_InLogList
.ShowText(CString(MAKEINTRESOURCE(IDS_UPTODATE
)));
387 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
388 this->ShowTab(IDC_REFLIST
);
392 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
393 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
395 this->AddDiffFileList(&m_InChangeFileList
, &m_arInChangeList
, newhash
.ToString(), m_oldHash
.ToString());
398 range
.Format(_T("%s..%s"), m_oldHash
.ToString(), newhash
.ToString());
399 m_InLogList
.FillGitLog(nullptr, &range
, CGit::LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
);
400 this->ShowTab(IDC_IN_LOGLIST
);
405 void CSyncDlg::FetchComplete()
407 EnableControlButton(true);
409 this->FetchOutList(true);
411 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
412 ShowTab(IDC_CMD_GIT_PROG
);
414 ShowTab(IDC_REFLIST
);
419 if (m_CurrentCmd
!= GIT_COMMAND_FETCHANDREBASE
)
423 CString remotebranch
;
425 m_ctrlURL
.GetWindowText(remote
);
426 if (!remote
.IsEmpty())
428 STRING_VECTOR remotes
;
429 g_Git
.GetRemoteList(remotes
);
430 if (std::find(remotes
.begin(), remotes
.end(), remote
) == remotes
.end())
433 m_ctrlRemoteBranch
.GetWindowText(remotebranch
);
434 if (!remote
.IsEmpty() && !remotebranch
.IsEmpty())
435 upstream
= _T("remotes/") + remote
+ _T("/") + remotebranch
;
437 CAppUtils::RebaseAfterFetch(upstream
);
440 void CSyncDlg::StashComplete()
442 EnableControlButton(true);
443 INT_PTR entry
= m_ctrlStash
.GetCurrentEntry();
444 if (entry
!= 1 && entry
!= 2)
450 int hasConflicts
= g_Git
.HasWorkingTreeConflicts();
451 if (hasConflicts
< 0)
453 m_ctrlCmdOut
.SetSel(-1, -1);
454 m_ctrlCmdOut
.ReplaceSel(g_Git
.GetGitLastErr(L
"Checking for conflicts failed.", CGit::GIT_CMD_CHECKCONFLICTS
));
456 ShowTab(IDC_CMD_LOG
);
462 m_ConflictFileList
.Clear();
467 m_ConflictFileList
.GetStatus(&list
,true);
468 m_ConflictFileList
.Show(CTGitPath::LOGACTIONS_UNMERGED
, CTGitPath::LOGACTIONS_UNMERGED
);
470 ShowTab(IDC_IN_CONFLICT
);
473 ShowTab(IDC_CMD_LOG
);
477 void CSyncDlg::OnBnClickedButtonPush()
481 m_ctrlCmdOut
.SetWindowTextW(_T(""));
484 if(this->m_strURL
.IsEmpty())
486 CMessageBox::Show(NULL
, IDS_PROC_GITCONFIG_URLEMPTY
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
490 this->m_regPushButton
=(DWORD
)this->m_ctrlPush
.GetCurrentEntry();
492 this->m_bAbort
=false;
493 this->m_GitCmdList
.clear();
495 ShowTab(IDC_CMD_LOG
);
501 DWORD exitcode
= 0xFFFFFFFF;
502 if (CHooks::Instance().PrePush(g_Git
.m_CurrentDir
, exitcode
, error
))
507 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
508 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
513 CString refName
= g_Git
.FixBranchName(m_strLocalBranch
);
514 switch (m_ctrlPush
.GetCurrentEntry())
517 arg
+= _T(" --tags ");
520 refName
= _T("refs/notes/commits"); //default ref for notes
525 arg
+= _T(" --force ");
527 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
528 arg
+= _T("--progress ");
530 cmd
.Format(_T("git.exe push -v %s \"%s\" %s"),
535 if (!m_strRemoteBranch
.IsEmpty() && m_ctrlPush
.GetCurrentEntry() != 2)
537 cmd
+= _T(":") + m_strRemoteBranch
;
540 m_GitCmdList
.push_back(cmd
);
542 m_CurrentCmd
= GIT_COMMAND_PUSH
;
544 if(this->m_bAutoLoadPuttyKey
)
546 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
549 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
552 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
556 m_pThread
->m_bAutoDelete
= TRUE
;
557 m_pThread
->ResumeThread();
561 void CSyncDlg::OnBnClickedButtonApply()
564 if (g_Git
.GetHash(oldhash
, _T("HEAD")))
566 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
573 if(dlg
.DoModal() == IDOK
)
576 for (int i
= 0; i
< dlg
.m_PathList
.GetCount(); ++i
)
578 cmd
.Format(_T("git.exe am \"%s\""),dlg
.m_PathList
[i
].GetGitPathString());
580 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
582 CMessageBox::Show(NULL
,output
,_T("TortoiseGit"),MB_OK
);
587 this->m_ctrlCmdOut
.SetSel(-1,-1);
588 this->m_ctrlCmdOut
.ReplaceSel(cmd
+_T("\n"));
589 this->m_ctrlCmdOut
.SetSel(-1,-1);
590 this->m_ctrlCmdOut
.ReplaceSel(output
);
594 if (g_Git
.GetHash(newhash
, _T("HEAD")))
596 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash after applying patches.")), _T("TortoiseGit"), MB_ICONERROR
);
600 this->m_InLogList
.Clear();
601 this->m_InChangeFileList
.Clear();
603 if(newhash
== oldhash
)
605 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
606 this->m_InLogList
.ShowText(_T("No commits get from patch"));
607 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
612 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
613 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
616 range
.Format(_T("%s..%s"), m_oldHash
.ToString(), newhash
.ToString());
617 this->AddDiffFileList(&m_InChangeFileList
, &m_arInChangeList
, newhash
.ToString(), oldhash
.ToString());
618 m_InLogList
.FillGitLog(nullptr, &range
, CGit::LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
);
620 this->FetchOutList(true);
623 this->m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,true);
627 this->ShowTab(IDC_CMD_LOG
);
631 this->ShowTab(IDC_IN_LOGLIST
);
636 void CSyncDlg::OnBnClickedButtonEmail()
638 CString cmd
, out
, err
;
640 this->m_strLocalBranch
= this->m_ctrlLocalBranch
.GetString();
641 this->m_ctrlRemoteBranch
.GetWindowText(this->m_strRemoteBranch
);
642 this->m_ctrlURL
.GetWindowText(this->m_strURL
);
643 m_strURL
=m_strURL
.Trim();
644 m_strRemoteBranch
=m_strRemoteBranch
.Trim();
646 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
648 m_strURL
+_T('/')+m_strRemoteBranch
,g_Git
.FixBranchName(m_strLocalBranch
));
650 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
652 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
656 CAppUtils::SendPatchMail(cmd
,out
);
659 void CSyncDlg::ShowProgressCtrl(bool bShow
)
661 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
662 this->m_ctrlAnimate
.ShowWindow(b
);
663 this->m_ctrlProgress
.ShowWindow(b
);
664 this->m_ctrlProgLabel
.ShowWindow(b
);
665 this->m_ctrlAnimate
.Open(IDR_DOWNLOAD
);
667 this->m_ctrlAnimate
.Play(0, UINT_MAX
, UINT_MAX
);
669 this->m_ctrlAnimate
.Stop();
671 void CSyncDlg::ShowInputCtrl(bool bShow
)
673 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
674 this->m_ctrlURL
.ShowWindow(b
);
675 this->m_ctrlLocalBranch
.ShowWindow(b
);
676 this->m_ctrlRemoteBranch
.ShowWindow(b
);
677 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH
)->ShowWindow(b
);
678 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH
)->ShowWindow(b
);
679 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH
)->ShowWindow(b
);
680 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH
)->ShowWindow(b
);
681 this->GetDlgItem(IDC_BUTTON_MANAGE
)->ShowWindow(b
);
682 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->ShowWindow(b
);
683 this->GetDlgItem(IDC_CHECK_FORCE
)->ShowWindow(b
);
684 this->GetDlgItem(IDC_STATIC_REMOTE_URL
)->ShowWindow(b
);
686 BOOL
CSyncDlg::OnInitDialog()
688 CResizableStandAloneDialog::OnInitDialog();
689 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
691 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
692 // do this, Explorer would be unable to send that message to our window if we
693 // were running elevated. It's OK to make the call all the time, since if we're
694 // not elevated, this is a no-op.
695 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
696 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
697 CAutoLibrary hUser
= AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
700 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
701 if (pfnChangeWindowMessageFilterEx
)
703 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
706 m_pTaskbarList
.Release();
707 if (FAILED(m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
)))
708 m_pTaskbarList
= nullptr;
710 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->EnableWindow(CAppUtils::IsSSHPutty());
713 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
714 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
715 this->m_ctrlAnimate.Play(0,-1,-1);
718 // ------------------ Create Tabctrl -----------
719 CWnd
*pwnd
=this->GetDlgItem(IDC_BUTTON_TABCTRL
);
721 pwnd
->GetWindowRect(&rectDummy
);
722 this->ScreenToClient(rectDummy
);
724 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_SYNC_TAB
))
726 TRACE0("Failed to create output tab window\n");
727 return FALSE
; // fail to create
729 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
731 // -------------Create Command Log Ctrl ---------
733 dwStyle
= ES_MULTILINE
| ES_READONLY
| WS_CHILD
| WS_VISIBLE
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
|WS_VSCROLL
;
735 if( !m_ctrlCmdOut
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_CMD_LOG
))
737 TRACE0("Failed to create Log commits window\n");
738 return FALSE
; // fail to create
741 // set the font to use in the log message view, configured in the settings dialog
743 CAppUtils::CreateFontForLogs(m_logFont
);
744 //GetDlgItem(IDC_CMD_LOG)->SetFont(&m_logFont);
745 m_ctrlCmdOut
.SetFont(&m_logFont
);
746 m_ctrlTabCtrl
.InsertTab(&m_ctrlCmdOut
, CString(MAKEINTRESOURCE(IDS_LOG
)), -1);
748 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
750 //---------- Create in coming list ctrl -----------
751 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
753 if( !m_InLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_LOGLIST
))
755 TRACE0("Failed to create output commits window\n");
756 return FALSE
; // fail to create
759 m_ctrlTabCtrl
.InsertTab(&m_InLogList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_INCOMMITS
)), -1);
761 m_InLogList
.m_ColumnRegKey
=_T("SyncIn");
762 m_InLogList
.InsertGitColumn();
764 //----------- Create In Change file list -----------
765 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
767 if( !m_InChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CHANGELIST
))
769 TRACE0("Failed to create output change files window\n");
770 return FALSE
; // fail to create
772 m_ctrlTabCtrl
.InsertTab(&m_InChangeFileList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_INCHANGELIST
)), -1);
774 m_InChangeFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("InSyncDlg"),
775 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWOREVISIONS
) |
776 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2REVISIONS
)), false, true, GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
);
779 //---------- Create Conflict List Ctrl -----------------
780 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
782 if( !m_ConflictFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CONFLICT
))
784 TRACE0("Failed to create output change files window\n");
785 return FALSE
; // fail to create
787 m_ctrlTabCtrl
.InsertTab(&m_ConflictFileList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_CONFLICTS
)), -1);
789 m_ConflictFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("ConflictSyncDlg"),
790 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWOREVISIONS
) |
791 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2REVISIONS
) |
792 GITSLC_POPCONFLICT
|GITSLC_POPRESOLVE
),false);
795 //---------- Create Commit Out List Ctrl---------------
797 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
799 if( !m_OutLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_LOGLIST
))
801 TRACE0("Failed to create output commits window\n");
802 return FALSE
; // fail to create
806 m_ctrlTabCtrl
.InsertTab(&m_OutLogList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_OUTCOMMITS
)), -1);
808 m_OutLogList
.m_ColumnRegKey
= _T("SyncOut");
809 m_OutLogList
.InsertGitColumn();
811 //------------- Create Change File List Control ----------------
813 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
815 if( !m_OutChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_CHANGELIST
))
817 TRACE0("Failed to create output change files window\n");
818 return FALSE
; // fail to create
820 m_ctrlTabCtrl
.InsertTab(&m_OutChangeFileList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_OUTCHANGELIST
)), -1);
822 m_OutChangeFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
, _T("OutSyncDlg"),
823 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWOREVISIONS
) |
824 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2REVISIONS
)), false, true, GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
);
826 if (!m_GitProgressList
.Create(dwStyle
| LVS_OWNERDATA
, rectDummy
, &m_ctrlTabCtrl
, IDC_CMD_GIT_PROG
))
828 TRACE0("Failed to create Git Progress List Window\n");
829 return FALSE
; // fail to create
831 m_ctrlTabCtrl
.InsertTab(&m_GitProgressList
, CString(MAKEINTRESOURCE(IDS_LOG
)), -1);
832 m_GitProgressList
.m_pAnimate
= &m_ctrlAnimate
;
833 m_GitProgressList
.m_pPostWnd
= this;
834 m_GitProgressList
.m_pProgressLabelCtrl
= &m_ctrlProgLabel
;
835 m_GitProgressList
.m_pProgControl
= &m_ctrlProgress
;
836 m_GitProgressList
.m_pTaskbarList
= m_pTaskbarList
;
838 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
839 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_FULLROWSELECT
;
840 m_refList
.Create(dwStyle
, rectDummy
, &m_ctrlTabCtrl
, IDC_REFLIST
);
841 m_refList
.SetExtendedStyle(exStyle
);
843 m_ctrlTabCtrl
.InsertTab(&m_refList
, CString(MAKEINTRESOURCE(IDS_REFLIST
)), -1);
845 AddAnchor(IDC_SYNC_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
847 AddAnchor(IDC_GROUP_INFO
,TOP_LEFT
,TOP_RIGHT
);
848 AddAnchor(IDC_COMBOBOXEX_URL
,TOP_LEFT
,TOP_RIGHT
);
849 AddAnchor(IDC_BUTTON_MANAGE
,TOP_RIGHT
);
850 AddAnchor(IDC_BUTTON_PULL
,BOTTOM_LEFT
);
851 AddAnchor(IDC_BUTTON_PUSH
,BOTTOM_LEFT
);
852 AddAnchor(IDC_BUTTON_SUBMODULE
,BOTTOM_LEFT
);
853 AddAnchor(IDC_BUTTON_STASH
,BOTTOM_LEFT
);
854 AddAnchor(IDC_BUTTON_APPLY
,BOTTOM_RIGHT
);
855 AddAnchor(IDC_BUTTON_EMAIL
,BOTTOM_RIGHT
);
856 AddAnchor(IDC_PROGRESS_SYNC
,TOP_LEFT
,TOP_RIGHT
);
857 AddAnchor(IDOK
,BOTTOM_RIGHT
);
858 AddAnchor(IDHELP
,BOTTOM_RIGHT
);
859 AddAnchor(IDC_STATIC_STATUS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
860 AddAnchor(IDC_ANIMATE_SYNC
,TOP_LEFT
);
861 AddAnchor(IDC_BUTTON_COMMIT
,BOTTOM_LEFT
);
862 AddAnchor(IDC_LOG
, BOTTOM_LEFT
);
864 // do not use BRANCH_COMBOX_ADD_ANCHOR here, we want to have different stylings
865 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH
, TOP_LEFT
,TOP_CENTER
);
866 AddAnchor(IDC_COMBOBOXEX_REMOTE_BRANCH
, TOP_CENTER
, TOP_RIGHT
);
867 AddAnchor(IDC_BUTTON_LOCAL_BRANCH
, TOP_CENTER
);
868 AddAnchor(IDC_BUTTON_REMOTE_BRANCH
, TOP_RIGHT
);
869 AddAnchor(IDC_STATIC_REMOTE_BRANCH
, TOP_CENTER
);
870 AddAnchor(IDC_PROG_LABEL
, TOP_LEFT
);
872 AdjustControlSize(IDC_CHECK_PUTTY_KEY
);
873 AdjustControlSize(IDC_CHECK_FORCE
);
875 CString WorkingDir
=g_Git
.m_CurrentDir
;
876 WorkingDir
.Replace(_T(':'),_T('_'));
877 m_RegKeyRemoteBranch
= CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir
;
880 this->AddOthersToAnchor();
882 this->m_ctrlPush
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PUSH
)));
883 this->m_ctrlPush
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PUSHTAGS
)));
884 this->m_ctrlPush
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PUSHNOTES
)));
886 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PULL
)));
887 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_FETCH
)));
888 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_FETCHREBASE
)));
889 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_REMOTEUPDATE
)));
890 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_CLEANUPSTALEBRANCHES
)));
892 this->m_ctrlSubmodule
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULEUPDATE
)));
893 this->m_ctrlSubmodule
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULEINIT
)));
894 this->m_ctrlSubmodule
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULESYNC
)));
896 this->m_ctrlStash
.AddEntry(CString(MAKEINTRESOURCE(IDS_MENUSTASHSAVE
)));
897 this->m_ctrlStash
.AddEntry(CString(MAKEINTRESOURCE(IDS_MENUSTASHPOP
)));
898 this->m_ctrlStash
.AddEntry(CString(MAKEINTRESOURCE(IDS_MENUSTASHAPPLY
)));
900 WorkingDir
.Replace(_T(':'),_T('_'));
903 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir
);
905 this->m_regPullButton
= CRegDWORD(regkey
+_T("\\Pull"),0);
906 this->m_regPushButton
= CRegDWORD(regkey
+_T("\\Push"),0);
907 this->m_regSubmoduleButton
= CRegDWORD(regkey
+_T("\\Submodule"));
908 this->m_regAutoLoadPutty
= CRegDWORD(regkey
+ _T("\\AutoLoadPutty"), CAppUtils::IsSSHPutty());
911 this->m_bAutoLoadPuttyKey
= m_regAutoLoadPutty
;
912 if(!CAppUtils::IsSSHPutty())
913 m_bAutoLoadPuttyKey
= false;
914 this->UpdateData(FALSE
);
916 this->m_ctrlPull
.SetCurrentEntry(this->m_regPullButton
);
917 this->m_ctrlPush
.SetCurrentEntry(this->m_regPushButton
);
918 this->m_ctrlSubmodule
.SetCurrentEntry(this->m_regSubmoduleButton
);
920 CString sWindowTitle
;
921 GetWindowText(sWindowTitle
);
922 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
924 EnableSaveRestore(_T("SyncDlg"));
926 m_ctrlURL
.SetCaseSensitive(TRUE
);
927 m_ctrlURL
.SetURLHistory(true);
928 m_ctrlURL
.SetMaxHistoryItems(0x7FFFFFFF);
929 this->m_ctrlURL
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir
, _T("url"));
933 if(!g_Git
.GetRemoteList(list
))
935 for (unsigned int i
= 0; i
< list
.size(); ++i
)
937 m_ctrlURL
.AddString(list
[i
]);
940 m_ctrlURL
.SetCurSel(0);
941 m_ctrlRemoteBranch
.SetCurSel(0);
943 this->LoadBranchInfo();
945 this->m_bInited
=true;
948 m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,false);
949 m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
950 m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
951 m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
952 m_ctrlTabCtrl
.ShowTab(IDC_CMD_GIT_PROG
-1, false);
953 m_ctrlTabCtrl
.ShowTab(IDC_REFLIST
-1, false);
955 m_ctrlRemoteBranch
.m_bWantReturn
= TRUE
;
956 m_ctrlURL
.m_bWantReturn
= TRUE
;
958 this->m_Gitverion
= CAppUtils::GetMsysgitVersion();
960 if (m_seq
> 0 && (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\SyncDialogRandomPos")))
964 GetWindowRect(&rect
);
965 rect
.top
-= m_seq
* 30;
966 rect
.bottom
-= m_seq
* 30;
972 MoveWindow(rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
975 return TRUE
; // return TRUE unless you set the focus to a control
976 // EXCEPTION: OCX Property Pages should return FALSE
979 void CSyncDlg::OnBnClickedButtonManage()
981 CAppUtils::LaunchRemoteSetting();
985 void CSyncDlg::Refresh()
987 theApp
.DoWaitCursor(1);
989 int lastSelected
= m_ctrlURL
.GetCurSel();
991 this->m_ctrlURL
.GetWindowText(url
);
993 this->m_ctrlURL
.Reset();
994 CString workingDir
= g_Git
.m_CurrentDir
;
995 workingDir
.Replace(_T(':'), _T('_'));
996 this->m_ctrlURL
.LoadHistory(_T("Software\\TortoiseGit\\History\\SyncURL\\") + workingDir
, _T("url"));
1000 if (!g_Git
.GetRemoteList(list
))
1002 for (size_t i
= 0; i
< list
.size(); ++i
)
1004 m_ctrlURL
.AddString(list
[i
]);
1009 if (lastSelected
>= 0 && !found
)
1011 m_ctrlURL
.SetCurSel(0);
1012 m_ctrlURL
.GetWindowText(url
);
1017 this->m_ctrlLocalBranch
.GetWindowText(local
);
1018 this->m_ctrlRemoteBranch
.GetWindowText(remote
);
1020 this->LoadBranchInfo();
1022 this->m_ctrlLocalBranch
.AddString(local
);
1023 this->m_ctrlRemoteBranch
.AddString(remote
);
1024 this->m_ctrlURL
.AddString(url
);
1026 m_OutLogList
.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_REFRESHING
)));
1027 this->FetchOutList(true);
1028 theApp
.DoWaitCursor(-1);
1031 BOOL
CSyncDlg::PreTranslateMessage(MSG
* pMsg
)
1033 if (pMsg
->message
== WM_KEYDOWN
)
1035 switch (pMsg
->wParam
)
1041 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1046 /* Avoid TAB control destroy but dialog exist*/
1050 TCHAR buff
[128] = { 0 };
1051 ::GetClassName(pMsg
->hwnd
,buff
,128);
1053 /* Use MSFTEDIT_CLASS http://msdn.microsoft.com/en-us/library/bb531344.aspx */
1054 if (_tcsnicmp(buff
, MSFTEDIT_CLASS
, 128) == 0 || //Unicode and MFC 2012 and later
1055 _tcsnicmp(buff
, RICHEDIT_CLASS
, 128) == 0 || //ANSI or MFC 2010
1056 _tcsnicmp(buff
, _T("SysListView32"), 128) == 0)
1058 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
1064 return __super::PreTranslateMessage(pMsg
);
1066 void CSyncDlg::FetchOutList(bool force
)
1070 m_OutChangeFileList
.Clear();
1071 this->m_OutLogList
.Clear();
1074 this->m_ctrlURL
.GetWindowText(remote
);
1075 CString remotebranch
;
1076 this->m_ctrlRemoteBranch
.GetWindowText(remotebranch
);
1077 remotebranch
=remote
+_T("/")+remotebranch
;
1078 CGitHash remotebranchHash
;
1079 g_Git
.GetHash(remotebranchHash
, remotebranch
);
1084 str
.LoadString(IDS_PROC_SYNC_PUSH_UNKNOWN
);
1085 m_OutLogList
.ShowText(str
);
1086 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
1087 m_OutLocalBranch
.Empty();
1088 m_OutRemoteBranch
.Empty();
1090 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1094 else if(remotebranchHash
.IsEmpty())
1097 str
.Format(IDS_PROC_SYNC_PUSH_UNKNOWNBRANCH
, remotebranch
);
1098 m_OutLogList
.ShowText(str
);
1099 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
1100 m_OutLocalBranch
.Empty();
1101 m_OutRemoteBranch
.Empty();
1103 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1108 CString localbranch
;
1109 localbranch
=this->m_ctrlLocalBranch
.GetString();
1111 if(localbranch
!= m_OutLocalBranch
|| m_OutRemoteBranch
!= remotebranch
|| force
)
1113 m_OutLogList
.ClearText();
1115 CGitHash base
, localBranchHash
;
1116 bool isFastForward
= g_Git
.IsFastForward(remotebranch
, localbranch
, &base
);
1118 if (g_Git
.GetHash(localBranchHash
, localbranch
))
1120 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + localbranch
+ _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
1123 if (remotebranchHash
== localBranchHash
)
1126 str
.Format(IDS_PROC_SYNC_COMMITSAHEAD
, 0, remotebranch
);
1127 m_OutLogList
.ShowText(str
);
1128 this->m_ctrlStatus
.SetWindowText(str
);
1129 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
1130 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1132 else if (isFastForward
|| m_bForce
)
1135 range
.Format(_T("%s..%s"), g_Git
.FixBranchName(remotebranch
), g_Git
.FixBranchName(localbranch
));
1137 m_OutLogList
.FillGitLog(nullptr, &range
, CGit::LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
);
1139 str
.Format(IDS_PROC_SYNC_COMMITSAHEAD
, m_OutLogList
.GetItemCount(), remotebranch
);
1140 this->m_ctrlStatus
.SetWindowText(str
);
1143 AddDiffFileList(&m_OutChangeFileList
, &m_arOutChangeList
, localbranch
, remotebranch
);
1146 AddDiffFileList(&m_OutChangeFileList
, &m_arOutChangeList
, localbranch
, base
.ToString());
1149 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,TRUE
);
1150 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(TRUE
);
1155 str
.Format(IDS_PROC_SYNC_NOFASTFORWARD
, localbranch
, remotebranch
);
1156 m_OutLogList
.ShowText(str
);
1157 this->m_ctrlStatus
.SetWindowText(str
);
1158 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID() - 1, FALSE
);
1159 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1162 this->m_OutLocalBranch
=localbranch
;
1163 this->m_OutRemoteBranch
=remotebranch
;
1168 bool CSyncDlg::IsURL()
1171 this->m_ctrlURL
.GetWindowText(str
);
1172 if(str
.Find(_T('\\'))>=0 || str
.Find(_T('/'))>=0)
1177 void CSyncDlg::OnCbnEditchangeComboboxex()
1179 SetTimer(IDT_INPUT
, 1000, NULL
);
1180 this->m_OutLogList
.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_WAINTINPUT
)));
1182 //this->FetchOutList();
1185 UINT
CSyncDlg::ProgressThread()
1187 m_startTick
= GetTickCount();
1190 CProgressDlg::RunCmdList(this, m_GitCmdList
, list
, true, nullptr, &this->m_bAbort
, &this->m_Databuf
);
1191 InterlockedExchange(&m_bBlock
, FALSE
);
1196 LRESULT
CSyncDlg::OnProgressUpdateUI(WPARAM wParam
,LPARAM lParam
)
1198 if(wParam
== MSG_PROGRESSDLG_START
)
1201 m_ctrlAnimate
.Play(0, UINT_MAX
, UINT_MAX
);
1202 this->m_ctrlProgress
.SetPos(0);
1205 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1206 m_pTaskbarList
->SetProgressValue(m_hWnd
, 0, 100);
1210 if(wParam
== MSG_PROGRESSDLG_END
|| wParam
== MSG_PROGRESSDLG_FAILED
)
1212 DWORD tickSpent
= GetTickCount() - m_startTick
;
1213 CString strEndTime
= CLoglistUtils::FormatDateAndTime(CTime::GetCurrentTime(), DATE_SHORTDATE
, true, false);
1216 m_Databuf
.m_critSec
.Lock();
1218 m_Databuf
.m_critSec
.Unlock();
1221 m_ctrlAnimate
.Stop();
1222 m_ctrlProgress
.SetPos(100);
1223 //this->DialogEnableWindow(IDOK,TRUE);
1225 DWORD exitCode
= (DWORD
)lParam
;
1230 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
1231 m_pTaskbarList
->SetProgressValue(m_hWnd
, 100, 100);
1234 log
.Format(IDS_PROC_PROGRESS_GITUNCLEANEXIT
, exitCode
);
1236 err
.Format(_T("\r\n\r\n%s (%lu ms @ %s)\r\n"), log
, tickSpent
, strEndTime
);
1237 CProgressDlg::InsertColorText(this->m_ctrlCmdOut
, err
, RGB(255,0,0));
1238 if (CRegDWORD(_T("Software\\TortoiseGit\\NoSounds"), FALSE
) == FALSE
)
1239 PlaySound((LPCTSTR
)SND_ALIAS_SYSTEMEXCLAMATION
, NULL
, SND_ALIAS_ID
| SND_ASYNC
);
1244 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1246 temp
.LoadString(IDS_SUCCESS
);
1248 log
.Format(_T("\r\n%s (%lu ms @ %s)\r\n"), temp
, tickSpent
, strEndTime
);
1249 CProgressDlg::InsertColorText(this->m_ctrlCmdOut
, log
, RGB(0,0,255));
1251 m_GitCmdStatus
= exitCode
;
1253 //if(wParam == MSG_PROGRESSDLG_END)
1258 ParserCmdOutput((char)lParam
);
1261 m_Databuf
.m_critSec
.Lock();
1262 for (size_t i
= m_BufStart
; i
< m_Databuf
.size(); ++i
)
1264 char c
= m_Databuf
[m_BufStart
];
1266 m_Databuf
.m_critSec
.Unlock();
1269 m_Databuf
.m_critSec
.Lock();
1272 if (m_BufStart
> 1000)
1274 m_Databuf
.erase(m_Databuf
.begin(), m_Databuf
.begin() + m_BufStart
);
1277 m_Databuf
.m_critSec
.Unlock();
1283 static std::map
<CString
, CGitHash
> * HashMapToRefMap(MAP_HASH_NAME
&map
)
1285 auto rmap
= new std::map
<CString
, CGitHash
>();
1286 for (auto mit
= map
.begin(); mit
!= map
.end(); ++mit
)
1288 for (auto rit
= mit
->second
.begin(); rit
!= mit
->second
.end(); ++rit
)
1290 rmap
->insert(std::make_pair(*rit
, mit
->first
));
1296 void CSyncDlg::FillNewRefMap()
1299 m_newHashMap
.clear();
1300 CAutoRepository
repo(g_Git
.GetGitRepository());
1303 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1307 if (CGit::GetMapHashToFriendName(repo
, m_newHashMap
))
1309 MessageBox(CGit::GetLibGit2LastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
1313 auto oldRefMap
= HashMapToRefMap(m_oldHashMap
);
1314 auto newRefMap
= HashMapToRefMap(m_newHashMap
);
1315 for (auto oit
= oldRefMap
->begin(); oit
!= oldRefMap
->end(); ++oit
)
1318 for (auto nit
= newRefMap
->begin(); nit
!= newRefMap
->end(); ++nit
)
1321 if (oit
->first
== nit
->first
)
1324 m_refList
.AddEntry(repo
, oit
->first
, &oit
->second
, &nit
->second
);
1331 m_refList
.AddEntry(repo
, oit
->first
, &oit
->second
, nullptr);
1334 for (auto nit
= newRefMap
->begin(); nit
!= newRefMap
->end(); ++nit
)
1337 for (auto oit
= oldRefMap
->begin(); oit
!= oldRefMap
->end(); ++oit
)
1339 if (oit
->first
== nit
->first
)
1348 m_refList
.AddEntry(repo
, nit
->first
, nullptr, &nit
->second
);
1356 void CSyncDlg::RunPostAction()
1363 if (this->m_CurrentCmd
== GIT_COMMAND_PUSH
)
1365 DWORD exitcode
= 0xFFFFFFFF;
1367 if (CHooks::Instance().PostPush(g_Git
.m_CurrentDir
, exitcode
, error
))
1372 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
1373 CMessageBox::Show(nullptr, temp
,_T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1378 EnableControlButton(true);
1380 this->FetchOutList(true);
1382 else if (this->m_CurrentCmd
== GIT_COMMAND_PULL
)
1386 else if (this->m_CurrentCmd
== GIT_COMMAND_FETCH
|| this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
1390 else if (this->m_CurrentCmd
== GIT_COMMAND_SUBMODULE
)
1392 //this->m_ctrlCmdOut.SetSel(-1,-1);
1393 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
1394 //this->m_ctrlCmdOut.SetSel(-1,-1);
1395 EnableControlButton(true);
1398 else if (this->m_CurrentCmd
== GIT_COMMAND_STASH
)
1402 else if (this->m_CurrentCmd
== GIT_COMMAND_REMOTE
)
1404 this->FetchOutList(true);
1405 EnableControlButton(true);
1407 ShowTab(IDC_REFLIST
);
1410 void CSyncDlg::ParserCmdOutput(char ch
)
1412 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut
,m_ctrlProgress
,m_hWnd
,m_pTaskbarList
,m_LogText
,ch
);
1414 void CSyncDlg::OnBnClickedButtonCommit()
1416 CString cmd
= _T("/command:commit");
1417 cmd
+= _T(" /path:\"");
1418 cmd
+= g_Git
.m_CurrentDir
;
1421 CAppUtils::RunTortoiseGitProc(cmd
);
1424 void CSyncDlg::OnOK()
1428 m_ctrlURL
.SaveHistory();
1430 m_regAutoLoadPutty
= this->m_bAutoLoadPuttyKey
;
1435 void CSyncDlg::OnCancel()
1440 CResizableStandAloneDialog::OnCancel();
1444 if (g_Git
.m_CurrentGitPi
.hProcess
)
1446 DWORD dwConfirmKillProcess
= CRegDWORD(_T("Software\\TortoiseGit\\ConfirmKillProcess"));
1447 if (dwConfirmKillProcess
&& CMessageBox::Show(m_hWnd
, IDS_PROC_CONFIRMKILLPROCESS
, IDS_APPNAME
, MB_YESNO
| MB_ICONQUESTION
) != IDYES
)
1449 if (::GenerateConsoleCtrlEvent(CTRL_C_EVENT
, 0))
1451 ::WaitForSingleObject(g_Git
.m_CurrentGitPi
.hProcess
, 10000);
1458 CProgressDlg::KillProcessTree(g_Git
.m_CurrentGitPi
.dwProcessId
);
1461 ::WaitForSingleObject(g_Git
.m_CurrentGitPi
.hProcess
,10000);
1463 CResizableStandAloneDialog::OnCancel();
1466 void CSyncDlg::OnBnClickedButtonSubmodule()
1470 m_ctrlCmdOut
.SetWindowTextW(_T(""));
1473 this->m_regSubmoduleButton
= (DWORD
)this->m_ctrlSubmodule
.GetCurrentEntry();
1475 this->SwitchToRun();
1477 this->m_bAbort
=false;
1478 this->m_GitCmdList
.clear();
1480 ShowTab(IDC_CMD_LOG
);
1484 switch (m_ctrlSubmodule
.GetCurrentEntry())
1487 cmd
=_T("git.exe submodule update --init");
1490 cmd
=_T("git.exe submodule init");
1493 cmd
=_T("git.exe submodule sync");
1497 m_GitCmdList
.push_back(cmd
);
1499 m_CurrentCmd
= GIT_COMMAND_SUBMODULE
;
1501 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1502 if (m_pThread
==NULL
)
1504 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1508 m_pThread
->m_bAutoDelete
= TRUE
;
1509 m_pThread
->ResumeThread();
1513 void CSyncDlg::OnBnClickedButtonStash()
1517 m_ctrlCmdOut
.SetWindowTextW(_T(""));
1523 m_GitCmdList
.clear();
1525 ShowTab(IDC_CMD_LOG
);
1527 m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
- 1, false);
1528 m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1, false);
1529 m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1, false);
1532 switch (m_ctrlStash
.GetCurrentEntry())
1535 cmd
= _T("git.exe stash save");
1538 cmd
= _T("git.exe stash pop");
1541 cmd
= _T("git.exe stash apply");
1545 m_GitCmdList
.push_back(cmd
);
1546 m_CurrentCmd
= GIT_COMMAND_STASH
;
1548 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
, 0, CREATE_SUSPENDED
);
1551 //ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1555 m_pThread
->m_bAutoDelete
= TRUE
;
1556 m_pThread
->ResumeThread();
1560 void CSyncDlg::OnTimer(UINT_PTR nIDEvent
)
1562 if( nIDEvent
== IDT_INPUT
)
1564 KillTimer(IDT_INPUT
);
1565 this->FetchOutList(true);
1570 void CSyncDlg::OnLvnInLogListColumnClick(NMHDR
* /* pNMHDR */, LRESULT
*pResult
)
1575 LRESULT
CSyncDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1577 m_pTaskbarList
.Release();
1578 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
1579 m_GitProgressList
.m_pTaskbarList
= m_pTaskbarList
;
1580 SetUUIDOverlayIcon(m_hWnd
);
1584 void CSyncDlg::OnBnClickedCheckForce()
1589 void CSyncDlg::OnBnClickedLog()
1591 CString cmd
= _T("/command:log");
1592 cmd
+= _T(" /path:\"");
1593 cmd
+= g_Git
.m_CurrentDir
;
1596 CAppUtils::RunTortoiseGitProc(cmd
);
1599 LRESULT
CSyncDlg::OnProgCmdFinish(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1606 void CSyncDlg::OnDestroy()
1608 m_bWantToExit
= true;
1609 __super::OnDestroy();