OSDN Git Service

Pull/Fetch Dlg: Used git config to determine default remote and remote branch. Also...
authorJohan 't Hart <johanthart@gmail.com>
Fri, 26 Jun 2009 18:59:58 +0000 (20:59 +0200)
committerJohan 't Hart <johanthart@gmail.com>
Fri, 26 Jun 2009 19:03:19 +0000 (21:03 +0200)
Also started implementing rebase option (rebase instead of merge) when pulling. Disabled this though, because I think the rebase dialog should be used for this. It needs some work.

src/Resources/TortoiseProcENG.rc
src/TortoiseProc/Commands/PullCommand.cpp
src/TortoiseProc/PullFetchDlg.cpp
src/TortoiseProc/PullFetchDlg.h
src/TortoiseProc/resource.h

index 7df8a5f..1b8630e 100644 (file)
Binary files a/src/Resources/TortoiseProcENG.rc and b/src/Resources/TortoiseProcENG.rc differ
index ddab7fe..5419e0d 100644 (file)
@@ -44,7 +44,10 @@ bool PullCommand::Execute()
                \r
                CString cmd;\r
                CString hashOld = g_Git.GetHash(L"HEAD");\r
                \r
                CString cmd;\r
                CString hashOld = g_Git.GetHash(L"HEAD");\r
-               cmd.Format(_T("git.exe pull \"%s\" %s"),url,dlg.m_RemoteBranchName);\r
+               CString cmdRebase;\r
+               if(dlg.m_bRebase)\r
+                       cmdRebase = "--rebase ";\r
+               cmd.Format(_T("git.exe pull %s\"%s\" %s"),cmdRebase, url, dlg.m_RemoteBranchName);\r
                CProgressDlg progress;\r
                progress.m_GitCmd = cmd;\r
                progress.m_bAutoCloseOnSuccess = true;\r
                CProgressDlg progress;\r
                progress.m_GitCmd = cmd;\r
                progress.m_bAutoCloseOnSuccess = true;\r
index 106297e..18073cd 100644 (file)
@@ -6,13 +6,14 @@
 #include "PullFetchDlg.h"\r
 #include "Git.h"\r
 #include "AppUtils.h"\r
 #include "PullFetchDlg.h"\r
 #include "Git.h"\r
 #include "AppUtils.h"\r
-\r
+#include "BrowseRefsDlg.h"\r
 // CPullFetchDlg dialog\r
 \r
 IMPLEMENT_DYNAMIC(CPullFetchDlg, CResizableStandAloneDialog)\r
 \r
 CPullFetchDlg::CPullFetchDlg(CWnd* pParent /*=NULL*/)\r
 // CPullFetchDlg dialog\r
 \r
 IMPLEMENT_DYNAMIC(CPullFetchDlg, CResizableStandAloneDialog)\r
 \r
 CPullFetchDlg::CPullFetchDlg(CWnd* pParent /*=NULL*/)\r
-       : CResizableStandAloneDialog(CPullFetchDlg::IDD, pParent)\r
+       : CResizableStandAloneDialog(CPullFetchDlg::IDD, pParent),\r
+         m_bRebase(false)\r
 {\r
        m_IsPull=TRUE;\r
     m_bAutoLoad = CAppUtils::IsSSHPutty();\r
 {\r
        m_IsPull=TRUE;\r
     m_bAutoLoad = CAppUtils::IsSSHPutty();\r
@@ -31,6 +32,7 @@ void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)
        DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);\r
     DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);\r
     DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);\r
        DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);\r
     DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);\r
     DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);\r
+    DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);\r
 \r
 }\r
 \r
 \r
 }\r
 \r
@@ -40,6 +42,7 @@ BEGIN_MESSAGE_MAP(CPullFetchDlg,CResizableStandAloneDialog )
        ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)\r
        ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)\r
     ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)\r
        ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)\r
        ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)\r
     ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)\r
+       ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)\r
 END_MESSAGE_MAP()\r
 \r
 BOOL CPullFetchDlg::OnInitDialog()\r
 END_MESSAGE_MAP()\r
 \r
 BOOL CPullFetchDlg::OnInitDialog()\r
@@ -54,6 +57,7 @@ BOOL CPullFetchDlg::OnInitDialog()
        AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
     AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,BOTTOM_RIGHT);\r
     AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);\r
        AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
     AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,BOTTOM_RIGHT);\r
     AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);\r
+       AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);\r
     AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);\r
        AddAnchor(IDHELP, BOTTOM_RIGHT);\r
 \r
     AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);\r
        AddAnchor(IDHELP, BOTTOM_RIGHT);\r
 \r
@@ -64,7 +68,12 @@ BOOL CPullFetchDlg::OnInitDialog()
        CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);\r
        m_Remote.EnableWindow(TRUE);\r
        m_Other.EnableWindow(FALSE);\r
        CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);\r
        m_Remote.EnableWindow(TRUE);\r
        m_Other.EnableWindow(FALSE);\r
-       m_RemoteBranch.EnableWindow(FALSE);\r
+       if(!m_IsPull)\r
+               m_RemoteBranch.EnableWindow(FALSE);\r
+\r
+//     if(!m_IsPull)\r
+               //Todo: implement rebase option sometime with rebase dialog\r
+               GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);\r
 \r
        m_Other.SetURLHistory(TRUE);\r
        m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));\r
 \r
        m_Other.SetURLHistory(TRUE);\r
        m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));\r
@@ -90,12 +99,26 @@ BOOL CPullFetchDlg::OnInitDialog()
        m_RemoteReg = remote;\r
        int sel=0;\r
 \r
        m_RemoteReg = remote;\r
        int sel=0;\r
 \r
+       //Select pull-remote from current branch\r
+       CString currentBranch = g_Git.GetSymbolicRef();\r
+       CString configName;\r
+       configName.Format(L"branch.%s.remote", currentBranch);\r
+       CString pullRemote = g_Git.GetConfigValue(configName);\r
+\r
+       //Select pull-branch from current branch\r
+       configName.Format(L"branch.%s.merge", currentBranch);\r
+       CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));\r
+       m_RemoteBranch.AddString(pullBranch);\r
+\r
+       if(pullRemote.IsEmpty())\r
+               pullRemote = remote;\r
+\r
        if(!g_Git.GetRemoteList(list))\r
        {       \r
                for(unsigned int i=0;i<list.size();i++)\r
                {\r
                        m_Remote.AddString(list[i]);\r
        if(!g_Git.GetRemoteList(list))\r
        {       \r
                for(unsigned int i=0;i<list.size();i++)\r
                {\r
                        m_Remote.AddString(list[i]);\r
-                       if(list[i] == remote)\r
+                       if(list[i] == pullRemote)\r
                                sel = i;\r
                }\r
        }\r
                                sel = i;\r
                }\r
        }\r
@@ -115,14 +138,15 @@ void CPullFetchDlg::OnBnClickedRd()
        {\r
                m_Remote.EnableWindow(TRUE);\r
                m_Other.EnableWindow(FALSE);\r
        {\r
                m_Remote.EnableWindow(TRUE);\r
                m_Other.EnableWindow(FALSE);\r
-               m_RemoteBranch.EnableWindow(FALSE);\r
-\r
+               if(!m_IsPull)\r
+                       m_RemoteBranch.EnableWindow(FALSE);\r
        }\r
        if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)\r
        {\r
                m_Remote.EnableWindow(FALSE);\r
                m_Other.EnableWindow(TRUE);;\r
        }\r
        if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)\r
        {\r
                m_Remote.EnableWindow(FALSE);\r
                m_Other.EnableWindow(TRUE);;\r
-               m_RemoteBranch.EnableWindow(TRUE);\r
+               if(!m_IsPull)\r
+                       m_RemoteBranch.EnableWindow(TRUE);\r
        }\r
        \r
 \r
        }\r
        \r
 \r
@@ -134,7 +158,10 @@ void CPullFetchDlg::OnBnClickedOk()
        if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)\r
        {\r
                m_RemoteURL=m_Remote.GetString();\r
        if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)\r
        {\r
                m_RemoteURL=m_Remote.GetString();\r
-               m_RemoteBranchName.Empty();\r
+               if(!m_IsPull)\r
+                       m_RemoteBranchName.Empty();\r
+               else\r
+                       m_RemoteBranchName=m_RemoteBranch.GetString();\r
                \r
        }\r
        if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)\r
                \r
        }\r
        if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)\r
@@ -156,3 +183,25 @@ void CPullFetchDlg::OnStnClickedRemoteManage()
     // TODO: Add your control notification handler code here\r
     CAppUtils::LaunchRemoteSetting();\r
 }\r
     // TODO: Add your control notification handler code here\r
     CAppUtils::LaunchRemoteSetting();\r
 }\r
+\r
+void CPullFetchDlg::OnBnClickedButtonBrowseRef()\r
+{\r
+       CString initialRef;\r
+       initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());\r
+       CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);\r
+       if(selectedRef.Left(13) != "refs/remotes/")\r
+               return;\r
+\r
+       selectedRef = selectedRef.Mid(13);\r
+       int ixSlash = selectedRef.Find('/');\r
+\r
+       CString remoteName   = selectedRef.Left(ixSlash);\r
+       CString remoteBranch = selectedRef.Mid(ixSlash + 1);\r
+       \r
+       int ixFound = m_Remote.FindStringExact(0, remoteName);\r
+       if(ixFound >= 0)\r
+               m_Remote.SetCurSel(ixFound);\r
+       m_RemoteBranch.AddString(remoteBranch);\r
+\r
+       CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);\r
+}\r
index 3297236..61a5428 100644 (file)
@@ -29,6 +29,7 @@ protected:
 public:\r
        BOOL        m_IsPull;\r
     BOOL        m_bAutoLoad;\r
 public:\r
        BOOL        m_IsPull;\r
     BOOL        m_bAutoLoad;\r
+       BOOL            m_bRebase;\r
     BOOL        m_bAutoLoadEnable;\r
     CHyperLink  m_RemoteManage;\r
 \r
     BOOL        m_bAutoLoadEnable;\r
     CHyperLink  m_RemoteManage;\r
 \r
@@ -37,4 +38,5 @@ public:
        CString m_RemoteURL;\r
        CString m_RemoteBranchName;\r
     afx_msg void OnStnClickedRemoteManage();\r
        CString m_RemoteURL;\r
        CString m_RemoteBranchName;\r
     afx_msg void OnStnClickedRemoteManage();\r
+       afx_msg void OnBnClickedButtonBrowseRef();\r
 };\r
 };\r
index 005da05..845fa22 100644 (file)
Binary files a/src/TortoiseProc/resource.h and b/src/TortoiseProc/resource.h differ