1 | <?php |
||
29 | class BranchCommand extends BaseCommand |
||
30 | { |
||
31 | const BRANCH_COMMAND = 'branch'; |
||
32 | |||
33 | /** |
||
34 | * constructor |
||
35 | * |
||
36 | * @param \GitElephant\Repository $repo The repository object this command |
||
37 | * will interact with |
||
38 | */ |
||
39 | 43 | public function __construct(Repository $repo = null) |
|
43 | |||
44 | /** |
||
45 | * Locate branches that contain a reference |
||
46 | * |
||
47 | * @param string $reference reference |
||
48 | * |
||
49 | * @throws \RuntimeException |
||
50 | * @return string the command |
||
51 | */ |
||
52 | public function contains($reference) |
||
53 | { |
||
54 | $this->clearAll(); |
||
55 | $this->addCommandName(self::BRANCH_COMMAND); |
||
56 | $this->addCommandArgument('--contains'); |
||
57 | $this->addCommandSubject($reference); |
||
58 | |||
59 | return $this->getCommand(); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Create a new branch |
||
64 | * |
||
65 | * @param string $name The new branch name |
||
66 | * @param string|null $startPoint the new branch start point. |
||
67 | * |
||
68 | * @throws \RuntimeException |
||
69 | * @return string the command |
||
70 | */ |
||
71 | 34 | public function create($name, $startPoint = null) |
|
72 | { |
||
73 | 34 | $this->clearAll(); |
|
74 | 34 | $this->addCommandName(self::BRANCH_COMMAND); |
|
75 | 34 | $this->addCommandSubject($name); |
|
76 | 34 | if (null !== $startPoint) { |
|
77 | 5 | $this->addCommandSubject2($startPoint); |
|
78 | 5 | } |
|
79 | |||
80 | 34 | return $this->getCommand(); |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * Lists branches |
||
85 | * |
||
86 | * @param bool $all lists all remotes |
||
87 | * @param bool $simple list only branch names |
||
88 | * |
||
89 | * @throws \RuntimeException |
||
90 | * @return string the command |
||
91 | */ |
||
92 | 43 | public function listBranches($all = false, $simple = false) |
|
93 | { |
||
94 | 43 | $this->clearAll(); |
|
95 | 43 | $this->addCommandName(self::BRANCH_COMMAND); |
|
96 | 43 | if (!$simple) { |
|
97 | 43 | $this->addCommandArgument('-v'); |
|
98 | 43 | } |
|
99 | 43 | $this->addCommandArgument('--no-color'); |
|
100 | 43 | $this->addCommandArgument('--no-abbrev'); |
|
101 | 43 | if ($all) { |
|
102 | 3 | $this->addCommandArgument('-a'); |
|
103 | 3 | } |
|
104 | |||
105 | 43 | return $this->getCommand(); |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * Lists branches |
||
110 | * |
||
111 | * @deprecated This method uses an unconventional name but is being left in |
||
112 | * place to remain compatible with existing code relying on it. |
||
113 | * New code should be written to use listBranches(). |
||
114 | * |
||
115 | * @param bool $all lists all remotes |
||
116 | * @param bool $simple list only branch names |
||
117 | * |
||
118 | * @throws \RuntimeException |
||
119 | * @return string the command |
||
120 | */ |
||
121 | public function lists($all = false, $simple = false) |
||
125 | |||
126 | /** |
||
127 | * get info about a single branch |
||
128 | * |
||
129 | * @param string $name The branch name |
||
130 | * @param bool $all lists all remotes |
||
131 | * @param bool $simple list only branch names |
||
132 | * @param bool $verbose verbose, show also the upstream branch |
||
133 | * |
||
134 | * @throws \RuntimeException |
||
135 | * @return string |
||
136 | */ |
||
137 | 1 | public function singleInfo($name, $all = false, $simple = false, $verbose = false) |
|
157 | |||
158 | /** |
||
159 | * Delete a branch by its name |
||
160 | * |
||
161 | * @param string $name The branch to delete |
||
162 | * @param bool $force Force the delete |
||
163 | * |
||
164 | * @throws \RuntimeException |
||
165 | * @return string the command |
||
166 | */ |
||
167 | 1 | public function delete($name, $force = false) |
|
177 | } |
||
178 |