├── .gitignore ├── LICENSE ├── README.md ├── easy-git-deploy ├── bootstrap.php ├── inc │ ├── Info.php │ ├── Pull.php │ ├── Push.php │ ├── VcsAbstract.php │ ├── VcsInterface.php │ ├── config.sample.php │ └── style.css ├── index.html ├── info.php ├── pull.php └── push.php └── screenshot.png /.gitignore: -------------------------------------------------------------------------------- 1 | easy-git-deploy/inc/config.php 2 | easy-git-deploy/inc/config.backup* 3 | .idea 4 | deployments.log 5 | */.htaccess 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Johannes Hoppe 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |  2 | 3 | ## #EasyGitDeploy 4 | 5 | Tired of complex shell scripts for managing GIT on your web server? 6 | This tool has exactly one button for each direction. That's all! 7 | 8 | EasyGitDeploy targets the following setup: Your are developing with git and remote repository (e.g. GitHub or BitBucket). To handle deployments for smaller projects (e.g. Static websites, **Angular apps, Wordpress**, etc.) you would like to deploy a branch directly to the webserver (by default 'master' is used). As soon as everything works as expected, you just have to use the _PULL_ button to either create a new git-driven directory on the webserver or to update the existing directory. This works as long as no file-changes were made on the webserver (e.g. automatic wordpress updates or uploaded user-content). 9 | 10 | If there are any conflicting changes, the _PUSH_ button is here to rescue. It creates a new branch and pushes the changes to the remote repository. Now it’s up to you to merge the new branch back to master. As soon as this was made, _PULL_ will work again and brings the project on the webserver back to the latest version. 11 | 12 | 13 | ## Requirements on the web server 14 | * Linux / Unix (or [Cygwin](http://www.cygwin.com/) on Windows) 15 | * PHP 5.4 16 | * git command line tool 17 | 18 | ## Expected Conflict resolvements 19 | 20 | | Dev | Live | Push Button | Pull Button | What to do? | 21 | |:--------------- |:--------------|:-----------------------|:-------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------------| 22 | | Unchanged | Unchanged | New Branch (unchanged) | No changes | | 23 | | Unchanged | **Changes** | New Branch | If on other Branch with open changes, cannot checkout master, nothing happens. | Nothing to do, but if you are not sure if dev is unchanged do 1st push and 2nd pull again. | 24 | | **New Commits** | Unchanged | New Branch (unchanged) | Live receives latest version of master branch. | | 25 | | **New Commits** | **Changes** | New Branch | 1. On master: updates or conflicts. 2. On other Branch with open changes, cannot checkout master, nothing happens. | On any problems, push first, maybe resolve conflicts on dev and pull again. | 26 | 27 | ## Licence 28 | 29 | The MIT License (MIT), Copyright (c) 2017 Johannes Hoppe 30 | see [License text](LICENSE) 31 | 32 | Many thanks to Brandon Summers for the [initial code](http://brandonsummers.name/blog/2012/02/10/using-bitbucket-for-automated-deployments/). 33 | Thanks to [Pascal Dittrich](http://www.pad-soft.de/) for feedback and code attributions. 34 | -------------------------------------------------------------------------------- /easy-git-deploy/bootstrap.php: -------------------------------------------------------------------------------- 1 | has_base_directory()) { 10 | $message = "Directory '{$this->_directory}' not found."; 11 | throw new Exception($message); 12 | } 13 | 14 | // Make sure we're in the right directory 15 | chdir($this->_directory); 16 | 17 | $this->exec_and_log( 18 | 'Git status:', 19 | 'git status'); 20 | 21 | $this->exec_and_log( 22 | 'Current revision:', 23 | 'git log -1'); 24 | 25 | $this->exec_and_log( 26 | 'All files that are changed locally:', 27 | 'git diff --name-only'); 28 | 29 | /* 30 | $this->exec_and_log( 31 | 'Commits you have in HEAD that are not in '.$this->_remote.'/'.$this->_branch, 32 | 'git log '.$this->_remote.'/'.$this->_branch.'..'); 33 | */ 34 | } 35 | catch (Exception $e) { 36 | $this->log($e, 'ERROR'); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /easy-git-deploy/inc/Pull.php: -------------------------------------------------------------------------------- 1 | has_base_directory()) { 10 | mkdir($this->_directory, 0777, true); 11 | } 12 | 13 | // Make sure we're in the right directory 14 | chdir($this->_directory); 15 | 16 | // only first run 17 | if (!is_dir('./.git')) { 18 | // The "." at the end specifies the current folder as the checkout folder! 19 | $this->exec_and_log('Cloning repo for the first time.', "git clone '" . $this->_url . "' ."); 20 | } 21 | 22 | // normal run 23 | else { 24 | 25 | // 1. Move to master branch. 26 | $this->exec_and_log('Switching to master branch.', 'git checkout ' . $this->_branch); 27 | 28 | // 2. Update the local repository 29 | $this->exec_and_log('Pulling in changes.', 'git pull'); 30 | 31 | // hidden feature: checkout special revision 32 | 33 | if (isset($_GET['hash']) && $this->is_sha1($_GET['hash'])) { 34 | $hash = $_GET['hash']; 35 | $this->exec_and_log('Checkout previous revision '. $hash.':', 'git checkout '. $hash); 36 | } 37 | } 38 | 39 | // Secure the .git directory 40 | $this->exec_and_log('Securing .git directory.', 'chmod -R og-rx .git'); 41 | 42 | $this->log('PULL successful.'); 43 | } 44 | catch (Exception $e) { 45 | $this->log($e, 'ERROR'); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /easy-git-deploy/inc/Push.php: -------------------------------------------------------------------------------- 1 | has_base_directory()) { 10 | $message = "Commit directory '{$this->_directory}' not found."; 11 | throw new Exception($message); 12 | } 13 | 14 | // Make sure we're in the right directory 15 | chdir($this->_directory); 16 | 17 | // Add files to repository. 18 | $this->exec_and_log('Adding untracked files.', 'git add -A .'); 19 | 20 | // Move changes to stash. 21 | $this->exec_and_log('Stashing changes.', 'git stash'); 22 | 23 | // Create a new branch. 24 | $branchName = 'productive_system_' . date('Y-m-d_H-i-s'); 25 | $this->exec_and_log( 26 | "Creating new branch '{$branchName}'.", 27 | "git checkout -b {$branchName}" 28 | ); 29 | 30 | // Unstash changes in new branch. 31 | $this->exec_and_log('Unstashing changes.', 'git stash pop'); 32 | 33 | // Create commit. 34 | $commitMessage = 'HTTP triggered server commit; ' . date('Y-m-d H:i:s'); 35 | $this->exec_and_log('Creating commit.', "git commit -am '{$commitMessage}'"); 36 | 37 | // Push changes to remote repository. 38 | $this->exec_and_log('Pushing in changes.', 'git push ' . $this->_remote . ' ' . $branchName); 39 | 40 | $this->log('PUSH successful.'); 41 | } 42 | catch (Exception $e) { 43 | $this->log($e, 'ERROR'); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /easy-git-deploy/inc/VcsAbstract.php: -------------------------------------------------------------------------------- 1 | $value) { 63 | if (in_array($option, $available_options)) { 64 | $this->{'_' . $option} = $value; 65 | } 66 | } 67 | } 68 | 69 | /** 70 | * Writes a message to the log file. 71 | * 72 | * @param array|string $message The message(s) to write 73 | * @param string $type The type of log message (e.g. INFO, DEBUG, ERROR, etc.) 74 | */ 75 | public function log($message, $type = 'INFO') { 76 | if ($this->_log) { 77 | // Set the name of the log file 78 | $filename = $this->_log; 79 | 80 | if (!file_exists($filename)) { 81 | // Create the log file 82 | file_put_contents($filename, ''); 83 | 84 | // Allow anyone to write to log files 85 | chmod($filename, 0666); 86 | } 87 | 88 | if (is_array($message)) { 89 | $message = implode("\n\t", $message); 90 | } 91 | 92 | $formatted = date($this->_date_format) . ' --- ' . $type . ': ' . $message . "\n"; 93 | file_put_contents($filename, $formatted, FILE_APPEND); 94 | 95 | $this->_log_messages .= $formatted; 96 | $this->_log_messages .= "-------------------------------------------------------------------------------\n"; 97 | } 98 | } 99 | 100 | /** 101 | * Calls exec and logs its input and output 102 | * @param string $description The description of the command 103 | * @param string $command The command to execute 104 | */ 105 | public function exec_and_log($description, $command) { 106 | $output = array(); 107 | exec($command . ' 2>&1', $output); 108 | 109 | $messages = array_merge(array($description, $command), $output); 110 | $this->log($messages); 111 | } 112 | 113 | /** 114 | * @return bool 115 | */ 116 | protected function has_base_directory() { 117 | return file_exists($this->_directory); 118 | } 119 | 120 | protected function is_sha1($str) { 121 | return (bool) preg_match('/^[0-9a-f]{40}$/i', $str); 122 | } 123 | } -------------------------------------------------------------------------------- /easy-git-deploy/inc/VcsInterface.php: -------------------------------------------------------------------------------- 1 | '../my_repo', 8 | 9 | // Used for first clone 10 | 'url' => 'https://USER:PASS@bitbucket.org/account/repo.git' 11 | 12 | // Further options: 'log', 'date_format', 'branch', 'remote' 13 | ); -------------------------------------------------------------------------------- /easy-git-deploy/inc/style.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | height: 100%; 3 | } 4 | 5 | .container { 6 | width: 700px; 7 | position: fixed; 8 | top: 50%; 9 | left: 50%; 10 | 11 | margin-top: -300px; 12 | margin-left: -350px; 13 | 14 | opacity: 0.8; 15 | } 16 | 17 | h1 { 18 | font-size: 50px; 19 | font-weight: 800; 20 | } 21 | 22 | h1 i { 23 | font-size: 100px; 24 | } 25 | 26 | .lead { 27 | font-size: 18px; 28 | margin-bottom: 30px; 29 | } 30 | 31 | .jumbotron { 32 | text-align: center; 33 | border-bottom: 1px solid #e5e5e5; 34 | 35 | background: #eeeeee; /* Old browsers */ 36 | background: -moz-linear-gradient(top, #eeeeee 0%, #cecece 100%); /* FF3.6+ */ 37 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(100%,#cecece)); /* Chrome,Safari4+ */ 38 | background: -webkit-linear-gradient(top, #eeeeee 0%,#cecece 100%); /* Chrome10+,Safari5.1+ */ 39 | background: -o-linear-gradient(top, #eeeeee 0%,#cecece 100%); /* Opera 11.10+ */ 40 | background: -ms-linear-gradient(top, #eeeeee 0%,#cecece 100%); /* IE10+ */ 41 | background: linear-gradient(to bottom, #eeeeee 0%,#cecece 100%); /* W3C */ 42 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#cecece',GradientType=0 ); /* IE6-9 */ 43 | } 44 | 45 | .jumbotron .btn { 46 | font-size: 21px; 47 | padding: 14px 24px; 48 | margin: 10px; 49 | } 50 | 51 | .jumbotron .btn small { 52 | display:block; 53 | font-size: 12px; 54 | } 55 | 56 | iframe { 57 | width: 100%; 58 | height: 99%; 59 | } -------------------------------------------------------------------------------- /easy-git-deploy/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 |28 | Tired of complex shell scripts for managing GIT on your web server? 29 | This tool has exactly one button for each direction. That's all! 30 |
31 | 32 | 33 | 34 | PUSH 35 | to remote 36 | 37 | 38 | 39 | 40 | PULL 41 | from remote 42 | 43 |