简体   繁体   English

cPanel主目录中的GIT回购

[英]GIT repo in cPanel Home Directory

I'm trying to ensure that a GIT web hook I've written will still be usable for a site when the GIT repo itself is the user's home directory in a cPanel server. 我试图确保当GIT回购本身是cPanel服务器中用户的主目录时,我编写的GIT Web挂钩仍可用于网站。

In prior cases I've always had the repo in a directory below the home directory, which works fine since the pull/fetch is executed in that directory and not home. 在以前的情况下,我总是将存储库放在主目录下的目录中,因为pull / fetch在该目录而不是主目录中执行,所以工作正常。

Our hook is designed to allow for other developers to be able to upload files via ftp for testing and then once tested, committed to the given repo. 我们的钩子旨在允许其他开发人员能够通过ftp上传文件进行测试,然后在测试后将其提交给指定的存储库。 When we push the changes to our repo, the web hook accounts for the untracked or changed files and deletes them or checks them out so they can be updated via GIT. 当我们将更改推送到存储库时,Web挂钩会考虑未跟踪或更改的文件并删除它们或将其检出,以便可以通过GIT更新它们。

This is part of the clients requirements and not negotiable, so I have to work around it. 这是客户要求的一部分,不能协商,因此我必须解决它。

Working on a dev version I can set up the file structure as so: 在开发版本上工作,我可以这样设置文件结构:

URL: http://dev.example.com 网址: http//dev.example.com

DIRS: DIRS:

/home
   /username
      /dev
         /.git
         /.gitignore
         /application
         /public_html

No problems since /dev contains ONLY the files we're tracking and deploying. 没问题,因为/ dev仅包含我们正在跟踪和部署的文件。

But in a live environment, the directory structure looks like: 但是在实际环境中,目录结构如下所示:

/home
   /.git
   /.gitignore
   /application
   /public_html
   ... 
   all other cpanel related user directories and files

My fetch function looks like so: 我的提取函数如下所示:

private function __fetch() {
    // change directory
    // set by searching recursively to find the .git directory
    // in this case $this->directory = home -- $this->alias = username
    chdir ($this->directory . '/' . $this->alias);

    // Fetch files for comparison
    exec("git fetch origin " . $this->branch . " 2>&1", $output);

    // Get local untracked files to delete
    exec("git status --porcelain -u | awk '/^[??]/ {print $2}'", $files);
    if (!empty($files)):
        foreach($files as $index => $file):
            unlink($this->directory . '/' . $this->alias . '/' . $file);
        endforeach;
    endif;
    unset($files);

    // Get local modified files to checkout
    exec("git diff --name-status | awk '/^[CDRMTUX]/ {print $2}'", $files);
    if (!empty($files)):
        foreach($files as $index => $file):
            exec("git checkout " . $file . " 2>&1", $error);
        endforeach;
    endif;
    unset($files);

    // We should be good now to merge
    exec("git pull origin " . $this->branch . " 2>&1", $result);

    return $result;
}

When listing untracked files in this directory, obviously there are tons which belong to cPanel, so ... the question is how can I rewrite this so that it can be executed successfully from this directory and not screw up anything belonging to cPanel? 当在该目录中列出未跟踪的文件时,显然有很多属于cPanel的文件,所以...问题是我该如何重写它,以便它可以从此目录中成功执行而不会弄乱属于cPanel的文件?

Ok I think I resolved this with some simple .gitignore changes. 好的,我认为我可以通过一些简单的.gitignore更改来解决此问题。

My previous .gitignore looked like so: 我以前的.gitignore看起来像这样:

.DS_Store

# Deploy
/public_html/deploy

# System Cache Files
/application/system/cache/*
!/application/system/cache/index.html

# Image File
/public_html/image/cache/*

# Modification Files
/application/vqmod/vqcache/*
/application/vqmod/logs/*

# Download Files
/application/system/download/*
!/application/system/download/index.html

# Log Files
/application/system/logs/*
!/application/system/logs/index.html

I added some additional ignores to the beginning to ignore all files, then negate the files we want to update like so: 我在开始时添加了一些其他忽略,以忽略所有文件,然后对要更新的文件取反,​​如下所示:

.DS_Store
# Ignore all files and directories
*

# Except our actual application folders
!/.git
!/.gitignore
!/application
!/public_html

# Now negate whats needed
# Deploy
/public_html/deploy

# System Cache Files
/application/system/cache/*
!/application/system/cache/index.html

# Image File
/public_html/image/cache/*

# Modification Files
/application/vqmod/vqcache/*
/application/vqmod/logs/*

# Download Files
/application/system/download/*
!/application/system/download/index.html

# Log Files
/application/system/logs/*
!/application/system/logs/index.html

Seems to have worked as I'm getting correct updates as well as not getting all the cPanel files removed. 似乎在我获取正确的更新以及未删除所有cPanel文件时起作用。

Hope this helps some other folks. 希望这对其他人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM