1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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
)
355 if(g_Git
.ListConflictFile(list
))
357 this->m_ctrlCmdOut
.SetSel(-1,-1);
358 this->m_ctrlCmdOut
.ReplaceSel(_T("Get conflict files fail\n"));
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
);
415 if( (!this->m_GitCmdStatus
) && this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
418 CString remote
, remotebranch
;
419 m_ctrlURL
.GetWindowText(remote
);
420 if (!remote
.IsEmpty())
422 STRING_VECTOR remotes
;
423 g_Git
.GetRemoteList(remotes
);
424 if (std::find(remotes
.begin(), remotes
.end(), remote
) == remotes
.end())
427 m_ctrlRemoteBranch
.GetWindowText(remotebranch
);
428 if (!remote
.IsEmpty() && !remotebranch
.IsEmpty())
429 dlg
.m_Upstream
= _T("remotes/") + remote
+ _T("/") + remotebranch
;
430 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
431 dlg
.m_PostButtonTexts
.Add(_T("Email &Patch..."));
432 INT_PTR response
= dlg
.DoModal();
438 if (response
== IDC_REBASE_POST_BUTTON
)
440 CString cmd
= _T("/command:log");
441 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
442 CAppUtils::RunTortoiseGitProc(cmd
);
444 if(response
== IDC_REBASE_POST_BUTTON
+ 1)
446 CString cmd
, out
, err
;
447 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
449 g_Git
.FixBranchName(dlg
.m_Upstream
),
450 g_Git
.FixBranchName(dlg
.m_Branch
));
451 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
453 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
457 CAppUtils::SendPatchMail(cmd
,out
);
462 void CSyncDlg::StashComplete()
464 EnableControlButton(true);
465 INT_PTR entry
= m_ctrlStash
.GetCurrentEntry();
466 if (entry
!= 1 && entry
!= 2)
473 if (g_Git
.ListConflictFile(list
))
475 m_ctrlCmdOut
.SetSel(-1, -1);
476 m_ctrlCmdOut
.ReplaceSel(_T("Get conflict files fail\n"));
478 ShowTab(IDC_CMD_LOG
);
484 m_ConflictFileList
.Clear();
489 m_ConflictFileList
.GetStatus(&list
,true);
490 m_ConflictFileList
.Show(CTGitPath::LOGACTIONS_UNMERGED
, CTGitPath::LOGACTIONS_UNMERGED
);
492 ShowTab(IDC_IN_CONFLICT
);
495 ShowTab(IDC_CMD_LOG
);
499 void CSyncDlg::OnBnClickedButtonPush()
503 m_ctrlCmdOut
.SetWindowTextW(_T(""));
506 if(this->m_strURL
.IsEmpty())
508 CMessageBox::Show(NULL
, IDS_PROC_GITCONFIG_URLEMPTY
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
512 this->m_regPushButton
=(DWORD
)this->m_ctrlPush
.GetCurrentEntry();
514 this->m_bAbort
=false;
515 this->m_GitCmdList
.clear();
517 ShowTab(IDC_CMD_LOG
);
523 DWORD exitcode
= 0xFFFFFFFF;
524 if (CHooks::Instance().PrePush(g_Git
.m_CurrentDir
, exitcode
, error
))
529 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
530 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
535 CString refName
= g_Git
.FixBranchName(m_strLocalBranch
);
536 switch (m_ctrlPush
.GetCurrentEntry())
539 arg
+= _T(" --tags ");
542 refName
= _T("refs/notes/commits"); //default ref for notes
547 arg
+= _T(" --force ");
549 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
550 arg
+= _T("--progress ");
552 cmd
.Format(_T("git.exe push -v %s \"%s\" %s"),
557 if (!m_strRemoteBranch
.IsEmpty() && m_ctrlPush
.GetCurrentEntry() != 2)
559 cmd
+= _T(":") + m_strRemoteBranch
;
562 m_GitCmdList
.push_back(cmd
);
564 m_CurrentCmd
= GIT_COMMAND_PUSH
;
566 if(this->m_bAutoLoadPuttyKey
)
568 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
571 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
574 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
578 m_pThread
->m_bAutoDelete
= TRUE
;
579 m_pThread
->ResumeThread();
583 void CSyncDlg::OnBnClickedButtonApply()
586 if (g_Git
.GetHash(oldhash
, _T("HEAD")))
588 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
595 if(dlg
.DoModal() == IDOK
)
598 for (int i
= 0; i
< dlg
.m_PathList
.GetCount(); ++i
)
600 cmd
.Format(_T("git.exe am \"%s\""),dlg
.m_PathList
[i
].GetGitPathString());
602 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
604 CMessageBox::Show(NULL
,output
,_T("TortoiseGit"),MB_OK
);
609 this->m_ctrlCmdOut
.SetSel(-1,-1);
610 this->m_ctrlCmdOut
.ReplaceSel(cmd
+_T("\n"));
611 this->m_ctrlCmdOut
.SetSel(-1,-1);
612 this->m_ctrlCmdOut
.ReplaceSel(output
);
616 if (g_Git
.GetHash(newhash
, _T("HEAD")))
618 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash after applying patches.")), _T("TortoiseGit"), MB_ICONERROR
);
622 this->m_InLogList
.Clear();
623 this->m_InChangeFileList
.Clear();
625 if(newhash
== oldhash
)
627 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
628 this->m_InLogList
.ShowText(_T("No commits get from patch"));
629 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
634 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
635 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
638 range
.Format(_T("%s..%s"), m_oldHash
.ToString(), newhash
.ToString());
639 this->AddDiffFileList(&m_InChangeFileList
, &m_arInChangeList
, newhash
.ToString(), oldhash
.ToString());
640 m_InLogList
.FillGitLog(nullptr, &range
, CGit::LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
);
642 this->FetchOutList(true);
645 this->m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,true);
649 this->ShowTab(IDC_CMD_LOG
);
653 this->ShowTab(IDC_IN_LOGLIST
);
658 void CSyncDlg::OnBnClickedButtonEmail()
660 CString cmd
, out
, err
;
662 this->m_strLocalBranch
= this->m_ctrlLocalBranch
.GetString();
663 this->m_ctrlRemoteBranch
.GetWindowText(this->m_strRemoteBranch
);
664 this->m_ctrlURL
.GetWindowText(this->m_strURL
);
665 m_strURL
=m_strURL
.Trim();
666 m_strRemoteBranch
=m_strRemoteBranch
.Trim();
668 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
670 m_strURL
+_T('/')+m_strRemoteBranch
,g_Git
.FixBranchName(m_strLocalBranch
));
672 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
674 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
678 CAppUtils::SendPatchMail(cmd
,out
);
681 void CSyncDlg::ShowProgressCtrl(bool bShow
)
683 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
684 this->m_ctrlAnimate
.ShowWindow(b
);
685 this->m_ctrlProgress
.ShowWindow(b
);
686 this->m_ctrlProgLabel
.ShowWindow(b
);
687 this->m_ctrlAnimate
.Open(IDR_DOWNLOAD
);
689 this->m_ctrlAnimate
.Play(0, UINT_MAX
, UINT_MAX
);
691 this->m_ctrlAnimate
.Stop();
693 void CSyncDlg::ShowInputCtrl(bool bShow
)
695 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
696 this->m_ctrlURL
.ShowWindow(b
);
697 this->m_ctrlLocalBranch
.ShowWindow(b
);
698 this->m_ctrlRemoteBranch
.ShowWindow(b
);
699 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH
)->ShowWindow(b
);
700 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH
)->ShowWindow(b
);
701 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH
)->ShowWindow(b
);
702 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH
)->ShowWindow(b
);
703 this->GetDlgItem(IDC_BUTTON_MANAGE
)->ShowWindow(b
);
704 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->ShowWindow(b
);
705 this->GetDlgItem(IDC_CHECK_FORCE
)->ShowWindow(b
);
706 this->GetDlgItem(IDC_STATIC_REMOTE_URL
)->ShowWindow(b
);
708 BOOL
CSyncDlg::OnInitDialog()
710 CResizableStandAloneDialog::OnInitDialog();
711 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
713 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
714 // do this, Explorer would be unable to send that message to our window if we
715 // were running elevated. It's OK to make the call all the time, since if we're
716 // not elevated, this is a no-op.
717 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
718 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
719 CAutoLibrary hUser
= AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
722 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
723 if (pfnChangeWindowMessageFilterEx
)
725 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
728 m_pTaskbarList
.Release();
729 if (FAILED(m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
)))
730 m_pTaskbarList
= nullptr;
732 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->EnableWindow(CAppUtils::IsSSHPutty());
735 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
736 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
737 this->m_ctrlAnimate.Play(0,-1,-1);
740 // ------------------ Create Tabctrl -----------
741 CWnd
*pwnd
=this->GetDlgItem(IDC_BUTTON_TABCTRL
);
743 pwnd
->GetWindowRect(&rectDummy
);
744 this->ScreenToClient(rectDummy
);
746 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_SYNC_TAB
))
748 TRACE0("Failed to create output tab window\n");
749 return FALSE
; // fail to create
751 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
753 // -------------Create Command Log Ctrl ---------
755 dwStyle
= ES_MULTILINE
| ES_READONLY
| WS_CHILD
| WS_VISIBLE
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
|WS_VSCROLL
;
757 if( !m_ctrlCmdOut
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_CMD_LOG
))
759 TRACE0("Failed to create Log commits window\n");
760 return FALSE
; // fail to create
763 // set the font to use in the log message view, configured in the settings dialog
765 CAppUtils::CreateFontForLogs(m_logFont
);
766 //GetDlgItem(IDC_CMD_LOG)->SetFont(&m_logFont);
767 m_ctrlCmdOut
.SetFont(&m_logFont
);
768 m_ctrlTabCtrl
.InsertTab(&m_ctrlCmdOut
, CString(MAKEINTRESOURCE(IDS_LOG
)), -1);
770 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
772 //---------- Create in coming list ctrl -----------
773 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
775 if( !m_InLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_LOGLIST
))
777 TRACE0("Failed to create output commits window\n");
778 return FALSE
; // fail to create
781 m_ctrlTabCtrl
.InsertTab(&m_InLogList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_INCOMMITS
)), -1);
783 m_InLogList
.m_ColumnRegKey
=_T("SyncIn");
784 m_InLogList
.InsertGitColumn();
786 //----------- Create In Change file list -----------
787 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
789 if( !m_InChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CHANGELIST
))
791 TRACE0("Failed to create output change files window\n");
792 return FALSE
; // fail to create
794 m_ctrlTabCtrl
.InsertTab(&m_InChangeFileList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_INCHANGELIST
)), -1);
796 m_InChangeFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("InSyncDlg"),
797 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWOREVISIONS
) |
798 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2REVISIONS
)), false, true, GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
);
801 //---------- Create Conflict List Ctrl -----------------
802 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
804 if( !m_ConflictFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CONFLICT
))
806 TRACE0("Failed to create output change files window\n");
807 return FALSE
; // fail to create
809 m_ctrlTabCtrl
.InsertTab(&m_ConflictFileList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_CONFLICTS
)), -1);
811 m_ConflictFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("ConflictSyncDlg"),
812 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWOREVISIONS
) |
813 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2REVISIONS
) |
814 GITSLC_POPCONFLICT
|GITSLC_POPRESOLVE
),false);
817 //---------- Create Commit Out List Ctrl---------------
819 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
821 if( !m_OutLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_LOGLIST
))
823 TRACE0("Failed to create output commits window\n");
824 return FALSE
; // fail to create
828 m_ctrlTabCtrl
.InsertTab(&m_OutLogList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_OUTCOMMITS
)), -1);
830 m_OutLogList
.m_ColumnRegKey
= _T("SyncOut");
831 m_OutLogList
.InsertGitColumn();
833 //------------- Create Change File List Control ----------------
835 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
837 if( !m_OutChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_CHANGELIST
))
839 TRACE0("Failed to create output change files window\n");
840 return FALSE
; // fail to create
842 m_ctrlTabCtrl
.InsertTab(&m_OutChangeFileList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_OUTCHANGELIST
)), -1);
844 m_OutChangeFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
, _T("OutSyncDlg"),
845 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWOREVISIONS
) |
846 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2REVISIONS
)), false, true, GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
);
848 if (!m_GitProgressList
.Create(dwStyle
| LVS_OWNERDATA
, rectDummy
, &m_ctrlTabCtrl
, IDC_CMD_GIT_PROG
))
850 TRACE0("Failed to create Git Progress List Window\n");
851 return FALSE
; // fail to create
853 m_ctrlTabCtrl
.InsertTab(&m_GitProgressList
, CString(MAKEINTRESOURCE(IDS_LOG
)), -1);
854 m_GitProgressList
.m_pAnimate
= &m_ctrlAnimate
;
855 m_GitProgressList
.m_pPostWnd
= this;
856 m_GitProgressList
.m_pProgressLabelCtrl
= &m_ctrlProgLabel
;
857 m_GitProgressList
.m_pProgControl
= &m_ctrlProgress
;
858 m_GitProgressList
.m_pTaskbarList
= m_pTaskbarList
;
860 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
861 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_FULLROWSELECT
;
862 m_refList
.Create(dwStyle
, rectDummy
, &m_ctrlTabCtrl
, IDC_REFLIST
);
863 m_refList
.SetExtendedStyle(exStyle
);
865 m_ctrlTabCtrl
.InsertTab(&m_refList
, CString(MAKEINTRESOURCE(IDS_REFLIST
)), -1);
867 this->m_tooltips
.Create(this);
869 AddAnchor(IDC_SYNC_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
871 AddAnchor(IDC_GROUP_INFO
,TOP_LEFT
,TOP_RIGHT
);
872 AddAnchor(IDC_COMBOBOXEX_URL
,TOP_LEFT
,TOP_RIGHT
);
873 AddAnchor(IDC_BUTTON_MANAGE
,TOP_RIGHT
);
874 AddAnchor(IDC_BUTTON_PULL
,BOTTOM_LEFT
);
875 AddAnchor(IDC_BUTTON_PUSH
,BOTTOM_LEFT
);
876 AddAnchor(IDC_BUTTON_SUBMODULE
,BOTTOM_LEFT
);
877 AddAnchor(IDC_BUTTON_STASH
,BOTTOM_LEFT
);
878 AddAnchor(IDC_BUTTON_APPLY
,BOTTOM_RIGHT
);
879 AddAnchor(IDC_BUTTON_EMAIL
,BOTTOM_RIGHT
);
880 AddAnchor(IDC_PROGRESS_SYNC
,TOP_LEFT
,TOP_RIGHT
);
881 AddAnchor(IDOK
,BOTTOM_RIGHT
);
882 AddAnchor(IDHELP
,BOTTOM_RIGHT
);
883 AddAnchor(IDC_STATIC_STATUS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
884 AddAnchor(IDC_ANIMATE_SYNC
,TOP_LEFT
);
885 AddAnchor(IDC_BUTTON_COMMIT
,BOTTOM_LEFT
);
886 AddAnchor(IDC_LOG
, BOTTOM_LEFT
);
888 // do not use BRANCH_COMBOX_ADD_ANCHOR here, we want to have different stylings
889 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH
, TOP_LEFT
,TOP_CENTER
);
890 AddAnchor(IDC_COMBOBOXEX_REMOTE_BRANCH
, TOP_CENTER
, TOP_RIGHT
);
891 AddAnchor(IDC_BUTTON_LOCAL_BRANCH
, TOP_CENTER
);
892 AddAnchor(IDC_BUTTON_REMOTE_BRANCH
, TOP_RIGHT
);
893 AddAnchor(IDC_STATIC_REMOTE_BRANCH
, TOP_CENTER
);
894 AddAnchor(IDC_PROG_LABEL
, TOP_LEFT
);
896 AdjustControlSize(IDC_CHECK_PUTTY_KEY
);
897 AdjustControlSize(IDC_CHECK_FORCE
);
899 CString WorkingDir
=g_Git
.m_CurrentDir
;
900 WorkingDir
.Replace(_T(':'),_T('_'));
901 m_RegKeyRemoteBranch
= CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir
;
904 this->AddOthersToAnchor();
906 this->m_ctrlPush
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PUSH
)));
907 this->m_ctrlPush
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PUSHTAGS
)));
908 this->m_ctrlPush
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PUSHNOTES
)));
910 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PULL
)));
911 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_FETCH
)));
912 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_FETCHREBASE
)));
913 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_REMOTEUPDATE
)));
914 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_CLEANUPSTALEBRANCHES
)));
916 this->m_ctrlSubmodule
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULEUPDATE
)));
917 this->m_ctrlSubmodule
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULEINIT
)));
918 this->m_ctrlSubmodule
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULESYNC
)));
920 this->m_ctrlStash
.AddEntry(CString(MAKEINTRESOURCE(IDS_MENUSTASHSAVE
)));
921 this->m_ctrlStash
.AddEntry(CString(MAKEINTRESOURCE(IDS_MENUSTASHPOP
)));
922 this->m_ctrlStash
.AddEntry(CString(MAKEINTRESOURCE(IDS_MENUSTASHAPPLY
)));
924 WorkingDir
.Replace(_T(':'),_T('_'));
927 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir
);
929 this->m_regPullButton
= CRegDWORD(regkey
+_T("\\Pull"),0);
930 this->m_regPushButton
= CRegDWORD(regkey
+_T("\\Push"),0);
931 this->m_regSubmoduleButton
= CRegDWORD(regkey
+_T("\\Submodule"));
932 this->m_regAutoLoadPutty
= CRegDWORD(regkey
+ _T("\\AutoLoadPutty"), CAppUtils::IsSSHPutty());
935 this->m_bAutoLoadPuttyKey
= m_regAutoLoadPutty
;
936 if(!CAppUtils::IsSSHPutty())
937 m_bAutoLoadPuttyKey
= false;
938 this->UpdateData(FALSE
);
940 this->m_ctrlPull
.SetCurrentEntry(this->m_regPullButton
);
941 this->m_ctrlPush
.SetCurrentEntry(this->m_regPushButton
);
942 this->m_ctrlSubmodule
.SetCurrentEntry(this->m_regSubmoduleButton
);
944 CString sWindowTitle
;
945 GetWindowText(sWindowTitle
);
946 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
948 EnableSaveRestore(_T("SyncDlg"));
950 m_ctrlURL
.SetCaseSensitive(TRUE
);
951 m_ctrlURL
.SetURLHistory(true);
952 this->m_ctrlURL
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir
, _T("url"));
956 if(!g_Git
.GetRemoteList(list
))
958 for (unsigned int i
= 0; i
< list
.size(); ++i
)
960 m_ctrlURL
.AddString(list
[i
]);
963 m_ctrlURL
.SetCurSel(0);
964 m_ctrlRemoteBranch
.SetCurSel(0);
966 this->LoadBranchInfo();
968 this->m_bInited
=true;
971 m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,false);
972 m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
973 m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
974 m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
975 m_ctrlTabCtrl
.ShowTab(IDC_CMD_GIT_PROG
-1, false);
976 m_ctrlTabCtrl
.ShowTab(IDC_REFLIST
-1, false);
978 m_ctrlRemoteBranch
.m_bWantReturn
= TRUE
;
979 m_ctrlURL
.m_bWantReturn
= TRUE
;
981 this->m_Gitverion
= CAppUtils::GetMsysgitVersion();
983 if (m_seq
> 0 && (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\SyncDialogRandomPos")))
987 GetWindowRect(&rect
);
988 rect
.top
-= m_seq
* 30;
989 rect
.bottom
-= m_seq
* 30;
995 MoveWindow(rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
998 return TRUE
; // return TRUE unless you set the focus to a control
999 // EXCEPTION: OCX Property Pages should return FALSE
1002 void CSyncDlg::OnBnClickedButtonManage()
1004 CAppUtils::LaunchRemoteSetting();
1008 void CSyncDlg::Refresh()
1010 theApp
.DoWaitCursor(1);
1012 int lastSelected
= m_ctrlURL
.GetCurSel();
1014 this->m_ctrlURL
.GetWindowText(url
);
1016 this->m_ctrlURL
.Reset();
1017 CString workingDir
= g_Git
.m_CurrentDir
;
1018 workingDir
.Replace(_T(':'), _T('_'));
1019 this->m_ctrlURL
.LoadHistory(_T("Software\\TortoiseGit\\History\\SyncURL\\") + workingDir
, _T("url"));
1023 if (!g_Git
.GetRemoteList(list
))
1025 for (size_t i
= 0; i
< list
.size(); ++i
)
1027 m_ctrlURL
.AddString(list
[i
]);
1032 if (lastSelected
>= 0 && !found
)
1034 m_ctrlURL
.SetCurSel(0);
1035 m_ctrlURL
.GetWindowText(url
);
1040 this->m_ctrlLocalBranch
.GetWindowText(local
);
1041 this->m_ctrlRemoteBranch
.GetWindowText(remote
);
1043 this->LoadBranchInfo();
1045 this->m_ctrlLocalBranch
.AddString(local
);
1046 this->m_ctrlRemoteBranch
.AddString(remote
);
1047 this->m_ctrlURL
.AddString(url
);
1049 m_OutLogList
.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_REFRESHING
)));
1050 this->FetchOutList(true);
1051 theApp
.DoWaitCursor(-1);
1054 BOOL
CSyncDlg::PreTranslateMessage(MSG
* pMsg
)
1056 if (pMsg
->message
== WM_KEYDOWN
)
1058 switch (pMsg
->wParam
)
1064 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1069 /* Avoid TAB control destroy but dialog exist*/
1073 TCHAR buff
[128] = { 0 };
1074 ::GetClassName(pMsg
->hwnd
,buff
,128);
1076 /* Use MSFTEDIT_CLASS http://msdn.microsoft.com/en-us/library/bb531344.aspx */
1077 if (_tcsnicmp(buff
, MSFTEDIT_CLASS
, 128) == 0 || //Unicode and MFC 2012 and later
1078 _tcsnicmp(buff
, RICHEDIT_CLASS
, 128) == 0 || //ANSI or MFC 2010
1079 _tcsnicmp(buff
, _T("SysListView32"), 128) == 0)
1081 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
1087 m_tooltips
.RelayEvent(pMsg
);
1088 return __super::PreTranslateMessage(pMsg
);
1090 void CSyncDlg::FetchOutList(bool force
)
1094 m_OutChangeFileList
.Clear();
1095 this->m_OutLogList
.Clear();
1098 this->m_ctrlURL
.GetWindowText(remote
);
1099 CString remotebranch
;
1100 this->m_ctrlRemoteBranch
.GetWindowText(remotebranch
);
1101 remotebranch
=remote
+_T("/")+remotebranch
;
1102 CGitHash remotebranchHash
;
1103 g_Git
.GetHash(remotebranchHash
, remotebranch
);
1108 str
.LoadString(IDS_PROC_SYNC_PUSH_UNKNOWN
);
1109 m_OutLogList
.ShowText(str
);
1110 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
1111 m_OutLocalBranch
.Empty();
1112 m_OutRemoteBranch
.Empty();
1114 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1118 else if(remotebranchHash
.IsEmpty())
1121 str
.Format(IDS_PROC_SYNC_PUSH_UNKNOWNBRANCH
, remotebranch
);
1122 m_OutLogList
.ShowText(str
);
1123 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
1124 m_OutLocalBranch
.Empty();
1125 m_OutRemoteBranch
.Empty();
1127 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1132 CString localbranch
;
1133 localbranch
=this->m_ctrlLocalBranch
.GetString();
1135 if(localbranch
!= m_OutLocalBranch
|| m_OutRemoteBranch
!= remotebranch
|| force
)
1137 m_OutLogList
.ClearText();
1139 CGitHash base
, localBranchHash
;
1140 bool isFastForward
= g_Git
.IsFastForward(remotebranch
, localbranch
, &base
);
1142 if (g_Git
.GetHash(localBranchHash
, localbranch
))
1144 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + localbranch
+ _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
1147 if (remotebranchHash
== localBranchHash
)
1150 str
.Format(IDS_PROC_SYNC_COMMITSAHEAD
, 0, remotebranch
);
1151 m_OutLogList
.ShowText(str
);
1152 this->m_ctrlStatus
.SetWindowText(str
);
1153 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
1154 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1156 else if (isFastForward
|| m_bForce
)
1159 range
.Format(_T("%s..%s"), g_Git
.FixBranchName(remotebranch
), g_Git
.FixBranchName(localbranch
));
1161 m_OutLogList
.FillGitLog(nullptr, &range
, CGit::LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
);
1163 str
.Format(IDS_PROC_SYNC_COMMITSAHEAD
, m_OutLogList
.GetItemCount(), remotebranch
);
1164 this->m_ctrlStatus
.SetWindowText(str
);
1167 AddDiffFileList(&m_OutChangeFileList
, &m_arOutChangeList
, localbranch
, remotebranch
);
1170 AddDiffFileList(&m_OutChangeFileList
, &m_arOutChangeList
, localbranch
, base
.ToString());
1173 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,TRUE
);
1174 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(TRUE
);
1179 str
.Format(IDS_PROC_SYNC_NOFASTFORWARD
, localbranch
, remotebranch
);
1180 m_OutLogList
.ShowText(str
);
1181 this->m_ctrlStatus
.SetWindowText(str
);
1182 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID() - 1, FALSE
);
1183 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1186 this->m_OutLocalBranch
=localbranch
;
1187 this->m_OutRemoteBranch
=remotebranch
;
1192 bool CSyncDlg::IsURL()
1195 this->m_ctrlURL
.GetWindowText(str
);
1196 if(str
.Find(_T('\\'))>=0 || str
.Find(_T('/'))>=0)
1201 void CSyncDlg::OnCbnEditchangeComboboxex()
1203 SetTimer(IDT_INPUT
, 1000, NULL
);
1204 this->m_OutLogList
.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_WAINTINPUT
)));
1206 //this->FetchOutList();
1209 UINT
CSyncDlg::ProgressThread()
1211 m_startTick
= GetTickCount();
1214 CProgressDlg::RunCmdList(this, m_GitCmdList
, list
, true, nullptr, &this->m_bAbort
, &this->m_Databuf
);
1215 InterlockedExchange(&m_bBlock
, FALSE
);
1220 LRESULT
CSyncDlg::OnProgressUpdateUI(WPARAM wParam
,LPARAM lParam
)
1222 if(wParam
== MSG_PROGRESSDLG_START
)
1225 m_ctrlAnimate
.Play(0, UINT_MAX
, UINT_MAX
);
1226 this->m_ctrlProgress
.SetPos(0);
1229 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1230 m_pTaskbarList
->SetProgressValue(m_hWnd
, 0, 100);
1234 if(wParam
== MSG_PROGRESSDLG_END
|| wParam
== MSG_PROGRESSDLG_FAILED
)
1236 DWORD tickSpent
= GetTickCount() - m_startTick
;
1237 CString strEndTime
= CLoglistUtils::FormatDateAndTime(CTime::GetCurrentTime(), DATE_SHORTDATE
, true, false);
1240 m_Databuf
.m_critSec
.Lock();
1242 m_Databuf
.m_critSec
.Unlock();
1245 m_ctrlAnimate
.Stop();
1246 m_ctrlProgress
.SetPos(100);
1247 //this->DialogEnableWindow(IDOK,TRUE);
1249 DWORD exitCode
= (DWORD
)lParam
;
1254 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
1255 m_pTaskbarList
->SetProgressValue(m_hWnd
, 100, 100);
1258 log
.Format(IDS_PROC_PROGRESS_GITUNCLEANEXIT
, exitCode
);
1260 err
.Format(_T("\r\n\r\n%s (%lu ms @ %s)\r\n"), log
, tickSpent
, strEndTime
);
1261 CProgressDlg::InsertColorText(this->m_ctrlCmdOut
, err
, RGB(255,0,0));
1262 PlaySound((LPCTSTR
)SND_ALIAS_SYSTEMEXCLAMATION
, NULL
, SND_ALIAS_ID
| SND_ASYNC
);
1267 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1269 temp
.LoadString(IDS_SUCCESS
);
1271 log
.Format(_T("\r\n%s (%lu ms @ %s)\r\n"), temp
, tickSpent
, strEndTime
);
1272 CProgressDlg::InsertColorText(this->m_ctrlCmdOut
, log
, RGB(0,0,255));
1274 m_GitCmdStatus
= exitCode
;
1276 //if(wParam == MSG_PROGRESSDLG_END)
1281 ParserCmdOutput((char)lParam
);
1284 m_Databuf
.m_critSec
.Lock();
1285 for (size_t i
= m_BufStart
; i
< m_Databuf
.size(); ++i
)
1287 char c
= m_Databuf
[m_BufStart
];
1289 m_Databuf
.m_critSec
.Unlock();
1292 m_Databuf
.m_critSec
.Lock();
1295 if (m_BufStart
> 1000)
1297 m_Databuf
.erase(m_Databuf
.begin(), m_Databuf
.begin() + m_BufStart
);
1300 m_Databuf
.m_critSec
.Unlock();
1306 static std::map
<CString
, CGitHash
> * HashMapToRefMap(MAP_HASH_NAME
&map
)
1308 auto rmap
= new std::map
<CString
, CGitHash
>();
1309 for (auto mit
= map
.begin(); mit
!= map
.end(); ++mit
)
1311 for (auto rit
= mit
->second
.begin(); rit
!= mit
->second
.end(); ++rit
)
1313 rmap
->insert(std::make_pair(*rit
, mit
->first
));
1319 void CSyncDlg::FillNewRefMap()
1322 m_newHashMap
.clear();
1323 CAutoRepository
repo(g_Git
.GetGitRepository());
1326 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1330 if (CGit::GetMapHashToFriendName(repo
, m_newHashMap
))
1332 MessageBox(CGit::GetLibGit2LastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
1336 auto oldRefMap
= HashMapToRefMap(m_oldHashMap
);
1337 auto newRefMap
= HashMapToRefMap(m_newHashMap
);
1338 for (auto oit
= oldRefMap
->begin(); oit
!= oldRefMap
->end(); ++oit
)
1341 for (auto nit
= newRefMap
->begin(); nit
!= newRefMap
->end(); ++nit
)
1344 if (oit
->first
== nit
->first
)
1347 m_refList
.AddEntry(repo
, oit
->first
, &oit
->second
, &nit
->second
);
1354 m_refList
.AddEntry(repo
, oit
->first
, &oit
->second
, nullptr);
1357 for (auto nit
= newRefMap
->begin(); nit
!= newRefMap
->end(); ++nit
)
1360 for (auto oit
= oldRefMap
->begin(); oit
!= oldRefMap
->end(); ++oit
)
1362 if (oit
->first
== nit
->first
)
1371 m_refList
.AddEntry(repo
, nit
->first
, nullptr, &nit
->second
);
1379 void CSyncDlg::RunPostAction()
1386 if (this->m_CurrentCmd
== GIT_COMMAND_PUSH
)
1388 DWORD exitcode
= 0xFFFFFFFF;
1390 if (CHooks::Instance().PostPush(g_Git
.m_CurrentDir
, exitcode
, error
))
1395 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
1396 CMessageBox::Show(nullptr, temp
,_T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1401 EnableControlButton(true);
1403 this->FetchOutList(true);
1405 else if (this->m_CurrentCmd
== GIT_COMMAND_PULL
)
1409 else if (this->m_CurrentCmd
== GIT_COMMAND_FETCH
|| this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
1413 else if (this->m_CurrentCmd
== GIT_COMMAND_SUBMODULE
)
1415 //this->m_ctrlCmdOut.SetSel(-1,-1);
1416 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
1417 //this->m_ctrlCmdOut.SetSel(-1,-1);
1418 EnableControlButton(true);
1421 else if (this->m_CurrentCmd
== GIT_COMMAND_STASH
)
1425 else if (this->m_CurrentCmd
== GIT_COMMAND_REMOTE
)
1427 this->FetchOutList(true);
1428 EnableControlButton(true);
1430 ShowTab(IDC_REFLIST
);
1433 void CSyncDlg::ParserCmdOutput(char ch
)
1435 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut
,m_ctrlProgress
,m_hWnd
,m_pTaskbarList
,m_LogText
,ch
);
1437 void CSyncDlg::OnBnClickedButtonCommit()
1439 CString cmd
= _T("/command:commit");
1440 cmd
+= _T(" /path:\"");
1441 cmd
+= g_Git
.m_CurrentDir
;
1444 CAppUtils::RunTortoiseGitProc(cmd
);
1447 void CSyncDlg::OnOK()
1451 m_ctrlURL
.SaveHistory();
1453 m_regAutoLoadPutty
= this->m_bAutoLoadPuttyKey
;
1458 void CSyncDlg::OnCancel()
1463 CResizableStandAloneDialog::OnCancel();
1467 if (g_Git
.m_CurrentGitPi
.hProcess
)
1469 DWORD dwConfirmKillProcess
= CRegDWORD(_T("Software\\TortoiseGit\\ConfirmKillProcess"));
1470 if (dwConfirmKillProcess
&& CMessageBox::Show(m_hWnd
, IDS_PROC_CONFIRMKILLPROCESS
, IDS_APPNAME
, MB_YESNO
| MB_ICONQUESTION
) != IDYES
)
1472 if (::GenerateConsoleCtrlEvent(CTRL_C_EVENT
, 0))
1474 ::WaitForSingleObject(g_Git
.m_CurrentGitPi
.hProcess
, 10000);
1481 CProgressDlg::KillProcessTree(g_Git
.m_CurrentGitPi
.dwProcessId
);
1484 ::WaitForSingleObject(g_Git
.m_CurrentGitPi
.hProcess
,10000);
1486 CResizableStandAloneDialog::OnCancel();
1489 void CSyncDlg::OnBnClickedButtonSubmodule()
1493 m_ctrlCmdOut
.SetWindowTextW(_T(""));
1496 this->m_regSubmoduleButton
= (DWORD
)this->m_ctrlSubmodule
.GetCurrentEntry();
1498 this->SwitchToRun();
1500 this->m_bAbort
=false;
1501 this->m_GitCmdList
.clear();
1503 ShowTab(IDC_CMD_LOG
);
1507 switch (m_ctrlSubmodule
.GetCurrentEntry())
1510 cmd
=_T("git.exe submodule update --init");
1513 cmd
=_T("git.exe submodule init");
1516 cmd
=_T("git.exe submodule sync");
1520 m_GitCmdList
.push_back(cmd
);
1522 m_CurrentCmd
= GIT_COMMAND_SUBMODULE
;
1524 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1525 if (m_pThread
==NULL
)
1527 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1531 m_pThread
->m_bAutoDelete
= TRUE
;
1532 m_pThread
->ResumeThread();
1536 void CSyncDlg::OnBnClickedButtonStash()
1540 m_ctrlCmdOut
.SetWindowTextW(_T(""));
1546 m_GitCmdList
.clear();
1548 ShowTab(IDC_CMD_LOG
);
1550 m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
- 1, false);
1551 m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1, false);
1552 m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1, false);
1555 switch (m_ctrlStash
.GetCurrentEntry())
1558 cmd
= _T("git.exe stash save");
1561 cmd
= _T("git.exe stash pop");
1564 cmd
= _T("git.exe stash apply");
1568 m_GitCmdList
.push_back(cmd
);
1569 m_CurrentCmd
= GIT_COMMAND_STASH
;
1571 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
, 0, CREATE_SUSPENDED
);
1574 //ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1578 m_pThread
->m_bAutoDelete
= TRUE
;
1579 m_pThread
->ResumeThread();
1583 void CSyncDlg::OnTimer(UINT_PTR nIDEvent
)
1585 if( nIDEvent
== IDT_INPUT
)
1587 KillTimer(IDT_INPUT
);
1588 this->FetchOutList(true);
1593 void CSyncDlg::OnLvnInLogListColumnClick(NMHDR
* /* pNMHDR */, LRESULT
*pResult
)
1598 LRESULT
CSyncDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1600 m_pTaskbarList
.Release();
1601 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
1602 m_GitProgressList
.m_pTaskbarList
= m_pTaskbarList
;
1603 SetUUIDOverlayIcon(m_hWnd
);
1607 void CSyncDlg::OnBnClickedCheckForce()
1612 void CSyncDlg::OnBnClickedLog()
1614 CString cmd
= _T("/command:log");
1615 cmd
+= _T(" /path:\"");
1616 cmd
+= g_Git
.m_CurrentDir
;
1619 CAppUtils::RunTortoiseGitProc(cmd
);
1622 LRESULT
CSyncDlg::OnProgCmdFinish(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1629 void CSyncDlg::OnDestroy()
1631 m_bWantToExit
= true;
1632 __super::OnDestroy();