1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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
)
41 m_pTooltip
=&this->m_tooltips
;
44 m_bAutoLoadPuttyKey
= CAppUtils::IsSSHPutty();
53 void CSyncDlg::DoDataExchange(CDataExchange
* pDX
)
55 CDialog::DoDataExchange(pDX
);
56 DDX_Check(pDX
, IDC_CHECK_PUTTY_KEY
, m_bAutoLoadPuttyKey
);
57 DDX_Check(pDX
, IDC_CHECK_FORCE
,m_bForce
);
58 DDX_Control(pDX
, IDC_COMBOBOXEX_URL
, m_ctrlURL
);
59 DDX_Control(pDX
, IDC_BUTTON_TABCTRL
, m_ctrlDumyButton
);
60 DDX_Control(pDX
, IDC_BUTTON_PULL
, m_ctrlPull
);
61 DDX_Control(pDX
, IDC_BUTTON_PUSH
, m_ctrlPush
);
62 DDX_Control(pDX
, IDC_STATIC_STATUS
, m_ctrlStatus
);
63 DDX_Control(pDX
, IDC_PROGRESS_SYNC
, m_ctrlProgress
);
64 DDX_Control(pDX
, IDC_ANIMATE_SYNC
, m_ctrlAnimate
);
65 DDX_Control(pDX
, IDC_BUTTON_SUBMODULE
,m_ctrlSubmodule
);
70 BEGIN_MESSAGE_MAP(CSyncDlg
, CResizableStandAloneDialog
)
71 ON_BN_CLICKED(IDC_BUTTON_PULL
, &CSyncDlg::OnBnClickedButtonPull
)
72 ON_BN_CLICKED(IDC_BUTTON_PUSH
, &CSyncDlg::OnBnClickedButtonPush
)
73 ON_BN_CLICKED(IDC_BUTTON_APPLY
, &CSyncDlg::OnBnClickedButtonApply
)
74 ON_BN_CLICKED(IDC_BUTTON_EMAIL
, &CSyncDlg::OnBnClickedButtonEmail
)
75 ON_BN_CLICKED(IDC_BUTTON_MANAGE
, &CSyncDlg::OnBnClickedButtonManage
)
77 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL
, &CSyncDlg::OnCbnEditchangeComboboxex
)
78 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH
, &CSyncDlg::OnCbnEditchangeComboboxex
)
79 ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI
, OnProgressUpdateUI
)
80 ON_NOTIFY(LVN_COLUMNCLICK
, IDC_IN_LOGLIST
, OnLvnInLogListColumnClick
)
81 ON_BN_CLICKED(IDC_BUTTON_COMMIT
, &CSyncDlg::OnBnClickedButtonCommit
)
82 ON_BN_CLICKED(IDC_BUTTON_SUBMODULE
, &CSyncDlg::OnBnClickedButtonSubmodule
)
84 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
88 void CSyncDlg::EnableControlButton(bool bEnabled
)
90 GetDlgItem(IDC_BUTTON_PULL
)->EnableWindow(bEnabled
);
91 GetDlgItem(IDC_BUTTON_PUSH
)->EnableWindow(bEnabled
);
92 GetDlgItem(IDC_BUTTON_APPLY
)->EnableWindow(bEnabled
);
93 GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(bEnabled
);
94 GetDlgItem(IDOK
)->EnableWindow(bEnabled
);
95 GetDlgItem(IDC_BUTTON_SUBMODULE
)->EnableWindow(bEnabled
);
97 // CSyncDlg message handlers
99 void CSyncDlg::OnBnClickedButtonPull()
102 CurrentEntry
= this->m_ctrlPull
.GetCurrentEntry();
103 this->m_regPullButton
= CurrentEntry
;
105 this->m_bAbort
=false;
106 this->m_GitCmdList
.clear();
111 m_oldHash
= g_Git
.GetHash(_T("HEAD"));
113 if( CurrentEntry
== 0)
115 if( g_Git
.GetHash(this->m_strLocalBranch
) != m_oldHash
)
117 CMessageBox::Show(NULL
,_T("Pull require local branch must be current branch"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
122 if(this->m_strURL
.IsEmpty())
124 CMessageBox::Show(NULL
,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
128 if(this->m_bAutoLoadPuttyKey
)
130 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
137 force
= _T(" --force ");
141 ShowTab(IDC_CMD_LOG
);
143 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
144 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
145 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
147 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_HIDE
);
150 if(CurrentEntry
== 0) //Pull
152 CString remotebranch
;
153 remotebranch
= m_strRemoteBranch
;
158 configName
.Format(L
"branch.%s.merge", this->m_strLocalBranch
);
159 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
161 configName
.Format(L
"branch.%s.remote", m_strLocalBranch
);
162 CString pullRemote
= g_Git
.GetConfigValue(configName
);
164 if(pullBranch
== remotebranch
&& pullRemote
== this->m_strURL
)
165 remotebranch
.Empty();
168 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
169 force
+= _T("--progress ");
171 cmd
.Format(_T("git.exe pull -v %s \"%s\" %s"),
176 m_CurrentCmd
= GIT_COMMAND_PULL
;
177 m_GitCmdList
.push_back(cmd
);
179 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
182 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
186 m_pThread
->m_bAutoDelete
= TRUE
;
187 m_pThread
->ResumeThread();
193 if(CurrentEntry
== 1 || CurrentEntry
==2 ) //Fetch
195 CString remotebranch
;
196 if(this->IsURL() || m_strRemoteBranch
.IsEmpty())
198 remotebranch
=this->m_strRemoteBranch
;
203 remotebranch
.Format(_T("remotes/%s/%s"),
204 m_strURL
,m_strRemoteBranch
);
205 if(g_Git
.GetHash(remotebranch
).IsEmpty())
206 remotebranch
=m_strRemoteBranch
;
208 remotebranch
=m_strRemoteBranch
+_T(":")+remotebranch
;
211 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
212 force
+= _T("--progress ");
214 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"),
219 if(CurrentEntry
== 1)
220 m_CurrentCmd
= GIT_COMMAND_FETCH
;
222 m_CurrentCmd
= GIT_COMMAND_FETCHANDREBASE
;
223 m_GitCmdList
.push_back(cmd
);
225 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
228 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
232 m_pThread
->m_bAutoDelete
= TRUE
;
233 m_pThread
->ResumeThread();
238 if(CurrentEntry
== 3)
240 m_CurrentCmd
= GIT_COMMAND_REMOTE
;
241 cmd
=_T("git.exe remote update");
242 m_GitCmdList
.push_back(cmd
);
244 InterlockedExchange(&m_bBlock
, TRUE
);
246 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
249 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
250 InterlockedExchange(&m_bBlock
, FALSE
);
254 m_pThread
->m_bAutoDelete
= TRUE
;
255 m_pThread
->ResumeThread();
259 ///Cleanup stale remote banches
260 if(CurrentEntry
== 4)
262 m_CurrentCmd
= GIT_COMMAND_REMOTE
;
263 cmd
.Format(_T("git.exe remote prune \"%s\""), m_strURL
);
264 m_GitCmdList
.push_back(cmd
);
266 InterlockedExchange(&m_bBlock
, TRUE
);
268 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
271 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
272 InterlockedExchange(&m_bBlock
, FALSE
);
276 m_pThread
->m_bAutoDelete
= TRUE
;
277 m_pThread
->ResumeThread();
282 void CSyncDlg::PullComplete()
284 EnableControlButton(true);
286 this->FetchOutList(true);
289 newhash
= g_Git
.GetHash(_T("HEAD"));
291 if( this ->m_GitCmdStatus
)
294 if(g_Git
.ListConflictFile(list
))
296 this->m_ctrlCmdOut
.SetSel(-1,-1);
297 this->m_ctrlCmdOut
.ReplaceSel(_T("Get conflict files fail\n"));
299 this->ShowTab(IDC_CMD_LOG
);
303 if(list
.GetCount()>0)
305 this->m_ConflictFileList
.Clear();
310 this->m_ConflictFileList
.GetStatus(&list
,true);
311 this->m_ConflictFileList
.Show(CTGitPath::LOGACTIONS_UNMERGED
,
312 CTGitPath::LOGACTIONS_UNMERGED
);
314 this->ShowTab(IDC_IN_CONFLICT
);
316 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_NORMAL
);
319 this->ShowTab(IDC_CMD_LOG
);
324 if(newhash
== this->m_oldHash
)
326 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
327 this->m_InLogList
.ShowText(_T("No commits get after pull"));
328 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
332 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
333 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
335 CString oldhash
=m_oldHash
.ToString();
336 this->AddDiffFileList(&m_InChangeFileList
,&m_arInChangeList
,newhash
,oldhash
);
338 m_InLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
341 this->ShowTab(IDC_IN_LOGLIST
);
345 void CSyncDlg::FetchComplete()
347 EnableControlButton(true);
349 this->FetchOutList(true);
351 ShowTab(IDC_CMD_LOG
);
352 if( (!this->m_GitCmdStatus
) && this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
355 dlg
.m_PostButtonTexts
.Add(_T("Email &Patch..."));
356 int response
= dlg
.DoModal();
362 if(response
== IDC_REBASE_POST_BUTTON
)
364 CString cmd
, out
, err
;
365 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
367 g_Git
.FixBranchName(dlg
.m_Upstream
),
368 g_Git
.FixBranchName(dlg
.m_Branch
));
369 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
371 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
375 CAppUtils::SendPatchMail(cmd
,out
);
380 void CSyncDlg::OnBnClickedButtonPush()
385 if(this->m_strURL
.IsEmpty())
387 CMessageBox::Show(NULL
,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
391 this->m_regPushButton
=this->m_ctrlPush
.GetCurrentEntry();
393 this->m_bAbort
=false;
394 this->m_GitCmdList
.clear();
396 ShowTab(IDC_CMD_LOG
);
404 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
406 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
411 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
413 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
418 switch (m_ctrlPush
.GetCurrentEntry())
421 arg
+= _T(" --tags ");
424 arg
+= _T(" --all ");
429 arg
+= _T(" --force ");
431 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
432 arg
+= _T("--progress ");
434 cmd
.Format(_T("git.exe push -v %s \"%s\" %s"),
437 g_Git
.FixBranchName(m_strLocalBranch
));
439 if (!m_strRemoteBranch
.IsEmpty())
441 cmd
+= _T(":") + m_strRemoteBranch
;
444 m_GitCmdList
.push_back(cmd
);
446 m_CurrentCmd
= GIT_COMMAND_PUSH
;
448 if(this->m_bAutoLoadPuttyKey
)
450 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
453 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
456 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
460 m_pThread
->m_bAutoDelete
= TRUE
;
461 m_pThread
->ResumeThread();
465 void CSyncDlg::OnBnClickedButtonApply()
468 oldhash
=g_Git
.GetHash(_T("HEAD"));
473 if(dlg
.DoModal() == IDOK
)
476 for(int i
=0;i
<dlg
.m_PathList
.GetCount();i
++)
478 cmd
.Format(_T("git.exe am \"%s\""),dlg
.m_PathList
[i
].GetGitPathString());
480 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
482 CMessageBox::Show(NULL
,output
,_T("TortoiseGit"),MB_OK
);
487 this->m_ctrlCmdOut
.SetSel(-1,-1);
488 this->m_ctrlCmdOut
.ReplaceSel(cmd
+_T("\n"));
489 this->m_ctrlCmdOut
.SetSel(-1,-1);
490 this->m_ctrlCmdOut
.ReplaceSel(output
);
493 CString newhash
=g_Git
.GetHash(_T("HEAD"));
495 this->m_InLogList
.Clear();
496 this->m_InChangeFileList
.Clear();
498 if(newhash
== oldhash
)
500 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
501 this->m_InLogList
.ShowText(_T("No commits get from patch"));
502 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
507 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
508 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
510 this->AddDiffFileList(&m_InChangeFileList
,&m_arInChangeList
,newhash
,oldhash
);
511 m_InLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
514 this->FetchOutList(true);
517 this->m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,true);
521 this->ShowTab(IDC_CMD_LOG
);
525 this->ShowTab(IDC_IN_LOGLIST
);
530 void CSyncDlg::OnBnClickedButtonEmail()
532 CString cmd
, out
, err
;
534 this->m_strLocalBranch
= this->m_ctrlLocalBranch
.GetString();
535 this->m_ctrlRemoteBranch
.GetWindowText(this->m_strRemoteBranch
);
536 this->m_ctrlURL
.GetWindowText(this->m_strURL
);
537 m_strURL
=m_strURL
.Trim();
538 m_strRemoteBranch
=m_strRemoteBranch
.Trim();
540 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
542 m_strURL
+_T('/')+m_strRemoteBranch
,g_Git
.FixBranchName(m_strLocalBranch
));
544 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
546 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
550 CAppUtils::SendPatchMail(cmd
,out
);
553 void CSyncDlg::ShowProgressCtrl(bool bShow
)
555 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
556 this->m_ctrlAnimate
.ShowWindow(b
);
557 this->m_ctrlProgress
.ShowWindow(b
);
558 this->m_ctrlAnimate
.Open(IDR_DOWNLOAD
);
560 this->m_ctrlAnimate
.Play(0,-1,-1);
562 this->m_ctrlAnimate
.Stop();
564 void CSyncDlg::ShowInputCtrl(bool bShow
)
566 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
567 this->m_ctrlURL
.ShowWindow(b
);
568 this->m_ctrlLocalBranch
.ShowWindow(b
);
569 this->m_ctrlRemoteBranch
.ShowWindow(b
);
570 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH
)->ShowWindow(b
);
571 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH
)->ShowWindow(b
);
572 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH
)->ShowWindow(b
);
573 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH
)->ShowWindow(b
);
574 this->GetDlgItem(IDC_BUTTON_MANAGE
)->ShowWindow(b
);
575 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->ShowWindow(b
);
576 this->GetDlgItem(IDC_CHECK_FORCE
)->ShowWindow(b
);
577 this->GetDlgItem(IDC_STATIC_REMOTE_URL
)->ShowWindow(b
);
579 BOOL
CSyncDlg::OnInitDialog()
581 CResizableStandAloneDialog::OnInitDialog();
582 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
584 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
585 // do this, Explorer would be unable to send that message to our window if we
586 // were running elevated. It's OK to make the call all the time, since if we're
587 // not elevated, this is a no-op.
588 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
589 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
590 CAutoLibrary hUser
= ::LoadLibrary(_T("user32.dll"));
593 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
594 if (pfnChangeWindowMessageFilterEx
)
596 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
599 m_pTaskbarList
.Release();
600 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
602 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->EnableWindow(CAppUtils::IsSSHPutty());
605 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
606 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
607 this->m_ctrlAnimate.Play(0,-1,-1);
610 // ------------------ Create Tabctrl -----------
611 CWnd
*pwnd
=this->GetDlgItem(IDC_BUTTON_TABCTRL
);
613 pwnd
->GetWindowRect(&rectDummy
);
614 this->ScreenToClient(rectDummy
);
616 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_SYNC_TAB
))
618 TRACE0("Failed to create output tab window\n");
619 return FALSE
; // fail to create
621 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
623 // -------------Create Command Log Ctrl ---------
625 dwStyle
= ES_MULTILINE
| ES_READONLY
| WS_CHILD
| WS_VISIBLE
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
|WS_VSCROLL
;
627 if( !m_ctrlCmdOut
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_CMD_LOG
))
629 TRACE0("Failed to create Log commits window\n");
630 return FALSE
; // fail to create
633 // set the font to use in the log message view, configured in the settings dialog
635 CAppUtils::CreateFontForLogs(m_logFont
);
636 //GetDlgItem(IDC_CMD_LOG)->SetFont(&m_logFont);
637 m_ctrlCmdOut
.SetFont(&m_logFont
);
638 m_ctrlTabCtrl
.InsertTab(&m_ctrlCmdOut
,_T("Log"),-1);
640 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
642 //---------- Create in coming list ctrl -----------
643 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
645 if( !m_InLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_LOGLIST
))
647 TRACE0("Failed to create output commits window\n");
648 return FALSE
; // fail to create
651 m_ctrlTabCtrl
.InsertTab(&m_InLogList
,_T("In Commits"),-1);
653 m_InLogList
.m_ColumnRegKey
=_T("SyncIn");
654 m_InLogList
.InsertGitColumn();
656 //----------- Create In Change file list -----------
657 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
659 if( !m_InChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CHANGELIST
))
661 TRACE0("Failed to create output change files window\n");
662 return FALSE
; // fail to create
664 m_ctrlTabCtrl
.InsertTab(&m_InChangeFileList
,_T("In ChangeList"),-1);
666 m_InChangeFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("OutSyncDlg"),
667 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO
)|
668 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2
)),false);
671 //---------- Create Conflict List Ctrl -----------------
672 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
674 if( !m_ConflictFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CONFLICT
))
676 TRACE0("Failed to create output change files window\n");
677 return FALSE
; // fail to create
679 m_ctrlTabCtrl
.InsertTab(&m_ConflictFileList
,_T("Conflict"),-1);
681 m_ConflictFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("OutSyncDlg"),
682 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO
)|
683 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2
)|
684 GITSLC_POPCONFLICT
|GITSLC_POPRESOLVE
),false);
687 //---------- Create Commit Out List Ctrl---------------
689 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
691 if( !m_OutLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_LOGLIST
))
693 TRACE0("Failed to create output commits window\n");
694 return FALSE
; // fail to create
698 m_ctrlTabCtrl
.InsertTab(&m_OutLogList
,_T("Out Commits"),-1);
700 m_OutLogList
.m_ColumnRegKey
= _T("SyncOut");
701 m_OutLogList
.InsertGitColumn();
703 //------------- Create Change File List Control ----------------
705 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
707 if( !m_OutChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_CHANGELIST
))
709 TRACE0("Failed to create output change files window\n");
710 return FALSE
; // fail to create
712 m_ctrlTabCtrl
.InsertTab(&m_OutChangeFileList
,_T("Out ChangeList"),-1);
714 m_OutChangeFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("OutSyncDlg"),
715 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO
)|
716 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2
)),false);
718 this->m_tooltips
.Create(this);
720 AddAnchor(IDC_SYNC_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
722 AddAnchor(IDC_GROUP_INFO
,TOP_LEFT
,TOP_RIGHT
);
723 AddAnchor(IDC_COMBOBOXEX_URL
,TOP_LEFT
,TOP_RIGHT
);
724 AddAnchor(IDC_BUTTON_MANAGE
,TOP_RIGHT
);
725 AddAnchor(IDC_BUTTON_PULL
,BOTTOM_LEFT
);
726 AddAnchor(IDC_BUTTON_PUSH
,BOTTOM_LEFT
);
727 AddAnchor(IDC_BUTTON_SUBMODULE
,BOTTOM_LEFT
);
728 AddAnchor(IDC_BUTTON_APPLY
,BOTTOM_RIGHT
);
729 AddAnchor(IDC_BUTTON_EMAIL
,BOTTOM_RIGHT
);
730 AddAnchor(IDC_PROGRESS_SYNC
,TOP_LEFT
,TOP_RIGHT
);
731 AddAnchor(IDOK
,BOTTOM_RIGHT
);
732 AddAnchor(IDHELP
,BOTTOM_RIGHT
);
733 AddAnchor(IDC_STATIC_STATUS
,BOTTOM_LEFT
);
734 AddAnchor(IDC_ANIMATE_SYNC
,TOP_LEFT
);
735 AddAnchor(IDC_BUTTON_COMMIT
,BOTTOM_LEFT
);
737 // do not use BRANCH_COMBOX_ADD_ANCHOR here, we want to have different stylings
738 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH
, TOP_LEFT
,TOP_CENTER
);
739 AddAnchor(IDC_COMBOBOXEX_REMOTE_BRANCH
, TOP_CENTER
, TOP_RIGHT
);
740 AddAnchor(IDC_BUTTON_LOCAL_BRANCH
, TOP_CENTER
);
741 AddAnchor(IDC_BUTTON_REMOTE_BRANCH
, TOP_RIGHT
);
742 AddAnchor(IDC_STATIC_REMOTE_BRANCH
, TOP_CENTER
);
744 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_HIDE
);
746 CString WorkingDir
=g_Git
.m_CurrentDir
;
747 WorkingDir
.Replace(_T(':'),_T('_'));
748 m_RegKeyRemoteBranch
= CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir
;
751 this->AddOthersToAnchor();
753 this->m_ctrlPush
.AddEntry(CString(_T("Pus&h")));
754 this->m_ctrlPush
.AddEntry(CString(_T("Push ta&gs")));
755 ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));
757 this->m_ctrlPull
.AddEntry(CString(_T("&Pull")));
758 this->m_ctrlPull
.AddEntry(CString(_T("Fetc&h")));
759 this->m_ctrlPull
.AddEntry(CString(_T("Fetch&&Re&base")));
760 this->m_ctrlPull
.AddEntry(CString(_T("Remote Update")));
761 this->m_ctrlPull
.AddEntry(CString(_T("Cleanup stale remote banches")));
763 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Update")));
764 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Init")));
765 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Sync")));
767 WorkingDir
.Replace(_T(':'),_T('_'));
770 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir
);
772 this->m_regPullButton
= CRegDWORD(regkey
+_T("\\Pull"),0);
773 this->m_regPushButton
= CRegDWORD(regkey
+_T("\\Push"),0);
774 this->m_regSubmoduleButton
= CRegDWORD(regkey
+_T("\\Submodule"));
775 this->m_regAutoLoadPutty
= CRegDWORD(regkey
+ _T("\\AutoLoadPutty"), CAppUtils::IsSSHPutty());
777 m_tooltips
.Create(this);
779 this->m_bAutoLoadPuttyKey
= m_regAutoLoadPutty
;
780 if(!CAppUtils::IsSSHPutty())
781 m_bAutoLoadPuttyKey
= false;
782 this->UpdateData(FALSE
);
784 this->m_ctrlPull
.SetCurrentEntry(this->m_regPullButton
);
785 this->m_ctrlPush
.SetCurrentEntry(this->m_regPushButton
);
786 this->m_ctrlSubmodule
.SetCurrentEntry(this->m_regSubmoduleButton
);
788 CString sWindowTitle
;
789 GetWindowText(sWindowTitle
);
790 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
792 EnableSaveRestore(_T("SyncDlg"));
794 this->m_ctrlURL
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir
, _T("url"));
798 if(!g_Git
.GetRemoteList(list
))
800 for(unsigned int i
=0;i
<list
.size();i
++)
802 m_ctrlURL
.AddString(list
[i
]);
805 m_ctrlURL
.SetCurSel(0);
806 m_ctrlRemoteBranch
.SetCurSel(0);
807 m_ctrlURL
.SetURLHistory(true);
809 this->LoadBranchInfo();
811 this->m_bInited
=true;
814 m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,false);
815 m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
816 m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
817 m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
819 m_ctrlRemoteBranch
.m_bWantReturn
= TRUE
;
820 m_ctrlURL
.m_bWantReturn
= TRUE
;
822 this->m_Gitverion
= CAppUtils::GetMsysgitVersion();
824 return TRUE
; // return TRUE unless you set the focus to a control
825 // EXCEPTION: OCX Property Pages should return FALSE
828 void CSyncDlg::OnBnClickedButtonManage()
830 CAppUtils::LaunchRemoteSetting();
834 void CSyncDlg::Refresh()
836 theApp
.DoWaitCursor(1);
841 this->m_ctrlLocalBranch
.GetWindowText(local
);
842 this->m_ctrlRemoteBranch
.GetWindowText(remote
);
843 this->m_ctrlURL
.GetWindowText(url
);
845 this->LoadBranchInfo();
847 this->m_ctrlLocalBranch
.AddString(local
);
848 this->m_ctrlRemoteBranch
.AddString(remote
);
849 this->m_ctrlURL
.AddString(url
);
851 m_OutLogList
.ShowText(_T("Refresh ..."));
852 this->FetchOutList(true);
853 theApp
.DoWaitCursor(-1);
856 BOOL
CSyncDlg::PreTranslateMessage(MSG
* pMsg
)
858 if (pMsg
->message
== WM_KEYDOWN
)
860 switch (pMsg
->wParam
)
866 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
871 /* Avoid TAB control destroy but dialog exist*/
876 ::GetClassName(pMsg
->hwnd
,buff
,128);
878 if(_tcsnicmp(buff
,_T("RichEdit20W"),128)==0)
880 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
886 m_tooltips
.RelayEvent(pMsg
);
887 return __super::PreTranslateMessage(pMsg
);
889 void CSyncDlg::FetchOutList(bool force
)
893 m_OutChangeFileList
.Clear();
894 this->m_OutLogList
.Clear();
897 this->m_ctrlURL
.GetWindowText(remote
);
898 CString remotebranch
;
899 this->m_ctrlRemoteBranch
.GetWindowText(remotebranch
);
900 remotebranch
=remote
+_T("/")+remotebranch
;
905 str
=_T("Don't know what will push because you enter URL");
906 m_OutLogList
.ShowText(str
);
907 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
908 m_OutLocalBranch
.Empty();
909 m_OutRemoteBranch
.Empty();
911 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
915 else if(g_Git
.GetHash(remotebranch
).IsEmpty())
918 str
.Format(_T("Don't know what will push because unknown \"%s\""),remotebranch
);
919 m_OutLogList
.ShowText(str
);
920 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
921 m_OutLocalBranch
.Empty();
922 m_OutRemoteBranch
.Empty();
924 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
930 localbranch
=this->m_ctrlLocalBranch
.GetString();
932 if(localbranch
!= m_OutLocalBranch
|| m_OutRemoteBranch
!= remotebranch
|| force
)
934 m_OutLogList
.ClearText();
935 m_OutLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
936 &remotebranch
,&localbranch
);
939 if(m_OutLogList
.GetItemCount() == 0)
941 str
.Format(_T("No commits ahead \"%s\""),remotebranch
);
942 m_OutLogList
.ShowText(str
);
943 this->m_ctrlStatus
.SetWindowText(str
);
944 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
945 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
949 str
.Format(_T("%d commits ahead \"%s\""),m_OutLogList
.GetItemCount(),remotebranch
);
950 this->m_ctrlStatus
.SetWindowText(str
);
952 AddDiffFileList(&m_OutChangeFileList
,&m_arOutChangeList
,localbranch
,remotebranch
);
954 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,TRUE
);
955 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(TRUE
);
958 this->m_OutLocalBranch
=localbranch
;
959 this->m_OutRemoteBranch
=remotebranch
;
964 bool CSyncDlg::IsURL()
967 this->m_ctrlURL
.GetWindowText(str
);
968 if(str
.Find(_T('\\'))>=0 || str
.Find(_T('/'))>=0)
973 void CSyncDlg::OnCbnEditchangeComboboxex()
975 SetTimer(IDT_INPUT
, 1000, NULL
);
976 this->m_OutLogList
.ShowText(_T("Wait for input"));
978 //this->FetchOutList();
981 UINT
CSyncDlg::ProgressThread()
983 m_GitCmdStatus
=CProgressDlg::RunCmdList(this,m_GitCmdList
,true,NULL
,&this->m_bAbort
);
984 InterlockedExchange(&m_bBlock
, FALSE
);
989 LRESULT
CSyncDlg::OnProgressUpdateUI(WPARAM wParam
,LPARAM lParam
)
991 if(wParam
== MSG_PROGRESSDLG_START
)
993 m_ctrlAnimate
.Play(0,-1,-1);
994 this->m_ctrlProgress
.SetPos(0);
997 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
998 m_pTaskbarList
->SetProgressValue(m_hWnd
, 0, 100);
1002 if(wParam
== MSG_PROGRESSDLG_END
|| wParam
== MSG_PROGRESSDLG_FAILED
)
1005 m_ctrlAnimate
.Stop();
1006 m_ctrlProgress
.SetPos(100);
1007 //this->DialogEnableWindow(IDOK,TRUE);
1009 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1011 //if(wParam == MSG_PROGRESSDLG_END)
1012 if(this->m_CurrentCmd
== GIT_COMMAND_PUSH
)
1017 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
1020 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
1025 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
1026 //ReportError(temp);
1027 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1033 EnableControlButton(true);
1035 this->FetchOutList(true);
1037 if(this->m_CurrentCmd
== GIT_COMMAND_PULL
)
1041 if(this->m_CurrentCmd
== GIT_COMMAND_FETCH
|| this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
1045 if(this->m_CurrentCmd
== GIT_COMMAND_SUBMODULE
)
1047 //this->m_ctrlCmdOut.SetSel(-1,-1);
1048 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
1049 //this->m_ctrlCmdOut.SetSel(-1,-1);
1050 EnableControlButton(true);
1053 if(this->m_CurrentCmd
== GIT_COMMAND_REMOTE
)
1055 this->FetchOutList(true);
1056 EnableControlButton(true);
1062 ParserCmdOutput((char)lParam
);
1068 void CSyncDlg::ParserCmdOutput(char ch
)
1070 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut
,m_ctrlProgress
,m_hWnd
,m_pTaskbarList
,m_LogText
,ch
);
1072 void CSyncDlg::OnBnClickedButtonCommit()
1074 CString cmd
= _T("/command:commit");
1075 cmd
+= _T(" /path:\"");
1076 cmd
+= g_Git
.m_CurrentDir
;
1079 CAppUtils::RunTortoiseProc(cmd
);
1082 void CSyncDlg::OnOK()
1086 m_ctrlURL
.SaveHistory();
1088 m_regAutoLoadPutty
= this->m_bAutoLoadPuttyKey
;
1092 void CSyncDlg::OnBnClickedButtonSubmodule()
1097 this->m_regSubmoduleButton
= this->m_ctrlSubmodule
.GetCurrentEntry();
1099 this->SwitchToRun();
1101 this->m_bAbort
=false;
1102 this->m_GitCmdList
.clear();
1104 ShowTab(IDC_CMD_LOG
);
1108 switch (m_ctrlSubmodule
.GetCurrentEntry())
1111 cmd
=_T("git.exe submodule update --init");
1114 cmd
=_T("git.exe submodule init");
1117 cmd
=_T("git.exe submodule sync");
1121 m_GitCmdList
.push_back(cmd
);
1123 m_CurrentCmd
= GIT_COMMAND_SUBMODULE
;
1125 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1126 if (m_pThread
==NULL
)
1128 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1132 m_pThread
->m_bAutoDelete
= TRUE
;
1133 m_pThread
->ResumeThread();
1137 void CSyncDlg::OnTimer(UINT_PTR nIDEvent
)
1139 if( nIDEvent
== IDT_INPUT
)
1141 KillTimer(IDT_INPUT
);
1142 this->FetchOutList(true);
1147 void CSyncDlg::OnLvnInLogListColumnClick(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1152 LRESULT
CSyncDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1154 m_pTaskbarList
.Release();
1155 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);