Last active
August 31, 2016 16:11
-
-
Save pekhee/5521042 to your computer and use it in GitHub Desktop.
Automates pushing to remotes using Git as version control. Adds every new file, Commit everything with user supplied message or a default message if user is not specified one. Also all commits are signed with "-s" option. In case user does not specify a remote, it will push master to every remote. Usage: push "My commit message" "My remote name"…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
$default_message = "A minor change to code, in order to test it."; // Your default message goes here!<<<<<<<<<<<<<<<<<<<<< | |
// HELP | |
if( array_get($argv, 1) == 'help' || array_get($argv, 1) == '-h' || array_get($argv, 1) == '--help'){ | |
echo PHP_EOL; | |
echo "************************************" . PHP_EOL; | |
echo PHP_EOL; | |
echo " Use case:" . PHP_EOL; | |
echo " $argv[0] \$message \$remote \$branch" . PHP_EOL; | |
echo PHP_EOL; | |
echo "************************************"; | |
echo PHP_EOL; | |
return 1; | |
} | |
// Init: | |
if( array_get($argv, 1, '') == 'mc'){ | |
$argv[1] = null; | |
} | |
// Conventions: | |
$message = array_get($argv, 1, escapeshellarg($default_message)); | |
$remote = array_get($argv, 2, 'ns'); | |
$branch = array_get($argv, 3, 'master'); | |
//Executetion: | |
echo PHP_EOL . "*************************************" . PHP_EOL; | |
echo " *****Adding all files:*********" . PHP_EOL . PHP_EOL; | |
exec('git add .'); | |
echo PHP_EOL . " *****Commiting:****************" . PHP_EOL . PHP_EOL; | |
exec("git commit -s -m $message"); | |
echo PHP_EOL . " *****Ensuring current status:**" . PHP_EOL . PHP_EOL; | |
exec('git status 2>$1'); | |
echo PHP_EOL . " *****Publishing to branch******" . PHP_EOL . PHP_EOL; | |
if( $remote == 'ns' ){ | |
exec("git remote", $remotes); | |
foreach( $remotes as $remote ){ | |
echo PHP_EOL . " *****Pushing to $remote******" . PHP_EOL . PHP_EOL; | |
exec("git push $remote $branch"); | |
} | |
} | |
//Helper: | |
function array_get($array, $key, $default = null){ | |
if(is_array($array)){ | |
if(isset($array[$key]) && $array[$key] !== null){ | |
return $array[$key]; | |
} | |
else{ | |
return $default; | |
} | |
} | |
else{ | |
return $default; | |
} | |
} | |
echo PHP_EOL . "*Successfuly updated $branch on $remote*" . PHP_EOL; | |
echo "**************************************" . PHP_EOL . PHP_EOL; | |
return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment