Pull merge.
[yaffs-website] / vendor / consolidation / robo / src / Task / Vcs / HgStack.php
1 <?php
2 namespace Robo\Task\Vcs;
3
4 use Robo\Task\CommandStack;
5
6 /**
7  * Runs hg commands in stack. You can use `stopOnFail()` to point that stack should be terminated on first fail.
8  *
9  * ``` php
10  * <?php
11  * $this->hgStack
12  *  ->cloneRepo('https://bitbucket.org/durin42/hgsubversion')
13  *  ->pull()
14  *  ->add()
15  *  ->commit('changed')
16  *  ->push()
17  *  ->tag('0.6.0')
18  *  ->push('0.6.0')
19  *  ->run();
20  * ?>
21  * ```
22  */
23 class HgStack extends CommandStack
24 {
25
26     /**
27      * @param string $pathToHg
28      */
29     public function __construct($pathToHg = 'hg')
30     {
31         $this->executable = $pathToHg;
32     }
33
34     /**
35      * Executes `hg clone`
36      *
37      * @param string $repo
38      * @param string $to
39      *
40      * @return $this
41      */
42     public function cloneRepo($repo, $to = '')
43     {
44         return $this->exec(['clone', $repo, $to]);
45     }
46
47     /**
48      * Executes `hg add` command with files to add by pattern
49      *
50      * @param string $include
51      * @param string $exclude
52      *
53      * @return $this
54      */
55     public function add($include = '', $exclude = '')
56     {
57         if (strlen($include) > 0) {
58             $include = "-I {$include}";
59         }
60
61         if (strlen($exclude) > 0) {
62             $exclude = "-X {$exclude}";
63         }
64
65         return $this->exec([__FUNCTION__, $include, $exclude]);
66     }
67
68     /**
69      * Executes `hg commit` command with a message
70      *
71      * @param string $message
72      * @param string $options
73      *
74      * @return $this
75      */
76     public function commit($message, $options = '')
77     {
78         return $this->exec([__FUNCTION__, "-m '{$message}'", $options]);
79     }
80
81     /**
82      * Executes `hg pull` command.
83      *
84      * @param string $branch
85      *
86      * @return $this
87      */
88     public function pull($branch = '')
89     {
90         if (strlen($branch) > 0) {
91             $branch = "-b '{$branch}''";
92         }
93
94         return $this->exec([__FUNCTION__, $branch]);
95     }
96
97     /**
98      * Executes `hg push` command
99      *
100      * @param string $branch
101      *
102      * @return $this
103      */
104     public function push($branch = '')
105     {
106         if (strlen($branch) > 0) {
107             $branch = "-b '{$branch}'";
108         }
109
110         return $this->exec([__FUNCTION__, $branch]);
111     }
112
113     /**
114      * Performs hg merge
115      *
116      * @param string $revision
117      *
118      * @return $this
119      */
120     public function merge($revision = '')
121     {
122         if (strlen($revision) > 0) {
123             $revision = "-r {$revision}";
124         }
125
126         return $this->exec([__FUNCTION__, $revision]);
127     }
128
129     /**
130      * Executes `hg tag` command
131      *
132      * @param string $tag_name
133      * @param string $message
134      *
135      * @return $this
136      */
137     public function tag($tag_name, $message = '')
138     {
139         if ($message !== '') {
140             $message = "-m '{$message}'";
141         }
142         return $this->exec([__FUNCTION__, $message, $tag_name]);
143     }
144
145     /**
146      * {@inheritdoc}
147      */
148     public function run()
149     {
150         $this->printTaskInfo('Running hg commands...');
151         return parent::run();
152     }
153 }