1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009 - 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"
26 #include "progressdlg.h"
27 #include "MessageBox.h"
28 #include "ImportPatchDlg.h"
29 #include "PathUtils.h"
30 #include "RebaseDlg.h"
35 IMPLEMENT_DYNAMIC(CSyncDlg
, CResizableStandAloneDialog
)
37 CSyncDlg::CSyncDlg(CWnd
* pParent
/*=NULL*/)
38 : CResizableStandAloneDialog(CSyncDlg::IDD
, pParent
)
40 m_pTooltip
=&this->m_tooltips
;
43 m_bAutoLoadPuttyKey
= CAppUtils::IsSSHPutty();
52 void CSyncDlg::DoDataExchange(CDataExchange
* pDX
)
54 CDialog::DoDataExchange(pDX
);
55 DDX_Check(pDX
, IDC_CHECK_PUTTY_KEY
, m_bAutoLoadPuttyKey
);
56 DDX_Check(pDX
, IDC_CHECK_FORCE
,m_bForce
);
57 DDX_Control(pDX
, IDC_COMBOBOXEX_URL
, m_ctrlURL
);
58 DDX_Control(pDX
, IDC_BUTTON_TABCTRL
, m_ctrlDumyButton
);
59 DDX_Control(pDX
, IDC_BUTTON_PULL
, m_ctrlPull
);
60 DDX_Control(pDX
, IDC_BUTTON_PUSH
, m_ctrlPush
);
61 DDX_Control(pDX
, IDC_STATIC_STATUS
, m_ctrlStatus
);
62 DDX_Control(pDX
, IDC_PROGRESS_SYNC
, m_ctrlProgress
);
63 DDX_Control(pDX
, IDC_ANIMATE_SYNC
, m_ctrlAnimate
);
64 DDX_Control(pDX
, IDC_BUTTON_SUBMODULE
,m_ctrlSubmodule
);
69 BEGIN_MESSAGE_MAP(CSyncDlg
, CResizableStandAloneDialog
)
70 ON_BN_CLICKED(IDC_BUTTON_PULL
, &CSyncDlg::OnBnClickedButtonPull
)
71 ON_BN_CLICKED(IDC_BUTTON_PUSH
, &CSyncDlg::OnBnClickedButtonPush
)
72 ON_BN_CLICKED(IDC_BUTTON_APPLY
, &CSyncDlg::OnBnClickedButtonApply
)
73 ON_BN_CLICKED(IDC_BUTTON_EMAIL
, &CSyncDlg::OnBnClickedButtonEmail
)
74 ON_BN_CLICKED(IDC_BUTTON_MANAGE
, &CSyncDlg::OnBnClickedButtonManage
)
76 ON_NOTIFY(CBEN_ENDEDIT
, IDC_COMBOBOXEX_URL
, &CSyncDlg::OnCbenEndeditComboboxexUrl
)
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_BN_CLICKED(IDC_BUTTON_COMMIT
, &CSyncDlg::OnBnClickedButtonCommit
)
81 ON_BN_CLICKED(IDC_BUTTON_SUBMODULE
, &CSyncDlg::OnBnClickedButtonSubmodule
)
86 void CSyncDlg::EnableControlButton(bool bEnabled
)
88 GetDlgItem(IDC_BUTTON_PULL
)->EnableWindow(bEnabled
);
89 GetDlgItem(IDC_BUTTON_PUSH
)->EnableWindow(bEnabled
);
90 GetDlgItem(IDC_BUTTON_APPLY
)->EnableWindow(bEnabled
);
91 GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(bEnabled
);
92 GetDlgItem(IDOK
)->EnableWindow(bEnabled
);
93 GetDlgItem(IDC_BUTTON_SUBMODULE
)->EnableWindow(bEnabled
);
95 // CSyncDlg message handlers
97 void CSyncDlg::OnBnClickedButtonPull()
99 // TODO: Add your control notification handler code here
101 CurrentEntry
= this->m_ctrlPull
.GetCurrentEntry();
102 this->m_regPullButton
= CurrentEntry
;
105 this->m_bAbort
=false;
106 this->m_GitCmdList
.clear();
111 m_oldHash
= g_Git
.GetHash(CString(_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 cmd
.Format(_T("git.exe pull %s \"%s\" %s"),
155 this->m_strRemoteBranch
);
157 m_CurrentCmd
= GIT_COMMAND_PULL
;
158 m_GitCmdList
.push_back(cmd
);
160 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
163 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
167 m_pThread
->m_bAutoDelete
= TRUE
;
168 m_pThread
->ResumeThread();
174 if(CurrentEntry
== 1 || CurrentEntry
==2 ) //Fetch
176 CString remotebranch
;
177 if(this->IsURL() || m_strRemoteBranch
.IsEmpty())
179 remotebranch
=this->m_strRemoteBranch
;
184 remotebranch
.Format(_T("remotes/%s/%s"),
185 m_strURL
,m_strRemoteBranch
);
186 if(g_Git
.GetHash(remotebranch
).IsEmpty())
187 remotebranch
=m_strRemoteBranch
;
189 remotebranch
=m_strRemoteBranch
+_T(":")+remotebranch
;
192 cmd
.Format(_T("git.exe fetch %s \"%s\" %s"),
197 if(CurrentEntry
== 1)
198 m_CurrentCmd
= GIT_COMMAND_FETCH
;
200 m_CurrentCmd
= GIT_COMMAND_FETCHANDREBASE
;
201 m_GitCmdList
.push_back(cmd
);
203 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
206 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
210 m_pThread
->m_bAutoDelete
= TRUE
;
211 m_pThread
->ResumeThread();
216 if(CurrentEntry
== 3)
218 m_CurrentCmd
= GIT_COMMAND_REMOTE
;
219 cmd
=_T("git.exe remote update");
220 m_GitCmdList
.push_back(cmd
);
222 InterlockedExchange(&m_bBlock
, TRUE
);
224 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
227 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
228 InterlockedExchange(&m_bBlock
, FALSE
);
232 m_pThread
->m_bAutoDelete
= TRUE
;
233 m_pThread
->ResumeThread();
239 void CSyncDlg::PullComplete()
241 EnableControlButton(true);
243 this->FetchOutList(true);
246 newhash
= g_Git
.GetHash(CString(_T("HEAD")));
250 if( this ->m_GitCmdStatus
)
253 if(g_Git
.ListConflictFile(list
))
255 this->m_ctrlCmdOut
.SetSel(-1,-1);
256 this->m_ctrlCmdOut
.ReplaceSel(_T("Get conflict files fail\n"));
258 this->ShowTab(IDC_CMD_LOG
);
262 if(list
.GetCount()>0)
264 this->m_ConflictFileList
.Clear();
269 this->m_ConflictFileList
.GetStatus(&list
,true);
270 this->m_ConflictFileList
.Show(CTGitPath::LOGACTIONS_UNMERGED
,
271 CTGitPath::LOGACTIONS_UNMERGED
);
273 this->ShowTab(IDC_IN_CONFLICT
);
275 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_NORMAL
);
278 this->ShowTab(IDC_CMD_LOG
);
282 if(newhash
== this->m_oldHash
)
284 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
285 this->m_InLogList
.ShowText(_T("No commits get after pull"));
286 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
290 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
291 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
293 this->AddDiffFileList(&m_InChangeFileList
,&m_arInChangeList
,newhash
,m_oldHash
);
295 m_InLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
296 &this->m_oldHash
,&newhash
);
298 this->ShowTab(IDC_IN_LOGLIST
);
302 void CSyncDlg::FetchComplete()
304 EnableControlButton(true);
306 this->FetchOutList(true);
308 ShowTab(IDC_CMD_LOG
);
309 if( (!this->m_GitCmdStatus
) && this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
312 dlg
.m_PostButtonTexts
.Add(_T("Email &Patch..."));
313 int response
= dlg
.DoModal();
319 if(response
== IDC_REBASE_POST_BUTTON
)
322 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
324 dlg
.m_Upstream
,dlg
.m_Branch
);
325 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
327 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
331 CAppUtils::SendPatchMail(cmd
,out
);
336 void CSyncDlg::OnBnClickedButtonPush()
338 // TODO: Add your control notification handler code here
342 if(this->m_strURL
.IsEmpty())
344 CMessageBox::Show(NULL
,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
348 this->m_regPushButton
=this->m_ctrlPush
.GetCurrentEntry();
350 this->m_bAbort
=false;
351 this->m_GitCmdList
.clear();
353 ShowTab(IDC_CMD_LOG
);
363 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
365 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
370 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
372 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
378 switch (m_ctrlPush
.GetCurrentEntry())
381 tags
= _T(" --tags ");
389 force
= _T(" --force ");
391 cmd
.Format(_T("git.exe push %s %s %s \"%s\" %s"),
396 if (!m_strRemoteBranch
.IsEmpty())
398 cmd
+= _T(":") + m_strRemoteBranch
;
401 m_GitCmdList
.push_back(cmd
);
403 m_CurrentCmd
= GIT_COMMAND_PUSH
;
405 if(this->m_bAutoLoadPuttyKey
)
407 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
410 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
413 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
417 m_pThread
->m_bAutoDelete
= TRUE
;
418 m_pThread
->ResumeThread();
423 void CSyncDlg::OnBnClickedButtonApply()
425 // TODO: Add your control notification handler code here
427 oldhash
=g_Git
.GetHash(CString(_T("HEAD")));
432 if(dlg
.DoModal() == IDOK
)
435 for(int i
=0;i
<dlg
.m_PathList
.GetCount();i
++)
437 cmd
.Format(_T("git.exe am \"%s\""),dlg
.m_PathList
[i
].GetGitPathString());
439 if(g_Git
.Run(cmd
,&output
,CP_ACP
))
441 CMessageBox::Show(NULL
,output
,_T("TortoiseGit"),MB_OK
);
446 this->m_ctrlCmdOut
.SetSel(-1,-1);
447 this->m_ctrlCmdOut
.ReplaceSel(cmd
+_T("\n"));
448 this->m_ctrlCmdOut
.SetSel(-1,-1);
449 this->m_ctrlCmdOut
.ReplaceSel(output
);
453 CString newhash
=g_Git
.GetHash(CString(_T("HEAD")));
455 this->m_InLogList
.Clear();
456 this->m_InChangeFileList
.Clear();
458 if(newhash
== oldhash
)
460 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
461 this->m_InLogList
.ShowText(_T("No commits get from patch"));
462 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
466 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
467 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
469 this->AddDiffFileList(&m_InChangeFileList
,&m_arInChangeList
,newhash
,oldhash
);
470 m_InLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
473 this->FetchOutList(true);
477 this->m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,true);
481 this->ShowTab(IDC_CMD_LOG
);
485 this->ShowTab(IDC_IN_LOGLIST
);
490 void CSyncDlg::OnBnClickedButtonEmail()
492 // TODO: Add your control notification handler code here
495 this->m_strLocalBranch
= this->m_ctrlLocalBranch
.GetString();
496 this->m_ctrlRemoteBranch
.GetWindowText(this->m_strRemoteBranch
);
497 this->m_ctrlURL
.GetWindowText(this->m_strURL
);
498 m_strURL
=m_strURL
.Trim();
499 m_strRemoteBranch
=m_strRemoteBranch
.Trim();
501 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
503 m_strURL
+_T('/')+m_strRemoteBranch
,m_strLocalBranch
);
505 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
507 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
511 CAppUtils::SendPatchMail(cmd
,out
);
514 void CSyncDlg::ShowProgressCtrl(bool bShow
)
516 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
517 this->m_ctrlAnimate
.ShowWindow(b
);
518 this->m_ctrlProgress
.ShowWindow(b
);
519 this->m_ctrlAnimate
.Open(IDR_DOWNLOAD
);
521 this->m_ctrlAnimate
.Play(0,-1,-1);
523 this->m_ctrlAnimate
.Stop();
525 void CSyncDlg::ShowInputCtrl(bool bShow
)
527 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
528 this->m_ctrlURL
.ShowWindow(b
);
529 this->m_ctrlLocalBranch
.ShowWindow(b
);
530 this->m_ctrlRemoteBranch
.ShowWindow(b
);
531 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH
)->ShowWindow(b
);
532 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH
)->ShowWindow(b
);
533 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH
)->ShowWindow(b
);
534 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH
)->ShowWindow(b
);
535 this->GetDlgItem(IDC_BUTTON_MANAGE
)->ShowWindow(b
);
536 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->ShowWindow(b
);
537 this->GetDlgItem(IDC_CHECK_FORCE
)->ShowWindow(b
);
538 this->GetDlgItem(IDC_STATIC_REMOTE_URL
)->ShowWindow(b
);
541 BOOL
CSyncDlg::OnInitDialog()
543 CResizableStandAloneDialog::OnInitDialog();
546 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->EnableWindow(CAppUtils::IsSSHPutty());
549 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
550 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
551 this->m_ctrlAnimate.Play(0,-1,-1);
554 // ------------------ Create Tabctrl -----------
555 CWnd
*pwnd
=this->GetDlgItem(IDC_BUTTON_TABCTRL
);
557 pwnd
->GetWindowRect(&rectDummy
);
558 this->ScreenToClient(rectDummy
);
560 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_SYNC_TAB
))
562 TRACE0("Failed to create output tab window\n");
563 return FALSE
; // fail to create
565 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
567 // -------------Create Command Log Ctrl ---------
569 dwStyle
= ES_MULTILINE
| ES_READONLY
| WS_CHILD
| WS_VISIBLE
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
|WS_VSCROLL
;
571 if( !m_ctrlCmdOut
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_CMD_LOG
))
573 TRACE0("Failed to create Log commits window\n");
574 return FALSE
; // fail to create
577 m_ctrlTabCtrl
.InsertTab(&m_ctrlCmdOut
,_T("Log"),-1);
579 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
581 //---------- Create in coming list ctrl -----------
582 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
584 if( !m_InLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_LOGLIST
))
586 TRACE0("Failed to create output commits window\n");
587 return FALSE
; // fail to create
591 m_ctrlTabCtrl
.InsertTab(&m_InLogList
,_T("In Commits"),-1);
593 m_InLogList
.InsertGitColumn();
595 //----------- Create In Change file list -----------
596 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
598 if( !m_InChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CHANGELIST
))
600 TRACE0("Failed to create output change files window\n");
601 return FALSE
; // fail to create
603 m_ctrlTabCtrl
.InsertTab(&m_InChangeFileList
,_T("In ChangeList"),-1);
605 m_InChangeFileList
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
|SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("OutSyncDlg"),
606 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO
)|
607 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2
)),false);
610 //---------- Create Conflict List Ctrl -----------------
611 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
613 if( !m_ConflictFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CONFLICT
))
615 TRACE0("Failed to create output change files window\n");
616 return FALSE
; // fail to create
618 m_ctrlTabCtrl
.InsertTab(&m_ConflictFileList
,_T("Conflict"),-1);
620 m_ConflictFileList
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
|SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("OutSyncDlg"),
621 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO
)|
622 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2
)|
623 SVNSLC_POPCONFLICT
|SVNSLC_POPRESOLVE
),false);
626 //---------- Create Commit Out List Ctrl---------------
628 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
630 if( !m_OutLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_LOGLIST
))
632 TRACE0("Failed to create output commits window\n");
633 return FALSE
; // fail to create
637 m_ctrlTabCtrl
.InsertTab(&m_OutLogList
,_T("Out Commits"),-1);
640 m_OutLogList
.InsertGitColumn();
642 //------------- Create Change File List Control ----------------
644 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
646 if( !m_OutChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_CHANGELIST
))
648 TRACE0("Failed to create output change files window\n");
649 return FALSE
; // fail to create
651 m_ctrlTabCtrl
.InsertTab(&m_OutChangeFileList
,_T("Out ChangeList"),-1);
653 m_OutChangeFileList
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
|SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("OutSyncDlg"),
654 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO
)|
655 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2
)),false);
657 this->m_tooltips
.Create(this);
659 AddAnchor(IDC_SYNC_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
661 AddAnchor(IDC_GROUP_INFO
,TOP_LEFT
,TOP_RIGHT
);
662 AddAnchor(IDC_COMBOBOXEX_URL
,TOP_LEFT
,TOP_RIGHT
);
663 AddAnchor(IDC_BUTTON_MANAGE
,TOP_RIGHT
);
664 AddAnchor(IDC_BUTTON_PULL
,BOTTOM_LEFT
);
665 AddAnchor(IDC_BUTTON_PUSH
,BOTTOM_LEFT
);
666 AddAnchor(IDC_BUTTON_SUBMODULE
,BOTTOM_LEFT
);
667 AddAnchor(IDC_BUTTON_APPLY
,BOTTOM_RIGHT
);
668 AddAnchor(IDC_BUTTON_EMAIL
,BOTTOM_RIGHT
);
669 AddAnchor(IDC_PROGRESS_SYNC
,TOP_LEFT
,TOP_RIGHT
);
670 AddAnchor(IDOK
,BOTTOM_RIGHT
);
671 AddAnchor(IDHELP
,BOTTOM_RIGHT
);
672 AddAnchor(IDC_STATIC_STATUS
,BOTTOM_LEFT
);
673 AddAnchor(IDC_ANIMATE_SYNC
,TOP_LEFT
);
674 AddAnchor(IDC_BUTTON_COMMIT
,BOTTOM_LEFT
);
676 BRANCH_COMBOX_ADD_ANCHOR();
678 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_HIDE
);
680 CString WorkingDir
=g_Git
.m_CurrentDir
;
681 WorkingDir
.Replace(_T(':'),_T('_'));
682 m_RegKeyRemoteBranch
= CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir
;
685 this->AddOthersToAnchor();
686 // TODO: Add extra initialization here
688 this->m_ctrlPush
.AddEntry(CString(_T("Pus&h")));
689 this->m_ctrlPush
.AddEntry(CString(_T("Push ta&gs")));
690 ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));
692 this->m_ctrlPull
.AddEntry(CString(_T("&Pull")));
693 this->m_ctrlPull
.AddEntry(CString(_T("Fetc&h")));
694 this->m_ctrlPull
.AddEntry(CString(_T("Fetch&&Re&base")));
695 this->m_ctrlPull
.AddEntry(CString(_T("Remote Update")));
697 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Update")));
698 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Init")));
699 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Sync")));
701 WorkingDir
.Replace(_T(':'),_T('_'));
704 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir
);
706 this->m_regPullButton
= CRegDWORD(regkey
+_T("\\Pull"),0);
707 this->m_regPushButton
= CRegDWORD(regkey
+_T("\\Push"),0);
708 this->m_regSubmoduleButton
= CRegDWORD(regkey
+_T("\\Submodule"));
709 this->m_regAutoLoadPutty
= CRegDWORD(regkey
+ _T("\\AutoLoadPutty"), CAppUtils::IsSSHPutty());
712 this->m_bAutoLoadPuttyKey
= m_regAutoLoadPutty
;
713 if(!CAppUtils::IsSSHPutty())
714 m_bAutoLoadPuttyKey
= false;
715 this->UpdateData(FALSE
);
717 this->m_ctrlPull
.SetCurrentEntry(this->m_regPullButton
);
718 this->m_ctrlPush
.SetCurrentEntry(this->m_regPushButton
);
719 this->m_ctrlSubmodule
.SetCurrentEntry(this->m_regSubmoduleButton
);
722 this->GetWindowText(str
);
723 str
+= _T(" - ") + g_Git
.m_CurrentDir
;
724 this->SetWindowText(str
);
726 EnableSaveRestore(_T("SyncDlg"));
728 this->m_ctrlURL
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir
, _T("url"));
732 if(!g_Git
.GetRemoteList(list
))
734 for(unsigned int i
=0;i
<list
.size();i
++)
736 m_ctrlURL
.AddString(list
[i
]);
739 m_ctrlURL
.SetCurSel(0);
740 m_ctrlRemoteBranch
.SetCurSel(0);
741 m_ctrlURL
.SetURLHistory(true);
743 this->LoadBranchInfo();
745 this->m_bInited
=true;
748 m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,false);
749 m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
750 m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
751 m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
754 m_ctrlRemoteBranch
.m_bWantReturn
= TRUE
;
755 m_ctrlURL
.m_bWantReturn
= TRUE
;
757 return TRUE
; // return TRUE unless you set the focus to a control
758 // EXCEPTION: OCX Property Pages should return FALSE
761 void CSyncDlg::OnBnClickedButtonManage()
763 // TODO: Add your control notification handler code here
764 CAppUtils::LaunchRemoteSetting();
767 void CSyncDlg::Refresh()
769 theApp
.DoWaitCursor(1);
774 this->m_ctrlLocalBranch
.GetWindowText(local
);
775 this->m_ctrlRemoteBranch
.GetWindowText(remote
);
776 this->m_ctrlURL
.GetWindowText(url
);
778 this->LoadBranchInfo();
780 this->m_ctrlLocalBranch
.AddString(local
);
781 this->m_ctrlRemoteBranch
.AddString(remote
);
782 this->m_ctrlURL
.AddString(url
);
784 m_OutLogList
.ShowText(_T("Refresh ..."));
785 this->FetchOutList(true);
786 theApp
.DoWaitCursor(-1);
789 BOOL
CSyncDlg::PreTranslateMessage(MSG
* pMsg
)
791 // TODO: Add your specialized code here and/or call the base class
793 if (pMsg
->message
== WM_KEYDOWN
)
795 switch (pMsg
->wParam
)
801 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
806 /* Avoid TAB control destroy but dialog exist*/
811 ::GetClassName(pMsg
->hwnd
,buff
,128);
813 if(_tcsnicmp(buff
,_T("RichEdit20W"),128)==0)
815 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
821 m_tooltips
.RelayEvent(pMsg
);
822 return __super::PreTranslateMessage(pMsg
);
824 void CSyncDlg::FetchOutList(bool force
)
828 m_OutChangeFileList
.Clear();
829 this->m_OutLogList
.Clear();
832 this->m_ctrlURL
.GetWindowText(remote
);
833 CString remotebranch
;
834 this->m_ctrlRemoteBranch
.GetWindowText(remotebranch
);
835 remotebranch
=remote
+_T("/")+remotebranch
;
840 str
=_T("Don't know what will push because you enter URL");
841 m_OutLogList
.ShowText(str
);
842 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
843 m_OutLocalBranch
.Empty();
844 m_OutRemoteBranch
.Empty();
846 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
849 }else if(g_Git
.GetHash(remotebranch
).GetLength()<40)
852 str
.Format(_T("Don't know what will push because unknown \"%s\""),remotebranch
);
853 m_OutLogList
.ShowText(str
);
854 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
855 m_OutLocalBranch
.Empty();
856 m_OutRemoteBranch
.Empty();
858 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
864 localbranch
=this->m_ctrlLocalBranch
.GetString();
866 if(localbranch
!= m_OutLocalBranch
|| m_OutRemoteBranch
!= remotebranch
|| force
)
868 m_OutLogList
.ClearText();
869 m_OutLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
870 &remotebranch
,&localbranch
);
873 if(m_OutLogList
.GetItemCount() == 0)
875 str
.Format(_T("No commits ahead \"%s\""),remotebranch
);
876 m_OutLogList
.ShowText(str
);
877 this->m_ctrlStatus
.SetWindowText(str
);
878 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
879 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
883 str
.Format(_T("%d commits ahead \"%s\""),m_OutLogList
.GetItemCount(),remotebranch
);
884 this->m_ctrlStatus
.SetWindowText(str
);
886 AddDiffFileList(&m_OutChangeFileList
,&m_arOutChangeList
,localbranch
,remotebranch
);
888 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,TRUE
);
889 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(TRUE
);
892 this->m_OutLocalBranch
=localbranch
;
893 this->m_OutRemoteBranch
=remotebranch
;
898 bool CSyncDlg::IsURL()
901 this->m_ctrlURL
.GetWindowText(str
);
902 if(str
.Find(_T('\\'))>=0 || str
.Find(_T('/'))>=0)
907 void CSyncDlg::OnCbenEndeditComboboxexUrl(NMHDR
*pNMHDR
, LRESULT
*pResult
)
909 // TODO: Add your control notification handler code here
913 void CSyncDlg::OnCbnEditchangeComboboxex()
915 SetTimer(IDT_INPUT
, 1000, NULL
);
916 this->m_OutLogList
.ShowText(_T("Wait for input"));
918 //this->FetchOutList();
919 // TODO: Add your control notification handler code here
922 UINT
CSyncDlg::ProgressThread()
924 m_GitCmdStatus
=CProgressDlg::RunCmdList(this,m_GitCmdList
,true,NULL
,&this->m_bAbort
);
925 InterlockedExchange(&m_bBlock
, FALSE
);
930 LRESULT
CSyncDlg::OnProgressUpdateUI(WPARAM wParam
,LPARAM lParam
)
932 if(wParam
== MSG_PROGRESSDLG_START
)
934 m_ctrlAnimate
.Play(0,-1,-1);
935 this->m_ctrlProgress
.SetPos(0);
938 if(wParam
== MSG_PROGRESSDLG_END
|| wParam
== MSG_PROGRESSDLG_FAILED
)
941 m_ctrlAnimate
.Stop();
942 m_ctrlProgress
.SetPos(100);
943 //this->DialogEnableWindow(IDOK,TRUE);
945 //if(wParam == MSG_PROGRESSDLG_END)
946 if(this->m_CurrentCmd
== GIT_COMMAND_PUSH
)
951 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
954 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
959 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
961 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
967 EnableControlButton(true);
969 this->FetchOutList(true);
971 if(this->m_CurrentCmd
== GIT_COMMAND_PULL
)
975 if(this->m_CurrentCmd
== GIT_COMMAND_FETCH
|| this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
979 if(this->m_CurrentCmd
== GIT_COMMAND_SUBMODULE
)
981 //this->m_ctrlCmdOut.SetSel(-1,-1);
982 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
983 //this->m_ctrlCmdOut.SetSel(-1,-1);
984 EnableControlButton(true);
987 if(this->m_CurrentCmd
== GIT_COMMAND_REMOTE
)
989 this->FetchOutList(true);
990 EnableControlButton(true);
996 ParserCmdOutput((TCHAR
)lParam
);
1002 void CSyncDlg::ParserCmdOutput(char ch
)
1004 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut
,m_ctrlProgress
,m_LogText
,ch
);
1006 void CSyncDlg::OnBnClickedButtonCommit()
1008 // TODO: Add your control notification handler code here
1009 CString proc
=CPathUtils::GetAppDirectory();
1010 proc
+= _T("TortoiseProc.exe /command:commit");
1011 proc
+= _T(" /path:\"");
1012 proc
+= g_Git
.m_CurrentDir
;
1014 CAppUtils::LaunchApplication(proc
,IDS_ERROR_CANNON_FIND_TORTOISEPROC
,false);
1017 void CSyncDlg::OnOK()
1019 // TODO: Add your specialized code here and/or call the base class
1022 m_ctrlURL
.SaveHistory();
1024 m_regAutoLoadPutty
= this->m_bAutoLoadPuttyKey
;
1028 void CSyncDlg::OnBnClickedButtonSubmodule()
1030 // TODO: Add your control notification handler code here
1031 // TODO: Add your control notification handler code here
1035 this->m_regSubmoduleButton
= this->m_ctrlSubmodule
.GetCurrentEntry();
1037 this->SwitchToRun();
1039 this->m_bAbort
=false;
1040 this->m_GitCmdList
.clear();
1042 ShowTab(IDC_CMD_LOG
);
1046 switch (m_ctrlSubmodule
.GetCurrentEntry())
1049 cmd
=_T("git.exe submodule update");
1052 cmd
=_T("git.exe submodule init");
1055 cmd
=_T("git.exe submodule sync");
1060 m_GitCmdList
.push_back(cmd
);
1062 m_CurrentCmd
= GIT_COMMAND_SUBMODULE
;
1064 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1065 if (m_pThread
==NULL
)
1067 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1071 m_pThread
->m_bAutoDelete
= TRUE
;
1072 m_pThread
->ResumeThread();
1078 void CSyncDlg::OnTimer(UINT_PTR nIDEvent
)
1080 if( nIDEvent
== IDT_INPUT
)
1082 KillTimer(IDT_INPUT
);
1083 this->FetchOutList(true);