diff --git a/.gitattributes b/.gitattributes new file mode 100755 index 0000000..c2c9a85 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +*.php text +*.json text +*.sh eol=lf +*.bat eol=crlf \ No newline at end of file diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 7710382..e685c25 --- a/README.md +++ b/README.md @@ -12,9 +12,10 @@ Currently implemented: - clean (removes all dead symlinks) - create (creates a modman file for an existing module) - clone (clones a git repository) + - remove (removes the symlinks) ---force is available for link, deploy, deploy-all and clone, if not set script aborts when conflicts are found +--force is available for link, deploy, deploy-all, remove and clone, if not set script aborts when conflicts are found Usage examples: diff --git a/modman.php b/modman.php old mode 100644 new mode 100755 index b3bd0d1..40cca45 --- a/modman.php +++ b/modman.php @@ -11,6 +11,27 @@ class Modman { */ const ERR_NO_MODMAN_FILE = 2; + /** + * test if running under Cygwin + * RJR 9-Apr-15 + * + * @return bool true if running on Cygwin, otherwise false + */ + static function isCygWin() { + static $bGotResult = false; // cache the result + static $bIsCygwin; // the result + + if (!$bGotResult) { + if (stripos(php_uname(),'cygwin') !== false) { + $bIsCygwin = true; + } else { + $bIsCygwin = false; + } + $bGotResult = true; + } + return $bIsCygwin; + } + /** * runs and dispatches the modman program * @@ -102,15 +123,10 @@ public function run($aParameters) { ) )); $sMessage = $oException->getMessage(); - $sCowsay = @file_get_contents('http://cowsay.morecode.org/say?message=' . urlencode($sMessage) . '&format=text', false, $rCtx); - if ($sCowsay) { - echo $sCowsay; - } else { - echo '-----' . PHP_EOL; - echo 'An error occured:' . PHP_EOL; - echo $sMessage . PHP_EOL; - echo '-----'; - } + echo '-----' . PHP_EOL; + echo 'An error occured:' . PHP_EOL; + echo $sMessage . PHP_EOL; + echo '-----'; echo PHP_EOL . PHP_EOL; $this->printHelp(); } @@ -133,6 +149,7 @@ public function printHelp(){ - clean - create (optional --force, --include and --include-hidden) - clone (optional --force, --create-modman) +- remove (optional --force) Currently supported in modman-files: - symlinks (with wildcards) @@ -541,7 +558,7 @@ public function doDeploy($bForce = false) { if ($this->sModuleName === Modman_Command_Init::MODMAN_BASEDIR_FILE) { return; } - + $oModmanModuleSymlink = new Modman_Module_Symlink($this->sModuleName); $sTarget = $oModmanModuleSymlink->getModmanModuleSymlinkPath(); @@ -1138,19 +1155,17 @@ private function isFolderEmpty($sDirectoryPath){ * @param string $sElementPath resource to remove */ public function doRemoveResource($sElementPath){ - if (is_dir($sElementPath)){ - if (is_link($sElementPath) OR $this->isFolderEmpty($sElementPath)){ - rmdir($sElementPath); - } - } else if (is_file($sElementPath)){ - // workaround for windows to delete read-only flag - // which prevents file from being deleted properly - chmod($sElementPath, 0777); - unlink($sElementPath); - } - elseif (is_link($sElementPath)){ - unlink($sElementPath); - } + + if (is_link($sElementPath)){ + unlink($sElementPath); + } elseif (is_file($sElementPath)) { + // workaround for windows to delete read-only flag + // which prevents file from being deleted properly + chmod($sElementPath, 0777); + unlink($sElementPath); + } elseif ( is_dir($sElementPath) AND $this->isFolderEmpty($sElementPath) ) { + rmdir($sElementPath); + } } /** diff --git a/modman.sh b/modman.sh old mode 100644 new mode 100755 index bc5d9ce..4e2538c --- a/modman.sh +++ b/modman.sh @@ -1,4 +1,29 @@ #!/bin/bash +# +# If running under Cygwin, set the type of symlinks we want to use. +# For modman-php we want native NTFS symbolic links. Windows shortcuts +# and Cygwin default symbolic links are not seen by Git or PhpStorm +# and therefore renders modman-php useless in these cases. +# +# Using winsymlinks:native works for me, but according to this thread: +# http:#stackoverflow.com/questions/19780951/cygwin-winsymlinksnative-doesnt-work +# some people may experience problems. Perhaps there are version issues. +# To cover all cases more investigation and additional logic may be needed. +# RJR 9-Apr-15 +# +function setupEnv() { + shopt -s nocasematch + if [[ `cmd /c ver` =~ Version\ *[6789] ]] + then + if [[ `uname -a` =~ cygwin ]] + then + CYGWIN=`echo "$CYGWIN" | sed -e 's/winsymlinks[:a-z]*//' -e 's/$/ winsymlinks:native/'` + export CYGWIN + fi + fi +} + +setupEnv sScript="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/modman.php"; php "$sScript" "$@";