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_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL
, &CSyncDlg::OnCbnEditchangeComboboxex
)
77 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH
, &CSyncDlg::OnCbnEditchangeComboboxex
)
78 ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI
, OnProgressUpdateUI
)
79 ON_BN_CLICKED(IDC_BUTTON_COMMIT
, &CSyncDlg::OnBnClickedButtonCommit
)
80 ON_BN_CLICKED(IDC_BUTTON_SUBMODULE
, &CSyncDlg::OnBnClickedButtonSubmodule
)
82 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
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()
100 CurrentEntry
= this->m_ctrlPull
.GetCurrentEntry();
101 this->m_regPullButton
= CurrentEntry
;
103 this->m_bAbort
=false;
104 this->m_GitCmdList
.clear();
109 m_oldHash
= g_Git
.GetHash(_T("HEAD"));
111 if( CurrentEntry
== 0)
113 if( g_Git
.GetHash(this->m_strLocalBranch
) != m_oldHash
)
115 CMessageBox::Show(NULL
,_T("Pull require local branch must be current branch"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
120 if(this->m_strURL
.IsEmpty())
122 CMessageBox::Show(NULL
,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
126 if(this->m_bAutoLoadPuttyKey
)
128 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
135 force
= _T(" --force ");
139 ShowTab(IDC_CMD_LOG
);
141 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
142 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
143 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
145 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_HIDE
);
148 if(CurrentEntry
== 0) //Pull
150 CString remotebranch
;
151 remotebranch
= m_strRemoteBranch
;
156 configName
.Format(L
"branch.%s.merge", this->m_strLocalBranch
);
157 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
159 configName
.Format(L
"branch.%s.remote", m_strLocalBranch
);
160 CString pullRemote
= g_Git
.GetConfigValue(configName
);
162 if(pullBranch
== remotebranch
&& pullRemote
== this->m_strURL
)
163 remotebranch
.Empty();
166 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
167 force
+= _T("--progress ");
169 cmd
.Format(_T("git.exe pull -v %s \"%s\" %s"),
174 m_CurrentCmd
= GIT_COMMAND_PULL
;
175 m_GitCmdList
.push_back(cmd
);
177 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
180 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
184 m_pThread
->m_bAutoDelete
= TRUE
;
185 m_pThread
->ResumeThread();
191 if(CurrentEntry
== 1 || CurrentEntry
==2 ) //Fetch
193 CString remotebranch
;
194 if(this->IsURL() || m_strRemoteBranch
.IsEmpty())
196 remotebranch
=this->m_strRemoteBranch
;
201 remotebranch
.Format(_T("remotes/%s/%s"),
202 m_strURL
,m_strRemoteBranch
);
203 if(g_Git
.GetHash(remotebranch
).IsEmpty())
204 remotebranch
=m_strRemoteBranch
;
206 remotebranch
=m_strRemoteBranch
+_T(":")+remotebranch
;
209 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
210 force
+= _T("--progress ");
212 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"),
217 if(CurrentEntry
== 1)
218 m_CurrentCmd
= GIT_COMMAND_FETCH
;
220 m_CurrentCmd
= GIT_COMMAND_FETCHANDREBASE
;
221 m_GitCmdList
.push_back(cmd
);
223 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
226 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
230 m_pThread
->m_bAutoDelete
= TRUE
;
231 m_pThread
->ResumeThread();
236 if(CurrentEntry
== 3)
238 m_CurrentCmd
= GIT_COMMAND_REMOTE
;
239 cmd
=_T("git.exe remote update");
240 m_GitCmdList
.push_back(cmd
);
242 InterlockedExchange(&m_bBlock
, TRUE
);
244 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
247 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
248 InterlockedExchange(&m_bBlock
, FALSE
);
252 m_pThread
->m_bAutoDelete
= TRUE
;
253 m_pThread
->ResumeThread();
258 void CSyncDlg::PullComplete()
260 EnableControlButton(true);
262 this->FetchOutList(true);
265 newhash
= g_Git
.GetHash(_T("HEAD"));
267 if( this ->m_GitCmdStatus
)
270 if(g_Git
.ListConflictFile(list
))
272 this->m_ctrlCmdOut
.SetSel(-1,-1);
273 this->m_ctrlCmdOut
.ReplaceSel(_T("Get conflict files fail\n"));
275 this->ShowTab(IDC_CMD_LOG
);
279 if(list
.GetCount()>0)
281 this->m_ConflictFileList
.Clear();
286 this->m_ConflictFileList
.GetStatus(&list
,true);
287 this->m_ConflictFileList
.Show(CTGitPath::LOGACTIONS_UNMERGED
,
288 CTGitPath::LOGACTIONS_UNMERGED
);
290 this->ShowTab(IDC_IN_CONFLICT
);
292 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_NORMAL
);
295 this->ShowTab(IDC_CMD_LOG
);
300 if(newhash
== this->m_oldHash
)
302 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
303 this->m_InLogList
.ShowText(_T("No commits get after pull"));
304 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
308 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
309 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
311 CString oldhash
=m_oldHash
.ToString();
312 this->AddDiffFileList(&m_InChangeFileList
,&m_arInChangeList
,newhash
,oldhash
);
314 m_InLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
317 this->ShowTab(IDC_IN_LOGLIST
);
321 void CSyncDlg::FetchComplete()
323 EnableControlButton(true);
325 this->FetchOutList(true);
327 ShowTab(IDC_CMD_LOG
);
328 if( (!this->m_GitCmdStatus
) && this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
331 dlg
.m_PostButtonTexts
.Add(_T("Email &Patch..."));
332 int response
= dlg
.DoModal();
338 if(response
== IDC_REBASE_POST_BUTTON
)
340 CString cmd
, out
, err
;
341 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
343 g_Git
.FixBranchName(dlg
.m_Upstream
),
344 g_Git
.FixBranchName(dlg
.m_Branch
));
345 if(g_Git
.Run(cmd
, &out
, &err
, CP_ACP
))
347 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
351 CAppUtils::SendPatchMail(cmd
,out
);
356 void CSyncDlg::OnBnClickedButtonPush()
361 if(this->m_strURL
.IsEmpty())
363 CMessageBox::Show(NULL
,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
367 this->m_regPushButton
=this->m_ctrlPush
.GetCurrentEntry();
369 this->m_bAbort
=false;
370 this->m_GitCmdList
.clear();
372 ShowTab(IDC_CMD_LOG
);
380 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
382 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
387 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
389 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
394 switch (m_ctrlPush
.GetCurrentEntry())
397 arg
+= _T(" --tags ");
400 arg
+= _T(" --all ");
405 arg
+= _T(" --force ");
407 if(m_Gitverion
>= 0x01070203) //above 1.7.0.2
408 arg
+= _T("--progress ");
410 cmd
.Format(_T("git.exe push -v %s \"%s\" %s"),
413 g_Git
.FixBranchName(m_strLocalBranch
));
415 if (!m_strRemoteBranch
.IsEmpty())
417 cmd
+= _T(":") + m_strRemoteBranch
;
420 m_GitCmdList
.push_back(cmd
);
422 m_CurrentCmd
= GIT_COMMAND_PUSH
;
424 if(this->m_bAutoLoadPuttyKey
)
426 CAppUtils::LaunchPAgent(NULL
,&this->m_strURL
);
429 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
432 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
436 m_pThread
->m_bAutoDelete
= TRUE
;
437 m_pThread
->ResumeThread();
441 void CSyncDlg::OnBnClickedButtonApply()
444 oldhash
=g_Git
.GetHash(_T("HEAD"));
449 if(dlg
.DoModal() == IDOK
)
452 for(int i
=0;i
<dlg
.m_PathList
.GetCount();i
++)
454 cmd
.Format(_T("git.exe am \"%s\""),dlg
.m_PathList
[i
].GetGitPathString());
456 if(g_Git
.Run(cmd
,&output
,CP_ACP
))
458 CMessageBox::Show(NULL
,output
,_T("TortoiseGit"),MB_OK
);
463 this->m_ctrlCmdOut
.SetSel(-1,-1);
464 this->m_ctrlCmdOut
.ReplaceSel(cmd
+_T("\n"));
465 this->m_ctrlCmdOut
.SetSel(-1,-1);
466 this->m_ctrlCmdOut
.ReplaceSel(output
);
469 CString newhash
=g_Git
.GetHash(_T("HEAD"));
471 this->m_InLogList
.Clear();
472 this->m_InChangeFileList
.Clear();
474 if(newhash
== oldhash
)
476 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
477 this->m_InLogList
.ShowText(_T("No commits get from patch"));
478 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
483 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,true);
484 this->m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,true);
486 this->AddDiffFileList(&m_InChangeFileList
,&m_arInChangeList
,newhash
,oldhash
);
487 m_InLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
490 this->FetchOutList(true);
493 this->m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,true);
497 this->ShowTab(IDC_CMD_LOG
);
501 this->ShowTab(IDC_IN_LOGLIST
);
506 void CSyncDlg::OnBnClickedButtonEmail()
508 CString cmd
, out
, err
;
510 this->m_strLocalBranch
= this->m_ctrlLocalBranch
.GetString();
511 this->m_ctrlRemoteBranch
.GetWindowText(this->m_strRemoteBranch
);
512 this->m_ctrlURL
.GetWindowText(this->m_strURL
);
513 m_strURL
=m_strURL
.Trim();
514 m_strRemoteBranch
=m_strRemoteBranch
.Trim();
516 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
518 m_strURL
+_T('/')+m_strRemoteBranch
,g_Git
.FixBranchName(m_strLocalBranch
));
520 if (g_Git
.Run(cmd
, &out
, &err
, CP_ACP
))
522 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
526 CAppUtils::SendPatchMail(cmd
,out
);
529 void CSyncDlg::ShowProgressCtrl(bool bShow
)
531 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
532 this->m_ctrlAnimate
.ShowWindow(b
);
533 this->m_ctrlProgress
.ShowWindow(b
);
534 this->m_ctrlAnimate
.Open(IDR_DOWNLOAD
);
536 this->m_ctrlAnimate
.Play(0,-1,-1);
538 this->m_ctrlAnimate
.Stop();
540 void CSyncDlg::ShowInputCtrl(bool bShow
)
542 int b
=bShow
?SW_NORMAL
:SW_HIDE
;
543 this->m_ctrlURL
.ShowWindow(b
);
544 this->m_ctrlLocalBranch
.ShowWindow(b
);
545 this->m_ctrlRemoteBranch
.ShowWindow(b
);
546 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH
)->ShowWindow(b
);
547 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH
)->ShowWindow(b
);
548 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH
)->ShowWindow(b
);
549 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH
)->ShowWindow(b
);
550 this->GetDlgItem(IDC_BUTTON_MANAGE
)->ShowWindow(b
);
551 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->ShowWindow(b
);
552 this->GetDlgItem(IDC_CHECK_FORCE
)->ShowWindow(b
);
553 this->GetDlgItem(IDC_STATIC_REMOTE_URL
)->ShowWindow(b
);
555 BOOL
CSyncDlg::OnInitDialog()
557 CResizableStandAloneDialog::OnInitDialog();
558 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
560 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
561 // do this, Explorer would be unable to send that message to our window if we
562 // were running elevated. It's OK to make the call all the time, since if we're
563 // not elevated, this is a no-op.
564 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
565 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
566 HMODULE hUser
= ::LoadLibrary(_T("user32.dll"));
569 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
570 if (pfnChangeWindowMessageFilterEx
)
572 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
576 m_pTaskbarList
.Release();
577 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
579 this->GetDlgItem(IDC_CHECK_PUTTY_KEY
)->EnableWindow(CAppUtils::IsSSHPutty());
582 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
583 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
584 this->m_ctrlAnimate.Play(0,-1,-1);
587 // ------------------ Create Tabctrl -----------
588 CWnd
*pwnd
=this->GetDlgItem(IDC_BUTTON_TABCTRL
);
590 pwnd
->GetWindowRect(&rectDummy
);
591 this->ScreenToClient(rectDummy
);
593 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_SYNC_TAB
))
595 TRACE0("Failed to create output tab window\n");
596 return FALSE
; // fail to create
598 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
600 // -------------Create Command Log Ctrl ---------
602 dwStyle
= ES_MULTILINE
| ES_READONLY
| WS_CHILD
| WS_VISIBLE
| ES_AUTOHSCROLL
| ES_AUTOVSCROLL
|WS_VSCROLL
;
604 if( !m_ctrlCmdOut
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_CMD_LOG
))
606 TRACE0("Failed to create Log commits window\n");
607 return FALSE
; // fail to create
611 memset(&m_Format
, 0, sizeof(CHARFORMAT
));
612 m_Format
.cbSize
= sizeof(CHARFORMAT
);
613 m_Format
.dwMask
= CFM_FACE
| CFM_BOLD
;
614 wcsncpy(m_Format
.szFaceName
, L
"Courier New", LF_FACESIZE
- 1);
615 m_ctrlCmdOut
.SetDefaultCharFormat(m_Format
);
617 m_ctrlTabCtrl
.InsertTab(&m_ctrlCmdOut
,_T("Log"),-1);
619 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
621 //---------- Create in coming list ctrl -----------
622 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
624 if( !m_InLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_LOGLIST
))
626 TRACE0("Failed to create output commits window\n");
627 return FALSE
; // fail to create
630 m_ctrlTabCtrl
.InsertTab(&m_InLogList
,_T("In Commits"),-1);
632 m_InLogList
.m_ColumnRegKey
=_T("SyncIn");
633 m_InLogList
.InsertGitColumn();
635 //----------- Create In Change file list -----------
636 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
638 if( !m_InChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CHANGELIST
))
640 TRACE0("Failed to create output change files window\n");
641 return FALSE
; // fail to create
643 m_ctrlTabCtrl
.InsertTab(&m_InChangeFileList
,_T("In ChangeList"),-1);
645 m_InChangeFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("OutSyncDlg"),
646 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO
)|
647 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2
)),false);
650 //---------- Create Conflict List Ctrl -----------------
651 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
653 if( !m_ConflictFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_IN_CONFLICT
))
655 TRACE0("Failed to create output change files window\n");
656 return FALSE
; // fail to create
658 m_ctrlTabCtrl
.InsertTab(&m_ConflictFileList
,_T("Conflict"),-1);
660 m_ConflictFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("OutSyncDlg"),
661 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO
)|
662 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2
)|
663 GITSLC_POPCONFLICT
|GITSLC_POPRESOLVE
),false);
666 //---------- Create Commit Out List Ctrl---------------
668 dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| LVS_OWNERDATA
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;;
670 if( !m_OutLogList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_LOGLIST
))
672 TRACE0("Failed to create output commits window\n");
673 return FALSE
; // fail to create
677 m_ctrlTabCtrl
.InsertTab(&m_OutLogList
,_T("Out Commits"),-1);
679 m_OutLogList
.m_ColumnRegKey
= _T("SyncOut");
680 m_OutLogList
.InsertGitColumn();
682 //------------- Create Change File List Control ----------------
684 dwStyle
= LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
686 if( !m_OutChangeFileList
.Create(dwStyle
,rectDummy
,&m_ctrlTabCtrl
,IDC_OUT_CHANGELIST
))
688 TRACE0("Failed to create output change files window\n");
689 return FALSE
; // fail to create
691 m_ctrlTabCtrl
.InsertTab(&m_OutChangeFileList
,_T("Out ChangeList"),-1);
693 m_OutChangeFileList
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("OutSyncDlg"),
694 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO
)|
695 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2
)),false);
697 this->m_tooltips
.Create(this);
699 AddAnchor(IDC_SYNC_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
701 AddAnchor(IDC_GROUP_INFO
,TOP_LEFT
,TOP_RIGHT
);
702 AddAnchor(IDC_COMBOBOXEX_URL
,TOP_LEFT
,TOP_RIGHT
);
703 AddAnchor(IDC_BUTTON_MANAGE
,TOP_RIGHT
);
704 AddAnchor(IDC_BUTTON_PULL
,BOTTOM_LEFT
);
705 AddAnchor(IDC_BUTTON_PUSH
,BOTTOM_LEFT
);
706 AddAnchor(IDC_BUTTON_SUBMODULE
,BOTTOM_LEFT
);
707 AddAnchor(IDC_BUTTON_APPLY
,BOTTOM_RIGHT
);
708 AddAnchor(IDC_BUTTON_EMAIL
,BOTTOM_RIGHT
);
709 AddAnchor(IDC_PROGRESS_SYNC
,TOP_LEFT
,TOP_RIGHT
);
710 AddAnchor(IDOK
,BOTTOM_RIGHT
);
711 AddAnchor(IDHELP
,BOTTOM_RIGHT
);
712 AddAnchor(IDC_STATIC_STATUS
,BOTTOM_LEFT
);
713 AddAnchor(IDC_ANIMATE_SYNC
,TOP_LEFT
);
714 AddAnchor(IDC_BUTTON_COMMIT
,BOTTOM_LEFT
);
716 BRANCH_COMBOX_ADD_ANCHOR();
718 this->GetDlgItem(IDC_BUTTON_COMMIT
)->ShowWindow(SW_HIDE
);
720 CString WorkingDir
=g_Git
.m_CurrentDir
;
721 WorkingDir
.Replace(_T(':'),_T('_'));
722 m_RegKeyRemoteBranch
= CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir
;
725 this->AddOthersToAnchor();
727 this->m_ctrlPush
.AddEntry(CString(_T("Pus&h")));
728 this->m_ctrlPush
.AddEntry(CString(_T("Push ta&gs")));
729 ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));
731 this->m_ctrlPull
.AddEntry(CString(_T("&Pull")));
732 this->m_ctrlPull
.AddEntry(CString(_T("Fetc&h")));
733 this->m_ctrlPull
.AddEntry(CString(_T("Fetch&&Re&base")));
734 this->m_ctrlPull
.AddEntry(CString(_T("Remote Update")));
736 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Update")));
737 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Init")));
738 this->m_ctrlSubmodule
.AddEntry(CString(_T("Submodule Sync")));
740 WorkingDir
.Replace(_T(':'),_T('_'));
743 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir
);
745 this->m_regPullButton
= CRegDWORD(regkey
+_T("\\Pull"),0);
746 this->m_regPushButton
= CRegDWORD(regkey
+_T("\\Push"),0);
747 this->m_regSubmoduleButton
= CRegDWORD(regkey
+_T("\\Submodule"));
748 this->m_regAutoLoadPutty
= CRegDWORD(regkey
+ _T("\\AutoLoadPutty"), CAppUtils::IsSSHPutty());
751 this->m_bAutoLoadPuttyKey
= m_regAutoLoadPutty
;
752 if(!CAppUtils::IsSSHPutty())
753 m_bAutoLoadPuttyKey
= false;
754 this->UpdateData(FALSE
);
756 this->m_ctrlPull
.SetCurrentEntry(this->m_regPullButton
);
757 this->m_ctrlPush
.SetCurrentEntry(this->m_regPushButton
);
758 this->m_ctrlSubmodule
.SetCurrentEntry(this->m_regSubmoduleButton
);
760 CString sWindowTitle
;
761 GetWindowText(sWindowTitle
);
762 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
764 EnableSaveRestore(_T("SyncDlg"));
766 this->m_ctrlURL
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir
, _T("url"));
770 if(!g_Git
.GetRemoteList(list
))
772 for(unsigned int i
=0;i
<list
.size();i
++)
774 m_ctrlURL
.AddString(list
[i
]);
777 m_ctrlURL
.SetCurSel(0);
778 m_ctrlRemoteBranch
.SetCurSel(0);
779 m_ctrlURL
.SetURLHistory(true);
781 this->LoadBranchInfo();
783 this->m_bInited
=true;
786 m_ctrlTabCtrl
.ShowTab(IDC_CMD_LOG
-1,false);
787 m_ctrlTabCtrl
.ShowTab(IDC_IN_LOGLIST
-1,false);
788 m_ctrlTabCtrl
.ShowTab(IDC_IN_CHANGELIST
-1,false);
789 m_ctrlTabCtrl
.ShowTab(IDC_IN_CONFLICT
-1,false);
791 m_ctrlRemoteBranch
.m_bWantReturn
= TRUE
;
792 m_ctrlURL
.m_bWantReturn
= TRUE
;
794 this->m_Gitverion
= CAppUtils::GetMsysgitVersion();
796 return TRUE
; // return TRUE unless you set the focus to a control
797 // EXCEPTION: OCX Property Pages should return FALSE
800 void CSyncDlg::OnBnClickedButtonManage()
802 CAppUtils::LaunchRemoteSetting();
806 void CSyncDlg::Refresh()
808 theApp
.DoWaitCursor(1);
813 this->m_ctrlLocalBranch
.GetWindowText(local
);
814 this->m_ctrlRemoteBranch
.GetWindowText(remote
);
815 this->m_ctrlURL
.GetWindowText(url
);
817 this->LoadBranchInfo();
819 this->m_ctrlLocalBranch
.AddString(local
);
820 this->m_ctrlRemoteBranch
.AddString(remote
);
821 this->m_ctrlURL
.AddString(url
);
823 m_OutLogList
.ShowText(_T("Refresh ..."));
824 this->FetchOutList(true);
825 theApp
.DoWaitCursor(-1);
828 BOOL
CSyncDlg::PreTranslateMessage(MSG
* pMsg
)
830 if (pMsg
->message
== WM_KEYDOWN
)
832 switch (pMsg
->wParam
)
838 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
843 /* Avoid TAB control destroy but dialog exist*/
848 ::GetClassName(pMsg
->hwnd
,buff
,128);
850 if(_tcsnicmp(buff
,_T("RichEdit20W"),128)==0)
852 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
858 m_tooltips
.RelayEvent(pMsg
);
859 return __super::PreTranslateMessage(pMsg
);
861 void CSyncDlg::FetchOutList(bool force
)
865 m_OutChangeFileList
.Clear();
866 this->m_OutLogList
.Clear();
869 this->m_ctrlURL
.GetWindowText(remote
);
870 CString remotebranch
;
871 this->m_ctrlRemoteBranch
.GetWindowText(remotebranch
);
872 remotebranch
=remote
+_T("/")+remotebranch
;
877 str
=_T("Don't know what will push because you enter URL");
878 m_OutLogList
.ShowText(str
);
879 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
880 m_OutLocalBranch
.Empty();
881 m_OutRemoteBranch
.Empty();
883 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
887 else if(g_Git
.GetHash(remotebranch
).IsEmpty())
890 str
.Format(_T("Don't know what will push because unknown \"%s\""),remotebranch
);
891 m_OutLogList
.ShowText(str
);
892 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
893 m_OutLocalBranch
.Empty();
894 m_OutRemoteBranch
.Empty();
896 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
902 localbranch
=this->m_ctrlLocalBranch
.GetString();
904 if(localbranch
!= m_OutLocalBranch
|| m_OutRemoteBranch
!= remotebranch
|| force
)
906 m_OutLogList
.ClearText();
907 m_OutLogList
.FillGitLog(NULL
,CGit:: LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
,
908 &remotebranch
,&localbranch
);
911 if(m_OutLogList
.GetItemCount() == 0)
913 str
.Format(_T("No commits ahead \"%s\""),remotebranch
);
914 m_OutLogList
.ShowText(str
);
915 this->m_ctrlStatus
.SetWindowText(str
);
916 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,FALSE
);
917 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(FALSE
);
921 str
.Format(_T("%d commits ahead \"%s\""),m_OutLogList
.GetItemCount(),remotebranch
);
922 this->m_ctrlStatus
.SetWindowText(str
);
924 AddDiffFileList(&m_OutChangeFileList
,&m_arOutChangeList
,localbranch
,remotebranch
);
926 this->m_ctrlTabCtrl
.ShowTab(m_OutChangeFileList
.GetDlgCtrlID()-1,TRUE
);
927 this->GetDlgItem(IDC_BUTTON_EMAIL
)->EnableWindow(TRUE
);
930 this->m_OutLocalBranch
=localbranch
;
931 this->m_OutRemoteBranch
=remotebranch
;
936 bool CSyncDlg::IsURL()
939 this->m_ctrlURL
.GetWindowText(str
);
940 if(str
.Find(_T('\\'))>=0 || str
.Find(_T('/'))>=0)
945 void CSyncDlg::OnCbnEditchangeComboboxex()
947 SetTimer(IDT_INPUT
, 1000, NULL
);
948 this->m_OutLogList
.ShowText(_T("Wait for input"));
950 //this->FetchOutList();
953 UINT
CSyncDlg::ProgressThread()
955 m_GitCmdStatus
=CProgressDlg::RunCmdList(this,m_GitCmdList
,true,NULL
,&this->m_bAbort
);
956 InterlockedExchange(&m_bBlock
, FALSE
);
961 LRESULT
CSyncDlg::OnProgressUpdateUI(WPARAM wParam
,LPARAM lParam
)
963 if(wParam
== MSG_PROGRESSDLG_START
)
965 m_ctrlAnimate
.Play(0,-1,-1);
966 this->m_ctrlProgress
.SetPos(0);
969 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
970 m_pTaskbarList
->SetProgressValue(m_hWnd
, 0, 100);
974 if(wParam
== MSG_PROGRESSDLG_END
|| wParam
== MSG_PROGRESSDLG_FAILED
)
977 m_ctrlAnimate
.Stop();
978 m_ctrlProgress
.SetPos(100);
979 //this->DialogEnableWindow(IDOK,TRUE);
981 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
983 //if(wParam == MSG_PROGRESSDLG_END)
984 if(this->m_CurrentCmd
== GIT_COMMAND_PUSH
)
989 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
992 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
997 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
999 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1005 EnableControlButton(true);
1007 this->FetchOutList(true);
1009 if(this->m_CurrentCmd
== GIT_COMMAND_PULL
)
1013 if(this->m_CurrentCmd
== GIT_COMMAND_FETCH
|| this->m_CurrentCmd
== GIT_COMMAND_FETCHANDREBASE
)
1017 if(this->m_CurrentCmd
== GIT_COMMAND_SUBMODULE
)
1019 //this->m_ctrlCmdOut.SetSel(-1,-1);
1020 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
1021 //this->m_ctrlCmdOut.SetSel(-1,-1);
1022 EnableControlButton(true);
1025 if(this->m_CurrentCmd
== GIT_COMMAND_REMOTE
)
1027 this->FetchOutList(true);
1028 EnableControlButton(true);
1034 ParserCmdOutput((char)lParam
);
1040 void CSyncDlg::ParserCmdOutput(char ch
)
1042 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut
,m_ctrlProgress
,m_hWnd
,m_pTaskbarList
,m_LogText
,ch
);
1044 void CSyncDlg::OnBnClickedButtonCommit()
1046 CString proc
=CPathUtils::GetAppDirectory();
1047 proc
+= _T("TortoiseProc.exe /command:commit");
1048 proc
+= _T(" /path:\"");
1049 proc
+= g_Git
.m_CurrentDir
;
1051 CAppUtils::LaunchApplication(proc
,IDS_ERROR_CANNON_FIND_TORTOISEPROC
,false);
1054 void CSyncDlg::OnOK()
1058 m_ctrlURL
.SaveHistory();
1060 m_regAutoLoadPutty
= this->m_bAutoLoadPuttyKey
;
1064 void CSyncDlg::OnBnClickedButtonSubmodule()
1069 this->m_regSubmoduleButton
= this->m_ctrlSubmodule
.GetCurrentEntry();
1071 this->SwitchToRun();
1073 this->m_bAbort
=false;
1074 this->m_GitCmdList
.clear();
1076 ShowTab(IDC_CMD_LOG
);
1080 switch (m_ctrlSubmodule
.GetCurrentEntry())
1083 cmd
=_T("git.exe submodule update --init");
1086 cmd
=_T("git.exe submodule init");
1089 cmd
=_T("git.exe submodule sync");
1093 m_GitCmdList
.push_back(cmd
);
1095 m_CurrentCmd
= GIT_COMMAND_SUBMODULE
;
1097 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1098 if (m_pThread
==NULL
)
1100 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1104 m_pThread
->m_bAutoDelete
= TRUE
;
1105 m_pThread
->ResumeThread();
1109 void CSyncDlg::OnTimer(UINT_PTR nIDEvent
)
1111 if( nIDEvent
== IDT_INPUT
)
1113 KillTimer(IDT_INPUT
);
1114 this->FetchOutList(true);
1118 LRESULT
CSyncDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1120 m_pTaskbarList
.Release();
1121 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);