pocketarc / git-deploy-php

git-deploy-php is a simple php-based tool that deploys your Git repositories to FTP/SFTP servers, and keeps them updated automatically.
http://brunodebarros.github.io/git-deploy-php
292 stars 45 forks source link

Empty files on server when deploying to server for the first time #73

Open teanocrata opened 8 years ago

teanocrata commented 8 years ago

I ran the script after configuring the ini files. It made empty files on the server. All the files were just empty. (Maybe related with #48)

[opensmartcountry]

skip = false
user = "*@*.com"
host = "ftp.*.com"
port = 21
path = "/public_html/*.com"
passive = true

I've check file size with this code and all files have >0 bytes: Helpers::logmessage("File: " . $file . ' size: ' . filesize($file) . ' bytes');

Files PREVIOUS_REVISION and REVISION are succesfully created, both with 40 bytes size.

Thanks a lot!


git version 2.7.4 PHP 5.6.25-1+deb.sury.org~xenial+1 (cli) Linux Mint 18 Sarah (GNU/Linux 4.4.0-21-generic x86_64)

teanocrata commented 8 years ago

I fixed the problem by modifying the following line in the file Git.php at line: 85.

old line: $return['upload'][$file] = $this->get_file_contents("$target_commit:$file");

new line: $return['upload'][$file] = $this->get_file_contents("$target_commit:./$file");

I'm using git-deploy-php from a folder different from the root folder of the project, maybe this is the real problem.

pocketarc commented 8 years ago

Did you rebuild git-deploy afterward, by the way?

I use git-deploy from its repo folder daily so I'm not sure what could be going on here (I've got a "deploy [folder name]" command that I use that calls git-deploy with the right arguments).

I'm glad you were able to fix it. I'm currently working on a test suite for git-deploy so that I can change things without being afraid of breaking stuff - right now I don't know if adding that "./" would ruin things for those of us that don't have that problem, so I'm going to have to have a look at this issue once we've got the test suite up and running.

teanocrata commented 8 years ago

Hi Bruno!

I have rebuilt everything several times because I put different traces until I found the problem.

In the last traces I got:

[2016-08-24 17:06:28 +0200] get_file_contents: e40e38491ce42c737b71a6c25f39661ac29238f1:php/test/api_rest_test.php [2016-08-24 17:06:28 +0200] trim(sell_exec()) [2016-08-24 17:06:28 +0200] git show "e40e38491ce42c737b71a6c25f39661ac29238f1:php/test/api_rest_test.php" 2>&1 > "/tmp/git-deploy-1WGhFO"

Running same command from terminal:

teanocrata@OpnSC-CPD11 ~/Development/OpenSmartCountry/Web $ git show "e40e38491ce42c737b71a6c25f39661ac29238f1:cultivos.html"
fatal: Path 'Web/cultivos.html' exists, but not 'cultivos.html'.
Did you mean 'e40e38491ce42c737b71a6c25f39661ac29238f1:Web/cultivos.html' aka 'e40e38491ce42c737b71a6c25f39661ac29238f1:./cultivos.html'?

And that's why I added the "./" so that now the code is:

      } Else {
            foreach ($ result as $ file) {
                if (! in_array ($ file, $ submodule_paths)) {
                    Helpers :: LogMessage ( "get_file_contents:" "$ target_commit: $ file.");
                    $ Return [ 'upload'] [$ file] = $ this-> get_file_contents ( "$ target_commit: ./$ file");
                }
            }
        }

        return $ return;
    }

    get_file_contents protected function ($ path) {
        $ Temp = tempnam (sys_get_temp_dir (), "git-deploy-");
        $ This-> exec ( 'show' '$ path..' " '"> \ "$ Temp \" ");
        return file_get_contents ($ temp);
    }

    protected function exec ($ command, $ suffix = "") {
        if (chdir ($ this-> repo_path)) {
            $ Console = trim (shell_exec (self :: $ git_executable_path "2> & 1" $ suffix). "$ Command...");
            Helpers :: LogMessage ( "trim (sell_exec ())");
            Helpers :: LogMessage (self :: $ git_executable_path "2> & 1" $ suffix. "$ Command...");
            return $ console;
        } Else {
            Helpers :: error ( "Unable to access the git repository's folder.");
        }
    }

Are you going to release a version with deploy[folder name] funcionality? I'll use my modified fork (I've to clean the traces on the code previously) by'll now pending possible changes.

I am also automating tests in my project using simpletest and Travis CI, my idea is to also use git-deploy for the deploy through Travis CI.

Thanks a lot!

teanocrata commented 8 years ago

Hi Bruno,

Some news:

When I run diff command inside the folder where I have the files to deploy , the path in each line is the absolute path of the repo. Meanwhile when I run ls-files, the path in each line haven't the root folder, is relative path.

Moreover, when I run git diff without --relative, this command includes all files with differences in the repo.

For this reason at the end I've made 3 changes on the code in Git.php:

Git.php Line 46 old:

$command = "diff --no-renames --name-status {$current_commit} {$target_commit}";

Git.php Line 46 new:

$command = "diff --no-renames --name-status --relative {$current_commit} {$target_commit}";

Git.php Line 71 old:

$return['upload'][$path] = $this->get_file_contents("$target_commit:\"$path\"");

Git.php Line 71 new:

$return['upload'][$path] = $this->get_file_contents("$target_commit:./\"$path\"");

Git.php Line 85 old:

$return['upload'][$file] = $this->get_file_contents("$target_commit:$file");

Git.php Line 85 new:

$return['upload'][$file] = $this->get_file_contents("$target_commit:./$file");

(Note the difference between "$target_commit:./$file" and "$target_commit:./\"$path\"", $path variable is surrounded with ", should be the same with $file variable? I haven`t blanks in my file names to test it).