1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2007-2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "CheckoutCommand.h"
\r
22 #include "CheckoutDlg.h"
\r
23 #include "SVNProgressDlg.h"
\r
24 #include "BrowseFolder.h"
\r
25 #include "MessageBox.h"
\r
27 bool CheckoutCommand::Execute()
\r
30 // Get the directory supplied in the command line. If there isn't
\r
31 // one then we should use first the default checkout path
\r
32 // specified in the settings dialog, and fall back to the current
\r
33 // working directory instead if no such path was specified.
\r
34 CTSVNPath checkoutDirectory;
\r
35 CRegString regDefCheckoutPath(_T("Software\\TortoiseGit\\DefaultCheckoutPath"));
\r
36 if (cmdLinePath.IsEmpty())
\r
38 if (CString(regDefCheckoutPath).IsEmpty())
\r
40 checkoutDirectory.SetFromWin(sOrigCWD, true);
\r
41 DWORD len = ::GetTempPath(0, NULL);
\r
42 TCHAR * tszPath = new TCHAR[len];
\r
43 ::GetTempPath(len, tszPath);
\r
44 if (_tcsncicmp(checkoutDirectory.GetWinPath(), tszPath, len-2 /* \\ and \0 */) == 0)
\r
46 // if the current directory is set to a temp directory,
\r
47 // we don't use that but leave it empty instead.
\r
48 checkoutDirectory.Reset();
\r
54 checkoutDirectory.SetFromWin(CString(regDefCheckoutPath));
\r
59 checkoutDirectory = cmdLinePath;
\r
63 dlg.m_strCheckoutDirectory = checkoutDirectory.GetWinPathString();
\r
64 dlg.m_URL = parser.GetVal(_T("url"));
\r
65 // if there is no url specified on the command line, check if there's one
\r
66 // specified in the settings dialog to use as the default and use that
\r
67 CRegString regDefCheckoutUrl(_T("Software\\TortoiseGit\\DefaultCheckoutUrl"));
\r
68 if (!CString(regDefCheckoutUrl).IsEmpty())
\r
70 // if the URL specified is a child of the default URL, we also
\r
71 // adjust the default checkout path
\r
73 // Url specified on command line: http://server.com/repos/project/trunk/folder
\r
74 // Url specified as default : http://server.com/repos/project/trunk
\r
75 // checkout path specified : c:\work\project
\r
77 // checkout path adjusted : c:\work\project\folder
\r
78 CTSVNPath clurl = CTSVNPath(dlg.m_URL);
\r
79 CTSVNPath defurl = CTSVNPath(CString(regDefCheckoutUrl));
\r
80 if (defurl.IsAncestorOf(clurl))
\r
82 // the default url is the parent of the specified url
\r
83 if (CTSVNPath::CheckChild(CTSVNPath(CString(regDefCheckoutPath)), CTSVNPath(dlg.m_strCheckoutDirectory)))
\r
85 dlg.m_strCheckoutDirectory = CString(regDefCheckoutPath) + clurl.GetWinPathString().Mid(defurl.GetWinPathString().GetLength());
\r
86 dlg.m_strCheckoutDirectory.Replace(_T("\\\\"), _T("\\"));
\r
89 if (dlg.m_URL.IsEmpty())
\r
90 dlg.m_URL = regDefCheckoutUrl;
\r
92 if (dlg.m_URL.Left(5).Compare(_T("tsvn:"))==0)
\r
94 dlg.m_URL = dlg.m_URL.Mid(5);
\r
95 if (dlg.m_URL.Find('?') >= 0)
\r
97 dlg.Revision = SVNRev(dlg.m_URL.Mid(dlg.m_URL.Find('?')+1));
\r
98 dlg.m_URL = dlg.m_URL.Left(dlg.m_URL.Find('?'));
\r
101 if (parser.HasKey(_T("revision")))
\r
103 SVNRev Rev = SVNRev(parser.GetVal(_T("revision")));
\r
104 dlg.Revision = Rev;
\r
106 if (dlg.m_URL.Find('*')>=0)
\r
108 // multiple URL's specified
\r
109 // ask where to check them out to
\r
110 CBrowseFolder foldbrowse;
\r
111 foldbrowse.SetInfo(CString(MAKEINTRESOURCE(IDS_PROC_CHECKOUTTO)));
\r
112 foldbrowse.SetCheckBoxText(CString(MAKEINTRESOURCE(IDS_PROC_CHECKOUTTOPONLY)));
\r
113 foldbrowse.SetCheckBoxText2(CString(MAKEINTRESOURCE(IDS_PROC_CHECKOUTNOEXTERNALS)));
\r
114 foldbrowse.m_style = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_USENEWUI | BIF_VALIDATE;
\r
115 TCHAR checkoutpath[MAX_PATH];
\r
116 if (foldbrowse.Show(hwndExplorer, checkoutpath, MAX_PATH, CString(regDefCheckoutPath))==CBrowseFolder::OK)
\r
118 CSVNProgressDlg progDlg;
\r
119 theApp.m_pMainWnd = &progDlg;
\r
120 if (parser.HasVal(_T("closeonend")))
\r
121 progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
\r
122 progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Checkout);
\r
123 progDlg.SetOptions(foldbrowse.m_bCheck2 ? ProgOptIgnoreExternals : ProgOptNone);
\r
124 progDlg.SetPathList(CTSVNPathList(CTSVNPath(CString(checkoutpath))));
\r
125 progDlg.SetUrl(dlg.m_URL);
\r
126 progDlg.SetRevision(dlg.Revision);
\r
127 progDlg.SetDepth(foldbrowse.m_bCheck ? svn_depth_empty : svn_depth_infinity);
\r
129 bRet = !progDlg.DidErrorsOccur();
\r
132 else if (dlg.DoModal() == IDOK)
\r
134 checkoutDirectory.SetFromWin(dlg.m_strCheckoutDirectory, true);
\r
136 CSVNProgressDlg progDlg;
\r
137 theApp.m_pMainWnd = &progDlg;
\r
138 progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Checkout);
\r
139 if (parser.HasVal(_T("closeonend")))
\r
140 progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
\r
141 progDlg.SetOptions(dlg.m_bNoExternals ? ProgOptIgnoreExternals : ProgOptNone);
\r
142 progDlg.SetPathList(CTSVNPathList(checkoutDirectory));
\r
143 progDlg.SetUrl(dlg.m_URL);
\r
144 progDlg.SetRevision(dlg.Revision);
\r
145 progDlg.SetDepth(dlg.m_depth);
\r
147 bRet = !progDlg.DidErrorsOccur();
\r