2 namespace Robo\Task\Vcs;
4 use Robo\Task\CommandStack;
5 use Robo\Common\ProcessUtils;
8 * Runs Git commands in stack. You can use `stopOnFail()` to point that stack should be terminated on first fail.
12 * $this->taskGitStack()
15 * ->commit('adding everything')
16 * ->push('origin','master')
18 * ->push('origin','0.6.0')
21 * $this->taskGitStack()
24 * ->commit('doc updated')
30 class GitStack extends CommandStack
33 * @param string $pathToGit
35 public function __construct($pathToGit = 'git')
37 $this->executable = $pathToGit;
41 * Executes `git clone`
48 public function cloneRepo($repo, $to = "", $branch = "")
50 $cmd = ['clone', $repo, $to];
51 if (!empty($branch)) {
52 $cmd[] = "--branch $branch";
54 return $this->exec($cmd);
58 * Executes `git clone` with depth 1 as default
62 * @param string $branch
67 public function cloneShallow($repo, $to = '', $branch = "", $depth = 1)
69 $cmd = ["clone --depth $depth", $repo, $to];
70 if (!empty($branch)) {
71 $cmd[] = "--branch $branch";
74 return $this->exec($cmd);
78 * Executes `git add` command with files to add pattern
80 * @param string $pattern
84 public function add($pattern)
86 return $this->exec([__FUNCTION__, $pattern]);
90 * Executes `git commit` command with a message
92 * @param string $message
93 * @param string $options
97 public function commit($message, $options = "")
99 $message = ProcessUtils::escapeArgument($message);
100 return $this->exec([__FUNCTION__, "-m $message", $options]);
104 * Executes `git pull` command.
106 * @param string $origin
107 * @param string $branch
111 public function pull($origin = '', $branch = '')
113 return $this->exec([__FUNCTION__, $origin, $branch]);
117 * Executes `git push` command
119 * @param string $origin
120 * @param string $branch
124 public function push($origin = '', $branch = '')
126 return $this->exec([__FUNCTION__, $origin, $branch]);
132 * @param string $branch
136 public function merge($branch)
138 return $this->exec([__FUNCTION__, $branch]);
142 * Executes `git checkout` command
144 * @param string $branch
148 public function checkout($branch)
150 return $this->exec([__FUNCTION__, $branch]);
154 * Executes `git tag` command
156 * @param string $tag_name
157 * @param string $message
161 public function tag($tag_name, $message = "")
163 if ($message != "") {
164 $message = "-m '$message'";
166 return $this->exec([__FUNCTION__, $message, $tag_name]);
172 public function run()
174 $this->printTaskInfo("Running git commands...");
175 return parent::run();