1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
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 #include "CheckoutCommand.h"
22 #include "CheckoutDlg.h"
23 #include "SVNProgressDlg.h"
24 #include "BrowseFolder.h"
25 #include "MessageBox.h"
27 bool CheckoutCommand::Execute()
30 // Get the directory supplied in the command line. If there isn't
31 // one then we should use first the default checkout path
32 // specified in the settings dialog, and fall back to the current
33 // working directory instead if no such path was specified.
34 CTSVNPath checkoutDirectory
;
35 CRegString
regDefCheckoutPath(_T("Software\\TortoiseGit\\DefaultCheckoutPath"));
36 if (cmdLinePath
.IsEmpty())
38 if (CString(regDefCheckoutPath
).IsEmpty())
40 checkoutDirectory
.SetFromWin(sOrigCWD
, true);
41 DWORD len
= ::GetTempPath(0, NULL
);
42 TCHAR
* tszPath
= new TCHAR
[len
];
43 ::GetTempPath(len
, tszPath
);
44 if (_tcsncicmp(checkoutDirectory
.GetWinPath(), tszPath
, len
-2 /* \\ and \0 */) == 0)
46 // if the current directory is set to a temp directory,
47 // we don't use that but leave it empty instead.
48 checkoutDirectory
.Reset();
54 checkoutDirectory
.SetFromWin(CString(regDefCheckoutPath
));
59 checkoutDirectory
= cmdLinePath
;
63 dlg
.m_strCheckoutDirectory
= checkoutDirectory
.GetWinPathString();
64 dlg
.m_URL
= parser
.GetVal(_T("url"));
65 // if there is no url specified on the command line, check if there's one
66 // specified in the settings dialog to use as the default and use that
67 CRegString
regDefCheckoutUrl(_T("Software\\TortoiseGit\\DefaultCheckoutUrl"));
68 if (!CString(regDefCheckoutUrl
).IsEmpty())
70 // if the URL specified is a child of the default URL, we also
71 // adjust the default checkout path
73 // Url specified on command line: http://server.com/repos/project/trunk/folder
74 // Url specified as default : http://server.com/repos/project/trunk
75 // checkout path specified : c:\work\project
77 // checkout path adjusted : c:\work\project\folder
78 CTSVNPath clurl
= CTSVNPath(dlg
.m_URL
);
79 CTSVNPath defurl
= CTSVNPath(CString(regDefCheckoutUrl
));
80 if (defurl
.IsAncestorOf(clurl
))
82 // the default url is the parent of the specified url
83 if (CTSVNPath::CheckChild(CTSVNPath(CString(regDefCheckoutPath
)), CTSVNPath(dlg
.m_strCheckoutDirectory
)))
85 dlg
.m_strCheckoutDirectory
= CString(regDefCheckoutPath
) + clurl
.GetWinPathString().Mid(defurl
.GetWinPathString().GetLength());
86 dlg
.m_strCheckoutDirectory
.Replace(_T("\\\\"), _T("\\"));
89 if (dlg
.m_URL
.IsEmpty())
90 dlg
.m_URL
= regDefCheckoutUrl
;
92 if (dlg
.m_URL
.Left(5).Compare(_T("tsvn:"))==0)
94 dlg
.m_URL
= dlg
.m_URL
.Mid(5);
95 if (dlg
.m_URL
.Find('?') >= 0)
97 dlg
.Revision
= SVNRev(dlg
.m_URL
.Mid(dlg
.m_URL
.Find('?')+1));
98 dlg
.m_URL
= dlg
.m_URL
.Left(dlg
.m_URL
.Find('?'));
101 if (parser
.HasKey(_T("revision")))
103 SVNRev Rev
= SVNRev(parser
.GetVal(_T("revision")));
106 if (dlg
.m_URL
.Find('*')>=0)
108 // multiple URL's specified
109 // ask where to check them out to
110 CBrowseFolder foldbrowse
;
111 foldbrowse
.SetInfo(CString(MAKEINTRESOURCE(IDS_PROC_CHECKOUTTO
)));
112 foldbrowse
.SetCheckBoxText(CString(MAKEINTRESOURCE(IDS_PROC_CHECKOUTTOPONLY
)));
113 foldbrowse
.SetCheckBoxText2(CString(MAKEINTRESOURCE(IDS_PROC_CHECKOUTNOEXTERNALS
)));
114 foldbrowse
.m_style
= BIF_NEWDIALOGSTYLE
| BIF_RETURNONLYFSDIRS
| BIF_USENEWUI
| BIF_VALIDATE
;
115 TCHAR checkoutpath
[MAX_PATH
];
116 if (foldbrowse
.Show(hwndExplorer
, checkoutpath
, MAX_PATH
, CString(regDefCheckoutPath
))==CBrowseFolder::OK
)
118 CSVNProgressDlg progDlg
;
119 theApp
.m_pMainWnd
= &progDlg
;
120 if (parser
.HasVal(_T("closeonend")))
121 progDlg
.SetAutoClose(parser
.GetLongVal(_T("closeonend")));
122 progDlg
.SetCommand(CSVNProgressDlg::SVNProgress_Checkout
);
123 progDlg
.SetOptions(foldbrowse
.m_bCheck2
? ProgOptIgnoreExternals
: ProgOptNone
);
124 progDlg
.SetPathList(CTSVNPathList(CTSVNPath(CString(checkoutpath
))));
125 progDlg
.SetUrl(dlg
.m_URL
);
126 progDlg
.SetRevision(dlg
.Revision
);
127 progDlg
.SetDepth(foldbrowse
.m_bCheck
? svn_depth_empty
: svn_depth_infinity
);
129 bRet
= !progDlg
.DidErrorsOccur();
132 else if (dlg
.DoModal() == IDOK
)
134 checkoutDirectory
.SetFromWin(dlg
.m_strCheckoutDirectory
, true);
136 CSVNProgressDlg progDlg
;
137 theApp
.m_pMainWnd
= &progDlg
;
138 progDlg
.SetCommand(CSVNProgressDlg::SVNProgress_Checkout
);
139 if (parser
.HasVal(_T("closeonend")))
140 progDlg
.SetAutoClose(parser
.GetLongVal(_T("closeonend")));
141 progDlg
.SetOptions(dlg
.m_bNoExternals
? ProgOptIgnoreExternals
: ProgOptNone
);
142 progDlg
.SetPathList(CTSVNPathList(checkoutDirectory
));
143 progDlg
.SetUrl(dlg
.m_URL
);
144 progDlg
.SetRevision(dlg
.Revision
);
145 progDlg
.SetDepth(dlg
.m_depth
);
147 bRet
= !progDlg
.DidErrorsOccur();