Skip to content

Commit

Permalink
Add option to Ignore tracked files
Browse files Browse the repository at this point in the history
  • Loading branch information
arxeiss committed Oct 15, 2018
1 parent 2f95650 commit 637a33b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Deployment/CliRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CliRunner
'passivemode' => true,
'include' => '',
'ignore' => '',
'ignoreTracked' => '',
'allowdelete' => true,
'alwaysrunactions' => false,
'purge' => '',
Expand Down Expand Up @@ -146,6 +147,7 @@ private function createDeployer(array $config): Deployer

$deployment->includeMasks = self::toArray($config['include'], true);
$deployment->ignoreMasks = array_merge($this->ignoreMasks, self::toArray($config['ignore']));
$deployment->ignoreTrackedMasks = self::toArray($config['ignoretracked']);
$deployment->deploymentFile = empty($config['deploymentfile']) ? $deployment->deploymentFile : $config['deploymentfile'];
$deployment->allowDelete = $config['allowdelete'];
$deployment->alwaysRunActions = $config['alwaysrunactions'];
Expand Down
32 changes: 31 additions & 1 deletion src/Deployment/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Deployer
/** @var string[] */
public $ignoreMasks = [];

/** @var string[] */
public $ignoreTrackedMasks = [];

/** @var bool */
public $testMode = false;

Expand Down Expand Up @@ -108,6 +111,7 @@ public function deploy(): void
$this->logger->log("Remote $this->deploymentFile file not found");
$remotePaths = [];
}
$ignoredRemoteTracked = $this->inPlceFilterRemotePaths($remotePaths);

$this->logger->log("Scanning files in $this->localDir");
$localPaths = $this->collectPaths();
Expand All @@ -117,7 +121,7 @@ public function deploy(): void
$toUpload = array_keys(array_diff_assoc($localPaths, $remotePaths));

if ($localPaths !== $remotePaths) { // ignores allowDelete
$deploymentFile = $this->writeDeploymentFile($localPaths);
$deploymentFile = $this->writeDeploymentFile($localPaths + $ignoredRemoteTracked);
$toUpload[] = "/$this->deploymentFile"; // must be last
}

Expand Down Expand Up @@ -336,6 +340,10 @@ public function collectPaths(string $subdir = ''): array
if ($entry == '.' || $entry == '..') {
continue;

} elseif (Helpers::matchMask($short, $this->ignoreTrackedMasks, is_dir($path))) {
$this->logger->log(str_pad("Ignoring tracked .$short", 40), 'gray');
continue;

} elseif (Helpers::matchMask($short, $this->ignoreMasks, is_dir($path))) {
$this->logger->log(str_pad("Ignoring .$short", 40), 'gray');
continue;
Expand All @@ -357,6 +365,28 @@ public function collectPaths(string $subdir = ''): array
}


/**
* Filter in place all paths that are in ignoreTrackedMasks
*
* @param array &$remotePaths All remote paths to be filtered in place, array is changing
* @return array All filtered paths
*/
private function inPlceFilterRemotePaths(&$remotePaths)
{
$ignoringTracked = [];
if (empty($this->ignoreTrackedMasks)) {
return [];
}
foreach ($remotePaths as $file => $hash) {
if (Helpers::matchMask($file, $this->ignoreTrackedMasks, substr($file, -1) === '/')) {
$ignoringTracked[$file] = $hash;
unset($remotePaths[$file]);
}
}
return $ignoringTracked;
}


/**
* Calls preprocessors on file.
* @param string $file relative path, starts with /
Expand Down

0 comments on commit 637a33b

Please sign in to comment.