cPanel主目录中的GIT仓库

时间:2014-06-03 00:54:00

标签: php git

我正在尝试确保当GIT repo本身是cPanel服务器中用户的主目录时,我编写的GIT Web挂钩仍可用于站点。

在以前的情况下,我总是在主目录下面的目录中拥有repo,这可以正常工作,因为在该目录中执行了pull / fetch而不是home。

我们的钩子旨在允许其他开发人员能够通过ftp上传文件进行测试,然后进行测试,致力于给定的回购。当我们将更改推送到我们的仓库时,Web钩子会记录未跟踪或更改的文件并将其删除或检出,以便可以通过GIT更新它们。

这是客户要求的一部分,不可协商,所以我必须解决它。

使用开发版本我可以设置文件结构:

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

DIRS:

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

没有问题,因为/ dev只包含我们正在跟踪和部署的文件。

但在实时环境中,目录结构如下所示:

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

我的获取功能如下:

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;
}

当在这个目录中列出未跟踪的文件时,显然有吨属于cPanel,所以...问题是如何重写这个以便它可以从这个目录成功执行而不搞砸属于cPanel的任何东西?

1 个答案:

答案 0 :(得分:0)

好的,我想我通过一些简单的.gitignore更改解决了这个问题。

我以前的.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

我在开头添加了一些额外的忽略忽略所有文件,然后否定我们想要更新的文件,如下所示:

.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

似乎已经工作,因为我正在获得正确的更新以及没有删除所有cPanel文件。

希望这有助于其他人。