我正在寻找一种克隆git存储库的方法,例如从GitHub,并在下载的文件夹结构中包括所有者或组织。
例如,当angular-cli
从angular
当前文件夹中的组织克隆存储库时,我希望它在当前的工作目录中这样克隆它angular/angular-cli
。
我尝试使用谷歌搜索解决方案,但找不到解决方案,因为基本上所有结果都告诉我如何克隆存储库。我当然可以做到,但是我希望有一些工具可以帮助我使这一过程自动化。也许是bash或powershell脚本,甚至直接内置到git中。
编辑:与另一个问题相反,我正在寻找一种工具,该工具可根据源(例如Github)和用户/组织(例如Angular)自动将存储库放置在正确的文件夹结构中。
更新:由于我对这个旧的问答很满意,所以我想更新我的帖子。我最近开始将此脚本放入PowerShell模块(GitManagement)中,该模块可在以下位置找到:https : //github.com/totkeks/PowerShell-Modules
我自己在powershell中构建了一个解决方案。您可以通过名称和用于解析URL并为存储库构建相应路径的正则表达式配置不同的Git提供程序。
<#
.DESCRIPTION
Clone git repositories including the project/user/organization/... folder structure
#>
Param(
[parameter(Mandatory = $true)]
[String]
$Url
)
#------------------------------------------------------------------------------
# Configuration of available providers
#------------------------------------------------------------------------------
$GitProviders = @{
"Azure" = {
if ($args[0] -Match "https://(?:\w+@)?dev.azure.com/(?<Organization>\w+)/(?<Project>\w+)/_git/(?<Repository>[\w-_]+)") {
return [io.path]::Combine($Matches.Organization, $Matches.Project, $Matches.Repository)
}
}
"GitHub" = {
if ($args[0] -Match "https://github\.com/(?<UserOrOrganization>\w+)/(?<Repository>[\w-_]+)\.git") {
return [io.path]::Combine($Matches.UserOrOrganization, $Matches.Repository)
}
}
}
#------------------------------------------------------------------------------
# Find the right provider and clone the repository
#------------------------------------------------------------------------------
$Match = $GitProviders.GetEnumerator() |
Select-Object @{n = "Provider"; e = {$_.Key}}, @{n = "Path"; e = {$_.Value.invoke($Url)}} |
Where-Object { $_.Path -ne $null } |
Select-Object -First 1
if ($Match) {
Write-Host "Found match for provider: $($Match.Provider)"
if ($Global:ProjectsDir) {
$TargetDirectory = [io.path]::Combine($Global:ProjectsDir, $Match.Provider, $Match.Path)
}
else {
Write-Error "No projects directory configured. Aborting."
}
git clone $Url $TargetDirectory
}
else {
Write-Error "No match found for repository url: $Url"
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句