我的问题是我有一个客户,我们称他们为“Evil Corp”,它通过各种项目为我的公司提供大量业务,我们使用GitHub repos进行该项目。让我们以2命名为“TotallyNotPolluting”和“CoveringUpPolluting”。
我希望我的员工在克隆时默认情况下能够将“TotallyNotPolluting”存储库克隆到“EvilCorp”文件夹中。
行为:
因此,起始结构为:

E:
└── Work
    └── Repos
  • 具有起始文件夹结构:E:\Work\Repos以启动
  • 在Git Bash/GitHub桌面中/无论克隆存储库'TotallyNotPolluting'(所选位置是起始文件夹结构E:\Work\Repos)
  • 具有结尾的文件夹结构:E:\Work\Repos\EvilCorp\TotallyNotPolluting
  • 在Git Bash/GitHub桌面中/无论克隆存储库'CoveringUpPolluting'(所选位置是起始文件夹结构E:\Work\Repos)
  • 具有结尾的文件夹结构:E:\Work\Repos\EvilCorp\CoveringUpPolluting

  • 因此,最终结构为:
    E:
    └── Work
        └── Repos
            └── EvilCorp
                ├── TotallyNotPolluting
                └── CoveringUpPolluting
    
    这样,所有存储库都被组织到客户端文件夹中,而员工无需采取额外的步骤。
    这可能吗?要创建“克隆”操作,然后克隆到父目录(如果不存在)还是克隆到(如果存在)父目录?
    注意:我已经研究过使用子模块,但是我不希望包含其他存储库的存储库“EvilCorp”。克隆时我只想要文件夹。

    最佳答案

    您可以编写如下的脚本。我没有对其进行正确的测试,但这应该为您提供正确的移动方向。此shell脚本的目的是创建一个父目录,然后分别创建每个子文件夹,检查子文件夹是否为空。如果为空,则克隆存储库。该Shell脚本可以作为可执行文件分发给员工,然后在运行时将 repo 克隆到正确的位置。

    #create the directory, if it does not exist
    
    directoryName="<your directory name here>"
    mkdir -p directoryName
    repos="TotallyNotPolluting CoveringUpPolluting"
    forwardSlash="/"
    #go into directory
    pushd $directoryName
    
    
    
    for repo in $repos; do
    
        #check if directory is not present, if true, create the directory
    
        [ ! -d $repo ] && mkdir -p $repo
    
        #go into directory
    
        currentDirectory=$directoryName$forwardSlash$repo
        if [ "$(ls -A $currentDirectory)" ]; then
    
         echo "directory is not empty, skipping to clone"
        else
            pushd $directoryName$forwardSlash$repo
            git clone "git@$codeHost:$codeUser/$repo.git"
        fi
    
    done
    

    关于windows - 将多个存储库克隆到公共(public)父文件夹结构中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39518432/

    10-14 15:45
    查看更多