1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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"
36 IMPLEMENT_DYNAMIC(CSyncDlg
, CResizableStandAloneDialog
)
38 CSyncDlg::CSyncDlg(CWnd
* pParent
/*=NULL*/)
39 : CResizableStandAloneDialog(CSyncDlg::IDD
, pParent
)
42 m_pTooltip
=&this->m_tooltips
;
45 m_bAutoLoadPuttyKey
= CAppUtils::IsSSHPutty();
52 m_startTick
= GetTickCount();
59 void CSyncDlg::DoDataExchange(CDataExchange
* pDX
)
61 CDialog::DoDataExchange(pDX
);
62 DDX_Check(pDX
, IDC_CHECK_PUTTY_KEY
, m_bAutoLoadPuttyKey
);
63 DDX_Check(pDX
, IDC_CHECK_FORCE
,m_bForce
);
64 DDX_Control(pDX
, IDC_COMBOBOXEX_URL
, m_ctrlURL
);
65 DDX_Control(pDX
, IDC_BUTTON_TABCTRL
, m_ctrlDumyButton
);
66 DDX_Control(pDX
, IDC_BUTTON_PULL
, m_ctrlPull
);
67 DDX_Control(pDX
, IDC_BUTTON_PUSH
, m_ctrlPush
);
68 DDX_Control(pDX
, IDC_STATIC_STATUS
, m_ctrlStatus
);
69 DDX_Control(pDX
, IDC_PROGRESS_SYNC
, m_ctrlProgress
);
70 DDX_Control(pDX
, IDC_ANIMATE_SYNC
, m_ctrlAnimate
);
71 DDX_Control(pDX
, IDC_BUTTON_SUBMODULE
,m_ctrlSubmodule
);
72 DDX_Control(pDX
, IDC_PROG_LABEL
, m_ctrlProgLabel
);
77 BEGIN_MESSAGE_MAP(CSyncDlg
, CResizableStandAloneDialog
)
78 ON_BN_CLICKED(IDC_BUTTON_PULL
, &CSyncDlg::OnBnClickedButtonPull
)
79 ON_BN_CLICKED(IDC_BUTTON_PUSH
, &CSyncDlg::OnBnClickedButtonPush
)
80 ON_BN_CLICKED(IDC_BUTTON_APPLY
, &CSyncDlg::OnBnClickedButtonApply
)
81 ON_BN_CLICKED(IDC_BUTTON_EMAIL
, &CSyncDlg::OnBnClickedButtonEmail
)
82 ON_BN_CLICKED(IDC_BUTTON_MANAGE
, &CSyncDlg::OnBnClickedButtonManage
)
84 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL
, &CSyncDlg::OnCbnEditchangeComboboxex
)
85 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH
, &CSyncDlg::OnCbnEditchangeComboboxex
)
86 ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI
, OnProgressUpdateUI
)
87 ON_MESSAGE(WM_PROG_CMD_FINISH
, OnProgCmdFinish
)
88 ON_NOTIFY(LVN_COLUMNCLICK
, IDC_IN_LOGLIST
, OnLvnInLogListColumnClick
)
89 ON_BN_CLICKED(IDC_BUTTON_COMMIT
, &CSyncDlg::OnBnClickedButtonCommit
)
90 ON_BN_CLICKED(IDC_BUTTON_SUBMODULE
, &CSyncDlg::OnBnClickedButtonSubmodule
)
92 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
93 ON_BN_CLICKED(IDC_CHECK_FORCE
, &CSyncDlg::OnBnClickedCheckForce
)
94 ON_BN_CLICKED(IDC_LOG
, &CSyncDlg::OnBnClickedLog
)
98 void CSyncDlg::EnableControlButton(bool bEnabled
)
100 GetDlgItem(IDC_BUTTON_PULL
)->EnableWindow(bEnabled
);
101 GetDlgItem(IDC_BUTTON_PUSH
)->EnableWindow(bEnabled
);
102 GetDlgItem(IDC_BUTTON_APPLY
)->EnableWindow(bEnabled
);
103 GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(bEnabled
);
104 GetDlgItem(IDOK
)->EnableWindow(bEnabled
);
105 GetDlgItem(IDC_BUTTON_SUBMODULE
)->EnableWindow(bEnabled
);
107 // CSyncDlg message handlers
109 void CSyncDlg::OnBnClickedButtonPull()
112 CurrentEntry
= (int)this->m_ctrlPull
.GetCurrentEntry();
113 this->m_regPullButton
= CurrentEntry
;
115 this->m_bAbort
=false;
116 this->m_GitCmdList
.clear();
117 m_ctrlCmdOut
.SetWindowTextW(_T(""));
123 if (g_Git
.GetHash(m_oldHash
, _T("HEAD")))
125 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
129 if( CurrentEntry
== 0)
131 CGitHash localBranchHash
;
132 if (g_Git
.GetHash(localBranchHash
, m_strLocalBranch
))
134 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_strLocalBranch
+ _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
137 if (localBranchHash
!= m_oldHash
)
139 CMessageBox::Show(NULL
, IDS_PROC_SYNC_PULLWRONGBRANCH
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
144 if(this->m_strURL
.IsEmpty())
146 CMessageBox::Show(NULL
, IDS_PROC_GITCONFIG_URLEMPTY
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
150 if (m_bAutoLoadPuttyKey
&& CurrentEntry
!= 3) // CurrentEntry (Remote Update) handles this on its own)
152 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
159 force
= _T(" --force ");
163 ShowTab(IDC_CMD_LOG
);
165 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
166 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
167 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
170 if(CurrentEntry
== 0) //Pull
172 CString remotebranch
;
173 remotebranch
= m_strRemoteBranch
;
178 configName
.Format(L
"branch.%s.merge", this->m_strLocalBranch
);
179 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
181 configName
.Format(L
"branch.%s.remote", m_strLocalBranch
);
182 CString pullRemote
= g_Git
.GetConfigValue(configName
);
184 if(pullBranch
== remotebranch
&& pullRemote
== this->m_strURL
)
185 remotebranch
.Empty();
188 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
189 force
+= _T("--progress ");
191 cmd
.Format(_T("git.exe pull -v %s \"%s\" %s"),
196 m_CurrentCmd
= GIT_COMMAND_PULL
;
197 m_GitCmdList
.push_back(cmd
);
199 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
202 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
206 m_pThread
->m_bAutoDelete
= TRUE
;
207 m_pThread
->ResumeThread();
213 if(CurrentEntry
== 1 || CurrentEntry
==2 ) //Fetch
215 CString remotebranch
;
216 if(this->IsURL() || m_strRemoteBranch
.IsEmpty())
218 remotebranch
=this->m_strRemoteBranch
;
223 remotebranch
.Format(_T("remotes/%s/%s"),
224 m_strURL
,m_strRemoteBranch
);
225 CGitHash remoteBranchHash
;
226 g_Git
.GetHash(remoteBranchHash
, remotebranch
);
227 if (remoteBranchHash
.IsEmpty())
228 remotebranch
=m_strRemoteBranch
;
230 remotebranch
=m_strRemoteBranch
+_T(":")+remotebranch
;
233 if(CurrentEntry
== 1)
234 m_CurrentCmd
= GIT_COMMAND_FETCH
;
236 m_CurrentCmd
= GIT_COMMAND_FETCHANDREBASE
;
238 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
241 // current libgit2 only supports well formated refspec
242 refspec
.Format(_T("refs/heads/%s:refs/remotes/%s/%s"), m_strRemoteBranch
, m_strURL
, m_strRemoteBranch
);
243 m_GitProgressList
.SetUrl(m_strURL
);
244 m_GitProgressList
.SetRefSpec(refspec
);
245 m_GitProgressList
.SetCommand(CGitProgressList::GitProgress_Fetch
);
246 m_GitProgressList
.Init();
247 ShowTab(IDC_CMD_GIT_PROG
);
251 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
252 force
+= _T("--progress ");
254 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"),
259 m_GitCmdList
.push_back(cmd
);
261 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
264 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
268 m_pThread
->m_bAutoDelete
= TRUE
;
269 m_pThread
->ResumeThread();
275 if(CurrentEntry
== 3)
277 if (m_bAutoLoadPuttyKey
)
280 if (!g_Git
.GetRemoteList(list
))
282 for (size_t i
= 0; i
< list
.size(); ++i
)
283 CAppUtils::LaunchPAgent(NULL
, &list
[i
]);
287 m_CurrentCmd
= GIT_COMMAND_REMOTE
;
288 cmd
=_T("git.exe remote update");
289 m_GitCmdList
.push_back(cmd
);
291 InterlockedExchange(&m_bBlock
, TRUE
);
293 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
296 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
297 InterlockedExchange(&m_bBlock
, FALSE
);
301 m_pThread
->m_bAutoDelete
= TRUE
;
302 m_pThread
->ResumeThread();
306 ///Cleanup stale remote banches
307 if(CurrentEntry
== 4)
309 m_CurrentCmd
= GIT_COMMAND_REMOTE
;
310 cmd
.Format(_T("git.exe remote prune \"%s\""), m_strURL
);
311 m_GitCmdList
.push_back(cmd
);
313 InterlockedExchange(&m_bBlock
, TRUE
);
315 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
318 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
319 InterlockedExchange(&m_bBlock
, FALSE
);
323 m_pThread
->m_bAutoDelete
= TRUE
;
324 m_pThread
->ResumeThread();
329 void CSyncDlg::PullComplete()
331 EnableControlButton(true);
333 this->FetchOutList(true);
336 if (g_Git
.GetHash(newhash
, _T("HEAD")))
337 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash after pulling.")), _T("TortoiseGit"), MB_ICONERROR
);
339 if( this ->m_GitCmdStatus
)
342 if(g_Git
.ListConflictFile(list
))
344 this->m_ctrlCmdOut
.SetSel(-1,-1);
345 this->m_ctrlCmdOut
.ReplaceSel(_T("Get conflict files fail\n"));
347 this->ShowTab(IDC_CMD_LOG
);
351 if(list
.GetCount()>0)
353 this->m_ConflictFileList
.Clear();
358 this->m_ConflictFileList
.GetStatus(&list
,true);
359 this->m_ConflictFileList
.Show(CTGitPath::LOGACTIONS_UNMERGED
,
360 CTGitPath::LOGACTIONS_UNMERGED
);
362 this->ShowTab(IDC_IN_CONFLICT
);
365 this->ShowTab(IDC_CMD_LOG
);
370 if(newhash
== this->m_oldHash
)
372 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
373 this->m_InLogList
.ShowText(CString(MAKEINTRESOURCE(IDS_UPTODATE
)));
374 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
378 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
379 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
381 this->AddDiffFileList(&m_InChangeFileList
, &m_arInChangeList
, newhash
.ToString(), m_oldHash
.ToString());
384 range
.Format(_T("%s..%s"), m_oldHash
.ToString(), newhash
.ToString());
385 m_InLogList
.FillGitLog(nullptr, &range
, CGit::LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
);
387 this->ShowTab(IDC_IN_LOGLIST
);
391 void CSyncDlg::FetchComplete()
393 EnableControlButton(true);
395 this->FetchOutList(true);
397 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
398 ShowTab(IDC_CMD_GIT_PROG
);
400 ShowTab(IDC_CMD_LOG
);
401 if( (!this->m_GitCmdStatus
) && this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
404 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
405 dlg
.m_PostButtonTexts
.Add(_T("Email &Patch..."));
406 INT_PTR response
= dlg
.DoModal();
412 if (response
== IDC_REBASE_POST_BUTTON
)
414 CString cmd
= _T("/command:log");
415 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
416 CAppUtils::RunTortoiseGitProc(cmd
);
418 if(response
== IDC_REBASE_POST_BUTTON
+ 1)
420 CString cmd
, out
, err
;
421 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
423 g_Git
.FixBranchName(dlg
.m_Upstream
),
424 g_Git
.FixBranchName(dlg
.m_Branch
));
425 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
427 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
431 CAppUtils::SendPatchMail(cmd
,out
);
436 void CSyncDlg::OnBnClickedButtonPush()
440 m_ctrlCmdOut
.SetWindowTextW(_T(""));
443 if(this->m_strURL
.IsEmpty())
445 CMessageBox::Show(NULL
, IDS_PROC_GITCONFIG_URLEMPTY
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
449 this->m_regPushButton
=(DWORD
)this->m_ctrlPush
.GetCurrentEntry();
451 this->m_bAbort
=false;
452 this->m_GitCmdList
.clear();
454 ShowTab(IDC_CMD_LOG
);
462 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
464 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
469 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
471 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
476 CString refName
= g_Git
.FixBranchName(m_strLocalBranch
);
477 switch (m_ctrlPush
.GetCurrentEntry())
480 arg
+= _T(" --tags ");
483 refName
= _T("refs/notes/commits"); //default ref for notes
488 arg
+= _T(" --force ");
490 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
491 arg
+= _T("--progress ");
493 cmd
.Format(_T("git.exe push -v %s \"%s\" %s"),
498 if (!m_strRemoteBranch
.IsEmpty() && m_ctrlPush
.GetCurrentEntry() != 2)
500 cmd
+= _T(":") + m_strRemoteBranch
;
503 m_GitCmdList
.push_back(cmd
);
505 m_CurrentCmd
= GIT_COMMAND_PUSH
;
507 if(this->m_bAutoLoadPuttyKey
)
509 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
512 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
515 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
519 m_pThread
->m_bAutoDelete
= TRUE
;
520 m_pThread
->ResumeThread();
524 void CSyncDlg::OnBnClickedButtonApply()
527 if (g_Git
.GetHash(oldhash
, _T("HEAD")))
529 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
536 if(dlg
.DoModal() == IDOK
)
539 for (int i
= 0; i
< dlg
.m_PathList
.GetCount(); ++i
)
541 cmd
.Format(_T("git.exe am \"%s\""),dlg
.m_PathList
[i
].GetGitPathString());
543 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
545 CMessageBox::Show(NULL
,output
,_T("TortoiseGit"),MB_OK
);
550 this->m_ctrlCmdOut
.SetSel(-1,-1);
551 this->m_ctrlCmdOut
.ReplaceSel(cmd
+_T("\n"));
552 this->m_ctrlCmdOut
.SetSel(-1,-1);
553 this->m_ctrlCmdOut
.ReplaceSel(output
);
557 if (g_Git
.GetHash(newhash
, _T("HEAD")))
559 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash after applying patches.")), _T("TortoiseGit"), MB_ICONERROR
);
563 this->m_InLogList
.Clear();
564 this->m_InChangeFileList
.Clear();
566 if(newhash
== oldhash
)
568 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
569 this->m_InLogList
.ShowText(_T("No commits get from patch"));
570 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
575 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
576 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
579 range
.Format(_T("%s..%s"), m_oldHash
.ToString(), newhash
.ToString());
580 this->AddDiffFileList(&m_InChangeFileList
, &m_arInChangeList
, newhash
.ToString(), oldhash
.ToString());
581 m_InLogList
.FillGitLog(nullptr, &range
, CGit::LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
);
583 this->FetchOutList(true);
586 this->m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,true);
590 this->ShowTab(IDC_CMD_LOG
);
594 this->ShowTab(IDC_IN_LOGLIST
);
599 void CSyncDlg::OnBnClickedButtonEmail()
601 CString cmd
, out
, err
;
603 this->m_strLocalBranch
= this->m_ctrlLocalBranch
.GetString();
604 this->m_ctrlRemoteBranch
.GetWindowText(this->m_strRemoteBranch
);
605 this->m_ctrlURL
.GetWindowText(this->m_strURL
);
606 m_strURL
=m_strURL
.Trim();
607 m_strRemoteBranch
=m_strRemoteBranch
.Trim();
609 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
611 m_strURL
+_T('/')+m_strRemoteBranch
,g_Git
.FixBranchName(m_strLocalBranch
));
613 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
615 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
619 CAppUtils::SendPatchMail(cmd
,out
);
622 void CSyncDlg::ShowProgressCtrl(bool bShow
)
624 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
625 this->m_ctrlAnimate
.ShowWindow(b
);
626 this->m_ctrlProgress
.ShowWindow(b
);
627 this->m_ctrlProgLabel
.ShowWindow(b
);
628 this->m_ctrlAnimate
.Open(IDR_DOWNLOAD
);
630 this->m_ctrlAnimate
.Play(0, UINT_MAX
, UINT_MAX
);
632 this->m_ctrlAnimate
.Stop();
634 void CSyncDlg::ShowInputCtrl(bool bShow
)
636 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
637 this->m_ctrlURL
.ShowWindow(b
);
638 this->m_ctrlLocalBranch
.ShowWindow(b
);
639 this->m_ctrlRemoteBranch
.ShowWindow(b
);
640 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH
)->ShowWindow(b
);
641 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH
)->ShowWindow(b
);
642 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH
)->ShowWindow(b
);
643 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH
)->ShowWindow(b
);
644 this->GetDlgItem(IDC_BUTTON_MANAGE
)->ShowWindow(b
);
645 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->ShowWindow(b
);
646 this->GetDlgItem(IDC_CHECK_FORCE
)->ShowWindow(b
);
647 this->GetDlgItem(IDC_STATIC_REMOTE_URL
)->ShowWindow(b
);
649 BOOL
CSyncDlg::OnInitDialog()
651 CResizableStandAloneDialog::OnInitDialog();
652 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
654 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
655 // do this, Explorer would be unable to send that message to our window if we
656 // were running elevated. It's OK to make the call all the time, since if we're
657 // not elevated, this is a no-op.
658 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
659 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
660 CAutoLibrary hUser
= AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
663 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
664 if (pfnChangeWindowMessageFilterEx
)
666 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
669 m_pTaskbarList
.Release();
670 if (FAILED(m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
)))
671 m_pTaskbarList
= nullptr;
673 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->EnableWindow(CAppUtils::IsSSHPutty());
676 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
677 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
678 this->m_ctrlAnimate.Play(0,-1,-1);
681 // ------------------ Create Tabctrl -----------
682 CWnd
*pwnd
=this->GetDlgItem(IDC_BUTTON_TABCTRL
);
684 pwnd
->GetWindowRect(&rectDummy
);
685 this->ScreenToClient(rectDummy
);
687 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_SYNC_TAB
))
689 TRACE0("Failed to create output tab window\n");
690 return FALSE
; // fail to create
692 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
694 // -------------Create Command Log Ctrl ---------
696 dwStyle
= ES_MULTILINE
| ES_READONLY
| WS_CHILD
| WS_VISIBLE
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
|WS_VSCROLL
;
698 if( !m_ctrlCmdOut
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_CMD_LOG
))
700 TRACE0("Failed to create Log commits window\n");
701 return FALSE
; // fail to create
704 // set the font to use in the log message view, configured in the settings dialog
706 CAppUtils::CreateFontForLogs(m_logFont
);
707 //GetDlgItem(IDC_CMD_LOG)->SetFont(&m_logFont);
708 m_ctrlCmdOut
.SetFont(&m_logFont
);
709 m_ctrlTabCtrl
.InsertTab(&m_ctrlCmdOut
, CString(MAKEINTRESOURCE(IDS_LOG
)), -1);
711 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
713 //---------- Create in coming list ctrl -----------
714 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
716 if( !m_InLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_LOGLIST
))
718 TRACE0("Failed to create output commits window\n");
719 return FALSE
; // fail to create
722 m_ctrlTabCtrl
.InsertTab(&m_InLogList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_INCOMMITS
)), -1);
724 m_InLogList
.m_ColumnRegKey
=_T("SyncIn");
725 m_InLogList
.InsertGitColumn();
727 //----------- Create In Change file list -----------
728 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
730 if( !m_InChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CHANGELIST
))
732 TRACE0("Failed to create output change files window\n");
733 return FALSE
; // fail to create
735 m_ctrlTabCtrl
.InsertTab(&m_InChangeFileList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_INCHANGELIST
)), -1);
737 m_InChangeFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("InSyncDlg"),
738 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO
)|
739 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2
)), false, true, GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
);
742 //---------- Create Conflict List Ctrl -----------------
743 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
745 if( !m_ConflictFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CONFLICT
))
747 TRACE0("Failed to create output change files window\n");
748 return FALSE
; // fail to create
750 m_ctrlTabCtrl
.InsertTab(&m_ConflictFileList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_CONFLICTS
)), -1);
752 m_ConflictFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("ConflictSyncDlg"),
753 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO
)|
754 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2
)|
755 GITSLC_POPCONFLICT
|GITSLC_POPRESOLVE
),false);
758 //---------- Create Commit Out List Ctrl---------------
760 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
762 if( !m_OutLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_LOGLIST
))
764 TRACE0("Failed to create output commits window\n");
765 return FALSE
; // fail to create
769 m_ctrlTabCtrl
.InsertTab(&m_OutLogList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_OUTCOMMITS
)), -1);
771 m_OutLogList
.m_ColumnRegKey
= _T("SyncOut");
772 m_OutLogList
.InsertGitColumn();
774 //------------- Create Change File List Control ----------------
776 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
778 if( !m_OutChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_CHANGELIST
))
780 TRACE0("Failed to create output change files window\n");
781 return FALSE
; // fail to create
783 m_ctrlTabCtrl
.InsertTab(&m_OutChangeFileList
, CString(MAKEINTRESOURCE(IDS_PROC_SYNC_OUTCHANGELIST
)), -1);
785 m_OutChangeFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
, _T("OutSyncDlg"),
786 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO
)|
787 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2
)), false, true, GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
);
789 if (!m_GitProgressList
.Create(dwStyle
| LVS_OWNERDATA
, rectDummy
, &m_ctrlTabCtrl
, IDC_CMD_GIT_PROG
))
791 TRACE0("Failed to create Git Progress List Window\n");
792 return FALSE
; // fail to create
794 m_ctrlTabCtrl
.InsertTab(&m_GitProgressList
, CString(MAKEINTRESOURCE(IDS_LOG
)), -1);
795 m_GitProgressList
.m_pAnimate
= &m_ctrlAnimate
;
796 m_GitProgressList
.m_pPostWnd
= this;
797 m_GitProgressList
.m_pProgressLabelCtrl
= &m_ctrlProgLabel
;
798 m_GitProgressList
.m_pProgControl
= &m_ctrlProgress
;
799 m_GitProgressList
.m_pTaskbarList
= m_pTaskbarList
;
801 this->m_tooltips
.Create(this);
803 AddAnchor(IDC_SYNC_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
805 AddAnchor(IDC_GROUP_INFO
,TOP_LEFT
,TOP_RIGHT
);
806 AddAnchor(IDC_COMBOBOXEX_URL
,TOP_LEFT
,TOP_RIGHT
);
807 AddAnchor(IDC_BUTTON_MANAGE
,TOP_RIGHT
);
808 AddAnchor(IDC_BUTTON_PULL
,BOTTOM_LEFT
);
809 AddAnchor(IDC_BUTTON_PUSH
,BOTTOM_LEFT
);
810 AddAnchor(IDC_BUTTON_SUBMODULE
,BOTTOM_LEFT
);
811 AddAnchor(IDC_BUTTON_APPLY
,BOTTOM_RIGHT
);
812 AddAnchor(IDC_BUTTON_EMAIL
,BOTTOM_RIGHT
);
813 AddAnchor(IDC_PROGRESS_SYNC
,TOP_LEFT
,TOP_RIGHT
);
814 AddAnchor(IDOK
,BOTTOM_RIGHT
);
815 AddAnchor(IDHELP
,BOTTOM_RIGHT
);
816 AddAnchor(IDC_STATIC_STATUS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
817 AddAnchor(IDC_ANIMATE_SYNC
,TOP_LEFT
);
818 AddAnchor(IDC_BUTTON_COMMIT
,BOTTOM_LEFT
);
819 AddAnchor(IDC_LOG
, BOTTOM_LEFT
);
821 // do not use BRANCH_COMBOX_ADD_ANCHOR here, we want to have different stylings
822 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH
, TOP_LEFT
,TOP_CENTER
);
823 AddAnchor(IDC_COMBOBOXEX_REMOTE_BRANCH
, TOP_CENTER
, TOP_RIGHT
);
824 AddAnchor(IDC_BUTTON_LOCAL_BRANCH
, TOP_CENTER
);
825 AddAnchor(IDC_BUTTON_REMOTE_BRANCH
, TOP_RIGHT
);
826 AddAnchor(IDC_STATIC_REMOTE_BRANCH
, TOP_CENTER
);
827 AddAnchor(IDC_PROG_LABEL
, TOP_LEFT
);
829 AdjustControlSize(IDC_CHECK_PUTTY_KEY
);
830 AdjustControlSize(IDC_CHECK_FORCE
);
832 CString WorkingDir
=g_Git
.m_CurrentDir
;
833 WorkingDir
.Replace(_T(':'),_T('_'));
834 m_RegKeyRemoteBranch
= CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir
;
837 this->AddOthersToAnchor();
839 this->m_ctrlPush
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PUSH
)));
840 this->m_ctrlPush
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PUSHTAGS
)));
841 this->m_ctrlPush
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PUSHNOTES
)));
843 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_PULL
)));
844 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_FETCH
)));
845 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_FETCHREBASE
)));
846 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_REMOTEUPDATE
)));
847 this->m_ctrlPull
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_CLEANUPSTALEBRANCHES
)));
849 this->m_ctrlSubmodule
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULEUPDATE
)));
850 this->m_ctrlSubmodule
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULEINIT
)));
851 this->m_ctrlSubmodule
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_SUBKODULESYNC
)));
853 WorkingDir
.Replace(_T(':'),_T('_'));
856 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir
);
858 this->m_regPullButton
= CRegDWORD(regkey
+_T("\\Pull"),0);
859 this->m_regPushButton
= CRegDWORD(regkey
+_T("\\Push"),0);
860 this->m_regSubmoduleButton
= CRegDWORD(regkey
+_T("\\Submodule"));
861 this->m_regAutoLoadPutty
= CRegDWORD(regkey
+ _T("\\AutoLoadPutty"), CAppUtils::IsSSHPutty());
864 this->m_bAutoLoadPuttyKey
= m_regAutoLoadPutty
;
865 if(!CAppUtils::IsSSHPutty())
866 m_bAutoLoadPuttyKey
= false;
867 this->UpdateData(FALSE
);
869 this->m_ctrlPull
.SetCurrentEntry(this->m_regPullButton
);
870 this->m_ctrlPush
.SetCurrentEntry(this->m_regPushButton
);
871 this->m_ctrlSubmodule
.SetCurrentEntry(this->m_regSubmoduleButton
);
873 CString sWindowTitle
;
874 GetWindowText(sWindowTitle
);
875 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
877 EnableSaveRestore(_T("SyncDlg"));
879 this->m_ctrlURL
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir
, _T("url"));
883 if(!g_Git
.GetRemoteList(list
))
885 for (unsigned int i
= 0; i
< list
.size(); ++i
)
887 m_ctrlURL
.AddString(list
[i
]);
890 m_ctrlURL
.SetCurSel(0);
891 m_ctrlRemoteBranch
.SetCurSel(0);
892 m_ctrlURL
.SetURLHistory(true);
894 this->LoadBranchInfo();
896 this->m_bInited
=true;
899 m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,false);
900 m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
901 m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
902 m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
903 m_ctrlTabCtrl
.ShowTab(IDC_CMD_GIT_PROG
-1, false);
905 m_ctrlRemoteBranch
.m_bWantReturn
= TRUE
;
906 m_ctrlURL
.m_bWantReturn
= TRUE
;
908 this->m_Gitverion
= CAppUtils::GetMsysgitVersion();
910 return TRUE
; // return TRUE unless you set the focus to a control
911 // EXCEPTION: OCX Property Pages should return FALSE
914 void CSyncDlg::OnBnClickedButtonManage()
916 CAppUtils::LaunchRemoteSetting();
920 void CSyncDlg::Refresh()
922 theApp
.DoWaitCursor(1);
924 int lastSelected
= m_ctrlURL
.GetCurSel();
926 this->m_ctrlURL
.GetWindowText(url
);
928 this->m_ctrlURL
.Reset();
929 CString workingDir
= g_Git
.m_CurrentDir
;
930 workingDir
.Replace(_T(':'), _T('_'));
931 this->m_ctrlURL
.LoadHistory(_T("Software\\TortoiseGit\\History\\SyncURL\\") + workingDir
, _T("url"));
935 if (!g_Git
.GetRemoteList(list
))
937 for (int i
= 0; i
< list
.size(); ++i
)
939 m_ctrlURL
.AddString(list
[i
]);
944 if (lastSelected
>= 0 && !found
)
946 m_ctrlURL
.SetCurSel(0);
947 m_ctrlURL
.GetWindowText(url
);
952 this->m_ctrlLocalBranch
.GetWindowText(local
);
953 this->m_ctrlRemoteBranch
.GetWindowText(remote
);
955 this->LoadBranchInfo();
957 this->m_ctrlLocalBranch
.AddString(local
);
958 this->m_ctrlRemoteBranch
.AddString(remote
);
959 this->m_ctrlURL
.AddString(url
);
961 m_OutLogList
.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_REFRESHING
)));
962 this->FetchOutList(true);
963 theApp
.DoWaitCursor(-1);
966 BOOL
CSyncDlg::PreTranslateMessage(MSG
* pMsg
)
968 if (pMsg
->message
== WM_KEYDOWN
)
970 switch (pMsg
->wParam
)
976 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
981 /* Avoid TAB control destroy but dialog exist*/
986 ::GetClassName(pMsg
->hwnd
,buff
,128);
988 if(_tcsnicmp(buff
,_T("RichEdit20W"),128)==0)
990 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
996 m_tooltips
.RelayEvent(pMsg
);
997 return __super::PreTranslateMessage(pMsg
);
999 void CSyncDlg::FetchOutList(bool force
)
1003 m_OutChangeFileList
.Clear();
1004 this->m_OutLogList
.Clear();
1007 this->m_ctrlURL
.GetWindowText(remote
);
1008 CString remotebranch
;
1009 this->m_ctrlRemoteBranch
.GetWindowText(remotebranch
);
1010 remotebranch
=remote
+_T("/")+remotebranch
;
1011 CGitHash remotebranchHash
;
1012 g_Git
.GetHash(remotebranchHash
, remotebranch
);
1017 str
.LoadString(IDS_PROC_SYNC_PUSH_UNKNOWN
);
1018 m_OutLogList
.ShowText(str
);
1019 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
1020 m_OutLocalBranch
.Empty();
1021 m_OutRemoteBranch
.Empty();
1023 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1027 else if(remotebranchHash
.IsEmpty())
1030 str
.Format(IDS_PROC_SYNC_PUSH_UNKNOWNBRANCH
, remotebranch
);
1031 m_OutLogList
.ShowText(str
);
1032 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
1033 m_OutLocalBranch
.Empty();
1034 m_OutRemoteBranch
.Empty();
1036 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1041 CString localbranch
;
1042 localbranch
=this->m_ctrlLocalBranch
.GetString();
1044 if(localbranch
!= m_OutLocalBranch
|| m_OutRemoteBranch
!= remotebranch
|| force
)
1046 m_OutLogList
.ClearText();
1048 CGitHash base
, localBranchHash
;
1049 bool isFastForward
= g_Git
.IsFastForward(remotebranch
, localbranch
, &base
);
1051 if (g_Git
.GetHash(localBranchHash
, localbranch
))
1053 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + localbranch
+ _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
1056 if (remotebranchHash
== localBranchHash
)
1059 str
.Format(IDS_PROC_SYNC_COMMITSAHEAD
, 0, remotebranch
);
1060 m_OutLogList
.ShowText(str
);
1061 this->m_ctrlStatus
.SetWindowText(str
);
1062 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
1063 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1065 else if (isFastForward
|| m_bForce
)
1068 range
.Format(_T("%s..%s"), g_Git
.FixBranchName(remotebranch
), g_Git
.FixBranchName(localbranch
));
1070 m_OutLogList
.FillGitLog(nullptr, &range
, CGit::LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
);
1072 str
.Format(IDS_PROC_SYNC_COMMITSAHEAD
, m_OutLogList
.GetItemCount(), remotebranch
);
1073 this->m_ctrlStatus
.SetWindowText(str
);
1076 AddDiffFileList(&m_OutChangeFileList
, &m_arOutChangeList
, localbranch
, remotebranch
);
1079 AddDiffFileList(&m_OutChangeFileList
, &m_arOutChangeList
, localbranch
, base
.ToString());
1082 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,TRUE
);
1083 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(TRUE
);
1088 str
.Format(IDS_PROC_SYNC_NOFASTFORWARD
, localbranch
, remotebranch
);
1089 m_OutLogList
.ShowText(str
);
1090 this->m_ctrlStatus
.SetWindowText(str
);
1091 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID() - 1, FALSE
);
1092 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
1095 this->m_OutLocalBranch
=localbranch
;
1096 this->m_OutRemoteBranch
=remotebranch
;
1101 bool CSyncDlg::IsURL()
1104 this->m_ctrlURL
.GetWindowText(str
);
1105 if(str
.Find(_T('\\'))>=0 || str
.Find(_T('/'))>=0)
1110 void CSyncDlg::OnCbnEditchangeComboboxex()
1112 SetTimer(IDT_INPUT
, 1000, NULL
);
1113 this->m_OutLogList
.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_SYNC_WAINTINPUT
)));
1115 //this->FetchOutList();
1118 UINT
CSyncDlg::ProgressThread()
1120 m_startTick
= GetTickCount();
1121 m_GitCmdStatus
=CProgressDlg::RunCmdList(this,m_GitCmdList
,true,NULL
,&this->m_bAbort
);
1122 InterlockedExchange(&m_bBlock
, FALSE
);
1127 LRESULT
CSyncDlg::OnProgressUpdateUI(WPARAM wParam
,LPARAM lParam
)
1129 if(wParam
== MSG_PROGRESSDLG_START
)
1131 m_ctrlAnimate
.Play(0, UINT_MAX
, UINT_MAX
);
1132 this->m_ctrlProgress
.SetPos(0);
1135 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1136 m_pTaskbarList
->SetProgressValue(m_hWnd
, 0, 100);
1140 if(wParam
== MSG_PROGRESSDLG_END
|| wParam
== MSG_PROGRESSDLG_FAILED
)
1142 DWORD tickSpent
= GetTickCount() - m_startTick
;
1143 CString strEndTime
= CLoglistUtils::FormatDateAndTime(CTime::GetCurrentTime(), DATE_SHORTDATE
, true, false);
1145 m_ctrlAnimate
.Stop();
1146 m_ctrlProgress
.SetPos(100);
1147 //this->DialogEnableWindow(IDOK,TRUE);
1149 DWORD exitCode
= (DWORD
)lParam
;
1154 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
1155 m_pTaskbarList
->SetProgressValue(m_hWnd
, 100, 100);
1158 log
.Format(IDS_PROC_PROGRESS_GITUNCLEANEXIT
, exitCode
);
1160 err
.Format(_T("\r\n\r\n%s (%d ms @ %s)\r\n"), log
, tickSpent
, strEndTime
);
1161 CProgressDlg::InsertColorText(this->m_ctrlCmdOut
, err
, RGB(255,0,0));
1166 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1168 temp
.LoadString(IDS_SUCCESS
);
1170 log
.Format(_T("\r\n%s (%d ms @ %s)\r\n"), temp
, tickSpent
, strEndTime
);
1171 CProgressDlg::InsertColorText(this->m_ctrlCmdOut
, log
, RGB(0,0,255));
1174 //if(wParam == MSG_PROGRESSDLG_END)
1179 ParserCmdOutput((char)lParam
);
1184 void CSyncDlg::RunPostAction()
1186 if (this->m_CurrentCmd
== GIT_COMMAND_PUSH
)
1188 if (!m_GitCmdStatus
)
1191 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
1194 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
1199 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
1200 //ReportError(temp);
1201 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1207 EnableControlButton(true);
1209 this->FetchOutList(true);
1211 else if (this->m_CurrentCmd
== GIT_COMMAND_PULL
)
1215 else if (this->m_CurrentCmd
== GIT_COMMAND_FETCH
|| this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
1219 else if (this->m_CurrentCmd
== GIT_COMMAND_SUBMODULE
)
1221 //this->m_ctrlCmdOut.SetSel(-1,-1);
1222 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
1223 //this->m_ctrlCmdOut.SetSel(-1,-1);
1224 EnableControlButton(true);
1227 else if (this->m_CurrentCmd
== GIT_COMMAND_REMOTE
)
1229 this->FetchOutList(true);
1230 EnableControlButton(true);
1234 void CSyncDlg::ParserCmdOutput(char ch
)
1236 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut
,m_ctrlProgress
,m_hWnd
,m_pTaskbarList
,m_LogText
,ch
);
1238 void CSyncDlg::OnBnClickedButtonCommit()
1240 CString cmd
= _T("/command:commit");
1241 cmd
+= _T(" /path:\"");
1242 cmd
+= g_Git
.m_CurrentDir
;
1245 CAppUtils::RunTortoiseGitProc(cmd
);
1248 void CSyncDlg::OnOK()
1252 m_ctrlURL
.SaveHistory();
1254 m_regAutoLoadPutty
= this->m_bAutoLoadPuttyKey
;
1258 void CSyncDlg::OnBnClickedButtonSubmodule()
1262 m_ctrlCmdOut
.SetWindowTextW(_T(""));
1265 this->m_regSubmoduleButton
= (DWORD
)this->m_ctrlSubmodule
.GetCurrentEntry();
1267 this->SwitchToRun();
1269 this->m_bAbort
=false;
1270 this->m_GitCmdList
.clear();
1272 ShowTab(IDC_CMD_LOG
);
1276 switch (m_ctrlSubmodule
.GetCurrentEntry())
1279 cmd
=_T("git.exe submodule update --init");
1282 cmd
=_T("git.exe submodule init");
1285 cmd
=_T("git.exe submodule sync");
1289 m_GitCmdList
.push_back(cmd
);
1291 m_CurrentCmd
= GIT_COMMAND_SUBMODULE
;
1293 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1294 if (m_pThread
==NULL
)
1296 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1300 m_pThread
->m_bAutoDelete
= TRUE
;
1301 m_pThread
->ResumeThread();
1305 void CSyncDlg::OnTimer(UINT_PTR nIDEvent
)
1307 if( nIDEvent
== IDT_INPUT
)
1309 KillTimer(IDT_INPUT
);
1310 this->FetchOutList(true);
1315 void CSyncDlg::OnLvnInLogListColumnClick(NMHDR
* /* pNMHDR */, LRESULT
*pResult
)
1320 LRESULT
CSyncDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1322 m_pTaskbarList
.Release();
1323 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
1324 m_GitProgressList
.m_pTaskbarList
= m_pTaskbarList
;
1325 SetUUIDOverlayIcon(m_hWnd
);
1329 void CSyncDlg::OnBnClickedCheckForce()
1334 void CSyncDlg::OnBnClickedLog()
1336 CString cmd
= _T("/command:log");
1337 cmd
+= _T(" /path:\"");
1338 cmd
+= g_Git
.m_CurrentDir
;
1341 CAppUtils::RunTortoiseGitProc(cmd
);
1344 LRESULT
CSyncDlg::OnProgCmdFinish(WPARAM
/*wParam*/, LPARAM
/*lParam*/)