Add pre and post push hook support
[TortoiseGit.git] / src / TortoiseProc / SyncDlg.cpp
blob63a3ca481132c4107506aa8897a91562a9456012
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
23 #include "stdafx.h"
24 #include "TortoiseProc.h"
25 #include "SyncDlg.h"
26 #include "progressdlg.h"
27 #include "MessageBox.h"
28 #include "ImportPatchDlg.h"
29 #include "PathUtils.h"
30 #include "RebaseDlg.h"
31 #include "hooks.h"
33 // CSyncDlg dialog
35 IMPLEMENT_DYNAMIC(CSyncDlg, CResizableStandAloneDialog)
37 CSyncDlg::CSyncDlg(CWnd* pParent /*=NULL*/)
38 : CResizableStandAloneDialog(CSyncDlg::IDD, pParent)
40 m_pTooltip=&this->m_tooltips;
41 m_bInited=false;
42 m_CmdOutCurrentPos=0;
43 m_bAutoLoadPuttyKey = CAppUtils::IsSSHPutty();
44 m_bForce=false;
45 m_bBlock = false;
48 CSyncDlg::~CSyncDlg()
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);
65 BRANCH_COMBOX_DDX;
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)
75 BRANCH_COMBOX_EVENT
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)
82 ON_WM_TIMER()
83 END_MESSAGE_MAP()
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
100 int CurrentEntry;
101 CurrentEntry = this->m_ctrlPull.GetCurrentEntry();
102 this->m_regPullButton = CurrentEntry;
105 this->m_bAbort=false;
106 this->m_GitCmdList.clear();
108 this->UpdateData();
109 UpdateCombox();
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);
118 return;
122 if(this->m_strURL.IsEmpty())
124 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
125 return;
128 if(this->m_bAutoLoadPuttyKey)
130 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
133 this->SwitchToRun();
135 CString force;
136 if(this->m_bForce)
137 force = _T(" --force ");
139 CString cmd;
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);
149 ///Pull
150 if(CurrentEntry == 0) //Pull
152 cmd.Format(_T("git.exe pull %s \"%s\" %s"),
153 force,
154 m_strURL,
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);
161 if (m_pThread==NULL)
163 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
165 else
167 m_pThread->m_bAutoDelete = TRUE;
168 m_pThread->ResumeThread();
173 ///Fetch
174 if(CurrentEntry == 1 || CurrentEntry ==2 ) //Fetch
176 CString remotebranch;
177 if(this->IsURL() || m_strRemoteBranch.IsEmpty())
179 remotebranch=this->m_strRemoteBranch;
181 }else
184 remotebranch.Format(_T("remotes/%s/%s"),
185 m_strURL,m_strRemoteBranch);
186 if(g_Git.GetHash(remotebranch).IsEmpty())
187 remotebranch=m_strRemoteBranch;
188 else
189 remotebranch=m_strRemoteBranch+_T(":")+remotebranch;
192 cmd.Format(_T("git.exe fetch %s \"%s\" %s"),
193 force,
194 m_strURL,
195 remotebranch);
197 if(CurrentEntry == 1)
198 m_CurrentCmd = GIT_COMMAND_FETCH;
199 else
200 m_CurrentCmd = GIT_COMMAND_FETCHANDREBASE;
201 m_GitCmdList.push_back(cmd);
203 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
204 if (m_pThread==NULL)
206 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
208 else
210 m_pThread->m_bAutoDelete = TRUE;
211 m_pThread->ResumeThread();
215 ///Remote Update
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);
225 if (m_pThread==NULL)
227 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
228 InterlockedExchange(&m_bBlock, FALSE);
230 else
232 m_pThread->m_bAutoDelete = TRUE;
233 m_pThread->ResumeThread();
239 void CSyncDlg::PullComplete()
241 EnableControlButton(true);
242 SwitchToInput();
243 this->FetchOutList(true);
245 CString newhash;
246 newhash = g_Git.GetHash(CString(_T("HEAD")));
250 if( this ->m_GitCmdStatus )
252 CTGitPathList list;
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);
259 return;
262 if(list.GetCount()>0)
264 this->m_ConflictFileList.Clear();
265 CTGitPathList list;
266 CTGitPath path;
267 list.AddPath(path);
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);
277 else
278 this->ShowTab(IDC_CMD_LOG);
280 }else
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);
288 else
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);
305 SwitchToInput();
306 this->FetchOutList(true);
308 ShowTab(IDC_CMD_LOG);
309 if( (!this->m_GitCmdStatus) && this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
311 CRebaseDlg dlg;
312 dlg.m_PostButtonTexts.Add(_T("Email &Patch..."));
313 int response = dlg.DoModal();
314 if(response == IDOK)
316 return ;
319 if(response == IDC_REBASE_POST_BUTTON)
321 CString cmd,out;
322 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
323 g_Git.m_CurrentDir,
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);
328 return ;
331 CAppUtils::SendPatchMail(cmd,out);
336 void CSyncDlg::OnBnClickedButtonPush()
338 // TODO: Add your control notification handler code here
339 this->UpdateData();
340 UpdateCombox();
342 if(this->m_strURL.IsEmpty())
344 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
345 return;
348 this->m_regPushButton=this->m_ctrlPush.GetCurrentEntry();
349 this->SwitchToRun();
350 this->m_bAbort=false;
351 this->m_GitCmdList.clear();
353 ShowTab(IDC_CMD_LOG);
355 CString cmd;
356 CString tags;
357 CString force;
358 CString all;
360 CString error;
361 DWORD exitcode;
362 CTGitPathList list;
363 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
365 if (CHooks::Instance().PrePush(list,exitcode, error))
367 if (exitcode)
369 CString temp;
370 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
371 //ReportError(temp);
372 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
373 return ;
378 switch (m_ctrlPush.GetCurrentEntry())
380 case 1:
381 tags = _T(" --tags ");
382 break;
383 case 2:
384 all = _T(" --all ");
385 break;
388 if(this->m_bForce)
389 force = _T(" --force ");
391 cmd.Format(_T("git.exe push %s %s %s \"%s\" %s"),
392 tags,force,all,
393 m_strURL,
394 m_strLocalBranch);
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);
411 if (m_pThread==NULL)
413 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
415 else
417 m_pThread->m_bAutoDelete = TRUE;
418 m_pThread->ResumeThread();
423 void CSyncDlg::OnBnClickedButtonApply()
425 // TODO: Add your control notification handler code here
426 CString oldhash;
427 oldhash=g_Git.GetHash(CString(_T("HEAD")));
429 CImportPatchDlg dlg;
430 CString cmd,output;
432 if(dlg.DoModal() == IDOK)
434 int err=0;
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);
443 err=1;
444 break;
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);
464 }else
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,
471 &oldhash,&newhash);
473 this->FetchOutList(true);
477 this->m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,true);
479 if(err)
481 this->ShowTab(IDC_CMD_LOG);
483 }else
485 this->ShowTab(IDC_IN_LOGLIST);
490 void CSyncDlg::OnBnClickedButtonEmail()
492 // TODO: Add your control notification handler code here
493 CString cmd,out;
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"),
502 g_Git.m_CurrentDir,
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);
508 return ;
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);
520 if(b == SW_NORMAL)
521 this->m_ctrlAnimate.Play(0,-1,-1);
522 else
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);
556 CRect rectDummy;
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 ---------
568 DWORD dwStyle;
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('_'));
703 CString regkey ;
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());
711 this->UpdateData();
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);
721 CString str;
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"));
730 STRING_VECTOR list;
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;
746 FetchOutList();
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);
771 CString local;
772 CString remote;
773 CString url;
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)
798 case VK_F5:
800 if (m_bBlock)
801 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
802 Refresh();
804 break;
806 /* Avoid TAB control destroy but dialog exist*/
807 case VK_ESCAPE:
808 case VK_CANCEL:
810 TCHAR buff[128];
811 ::GetClassName(pMsg->hwnd,buff,128);
813 if(_tcsnicmp(buff,_T("RichEdit20W"),128)==0)
815 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
816 return TRUE;
821 m_tooltips.RelayEvent(pMsg);
822 return __super::PreTranslateMessage(pMsg);
824 void CSyncDlg::FetchOutList(bool force)
826 if(!m_bInited)
827 return;
828 m_OutChangeFileList.Clear();
829 this->m_OutLogList.Clear();
831 CString remote;
832 this->m_ctrlURL.GetWindowText(remote);
833 CString remotebranch;
834 this->m_ctrlRemoteBranch.GetWindowText(remotebranch);
835 remotebranch=remote+_T("/")+remotebranch;
837 if(IsURL())
839 CString str;
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);
847 return ;
849 }else if(g_Git.GetHash(remotebranch).GetLength()<40)
851 CString str;
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);
859 return ;
861 else
863 CString localbranch;
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);
872 CString str;
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);
881 else
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()
900 CString str;
901 this->m_ctrlURL.GetWindowText(str);
902 if(str.Find(_T('\\'))>=0 || str.Find(_T('/'))>=0)
903 return true;
904 else
905 return false;
907 void CSyncDlg::OnCbenEndeditComboboxexUrl(NMHDR *pNMHDR, LRESULT *pResult)
909 // TODO: Add your control notification handler code here
910 *pResult = 0;
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);
926 return 0;
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)
940 //m_bDone = true;
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 )
948 if(!m_GitCmdStatus)
950 CTGitPathList list;
951 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
952 DWORD exitcode;
953 CString error;
954 if (CHooks::Instance().PostPush(list,exitcode, error))
956 if (exitcode)
958 CString temp;
959 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
960 //ReportError(temp);
961 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
962 return false;
967 EnableControlButton(true);
968 SwitchToInput();
969 this->FetchOutList(true);
971 if(this->m_CurrentCmd == GIT_COMMAND_PULL )
973 PullComplete();
975 if(this->m_CurrentCmd == GIT_COMMAND_FETCH || this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
977 FetchComplete();
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);
985 SwitchToInput();
987 if(this->m_CurrentCmd == GIT_COMMAND_REMOTE)
989 this->FetchOutList(true);
990 EnableControlButton(true);
991 SwitchToInput();
995 if(lParam != 0)
996 ParserCmdOutput((TCHAR)lParam);
998 return 0;
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
1020 UpdateCombox();
1021 this->UpdateData();
1022 m_ctrlURL.SaveHistory();
1023 SaveHistory();
1024 m_regAutoLoadPutty = this->m_bAutoLoadPuttyKey;
1025 __super::OnOK();
1028 void CSyncDlg::OnBnClickedButtonSubmodule()
1030 // TODO: Add your control notification handler code here
1031 // TODO: Add your control notification handler code here
1032 this->UpdateData();
1033 UpdateCombox();
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);
1044 CString cmd;
1046 switch (m_ctrlSubmodule.GetCurrentEntry())
1048 case 0:
1049 cmd=_T("git.exe submodule update");
1050 break;
1051 case 1:
1052 cmd=_T("git.exe submodule init");
1053 break;
1054 case 2:
1055 cmd=_T("git.exe submodule sync");
1056 break;
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)));
1069 else
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);