Skip to content

Commit

Permalink
v1.3.1 - Fixes Fresh Upload
Browse files Browse the repository at this point in the history
Fresh upload was broken on previos dev cicyle. It is now fixed. Requires two checks. fixes #6
  • Loading branch information
banago committed Feb 15, 2014
1 parent 8f39926 commit 72d38fd
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions phploy
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class PHPloy
$tmpFile = tmpfile();
$filesToUpload = array();
$filesToDelete = array();
$output = array();

if ($this->isSubmodule) {
$this->dotRevision = $this->isSubmodule.'/.revision';
Expand All @@ -259,34 +260,35 @@ class PHPloy
$this->output('Fresh deployment - grab a ☕');
}

$gitCommand = 'git --git-dir="'.$this->repo.'/.git" --work-tree="'.$this->repo.'"';
$gitCommand = 'git --git-dir="'.$this->repo.'/.git" --work-tree="'.$this->repo.'"';

if ($localRevision == 'HEAD') {
if (empty($remoteRevision)) {
$command = $gitCommand.' ls-files';
} else if ($localRevision == 'HEAD') {
$command = $gitCommand.' diff --name-status '.$remoteRevision.'...'.$localRevision;
} else {
// Swap revisions when you revert
$command = $gitCommand.' diff --name-status '.$remoteRevision.'... '.$localRevision;
}

$output = array();
exec(escapeshellcmd($command), $output);

$filesToUpload = array();
$filesToDelete = array();

foreach ($output as $line) {
if ($line[0] == 'A' or $line[0] == 'C' or $line[0] == 'M') {
// Added (A), Modified (C), Unmerged (M)
$filesToUpload[] = trim(substr($line, 1));
} elseif ($line[0] == 'D') {
// Deleted (D)
$filesToDelete[] = trim(substr($line, 1));
} else {
throw new Exception("Unknown git-diff status: {$line[0]}");
}
}
if (!empty($remoteRevision)) {
foreach ($output as $line) {
if ($line[0] == 'A' or $line[0] == 'C' or $line[0] == 'M') {
// Added (A), Modified (C), Unmerged (M)
$filesToUpload[] = trim(substr($line, 1));
} elseif ($line[0] == 'D') {
// Deleted (D)
$filesToDelete[] = trim(substr($line, 1));
} else {
throw new Exception("Unknown git-diff status: {$line[0]}");
}
}
} else {
$filesToUpload = $output;
}

$filesToUpload = array_diff($filesToUpload, $this->files_to_ignore);
$filesToUpload = array_diff($filesToUpload, $this->filesToIgnore);

return array(
'upload' => $filesToUpload,
Expand Down

0 comments on commit 72d38fd

Please sign in to comment.