Completed
Push — master ( a88275...1a2f11 )
by Chris
06:23 queued 03:51
created

GitWorkingCopy::removeRemote()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace GitWrapper;
4
5
use Symfony\Component\Process\ProcessUtils;
6
7
/**
8
 * Interacts with a working copy.
9
 *
10
 * All commands executed via an instance of this class act on the working copy
11
 * that is set through the constructor.
12
 */
13
class GitWorkingCopy
14
{
15
    /**
16
     * The GitWrapper object that likely instantiated this class.
17
     *
18
     * @var \GitWrapper\GitWrapper
19
     */
20
    protected $wrapper;
21
22
    /**
23
     * Path to the directory containing the working copy.
24
     *
25
     * @var string
26
     */
27
    protected $directory;
28
29
    /**
30
     * The output captured by the last run Git commnd(s).
31
     *
32
     * @var string
33
     */
34
    protected $output = '';
35
36
    /**
37
     * A boolean flagging whether the repository is cloned.
38
     *
39
     * If the variable is null, the a rudimentary check will be performed to see
40
     * if the directory looks like it is a working copy.
41
     *
42
     * @param bool|null
43
     */
44
    protected $cloned;
45
46
    /**
47
     * Constructs a GitWorkingCopy object.
48
     *
49
     * @param \GitWrapper\GitWrapper $wrapper
50
     *   The GitWrapper object that likely instantiated this class.
51
     * @param string $directory
52
     *   Path to the directory containing the working copy.
53
     */
54 156
    public function __construct(GitWrapper $wrapper, $directory)
55
    {
56 156
        $this->wrapper = $wrapper;
57 156
        $this->directory = $directory;
58 156
    }
59
60
    /**
61
     * Returns the GitWrapper object that likely instantiated this class.
62
     *
63
     * @return \GitWrapper\GitWrapper
64
     */
65 12
    public function getWrapper()
66
    {
67 12
        return $this->wrapper;
68
    }
69
70
    /**
71
     * Gets the path to the directory containing the working copy.
72
     *
73
     * @return string
74
     */
75 4
    public function getDirectory()
76
    {
77 4
        return $this->directory;
78
    }
79
80
    /**
81
     * Gets the output captured by the last run Git commnd(s).
82
     *
83
     * @return string
84
     */
85 92
    public function getOutput()
86
    {
87 92
        $output = $this->output;
88 92
        $this->output = '';
89 92
        return $output;
90
    }
91
92
    /**
93
     * Clears the stored output captured by the last run Git command(s).
94
     *
95
     * @return \GitWrapper\GitWorkingCopy
96
     */
97 144
    public function clearOutput()
98
    {
99 144
        $this->output = '';
100 144
        return $this;
101
    }
102
103
    /**
104
     * Manually sets the cloned flag.
105
     *
106
     * @param boolean $cloned
107
     *   Whether the repository is cloned into the directory or not.
108
     *
109
     * @return \GitWrapper\GitWorkingCopy
110
     */
111 152
    public function setCloned($cloned)
112
    {
113 152
        $this->cloned = (bool) $cloned;
114 152
        return $this;
115
    }
116
117
    /**
118
     * Checks whether a repository has already been cloned to this directory.
119
     *
120
     * If the flag is not set, test if it looks like we're at a git directory.
121
     *
122
     * @return boolean
123
     */
124 4
    public function isCloned()
125
    {
126 4
        if (!isset($this->cloned)) {
127 4
            $gitDir = $this->directory;
128 4
            if (is_dir($gitDir . '/.git')) {
129 4
                $gitDir .= '/.git';
130 4
            };
131 4
            $this->cloned = (is_dir($gitDir . '/objects') && is_dir($gitDir . '/refs') && is_file($gitDir . '/HEAD'));
132 4
        }
133 4
        return $this->cloned;
134
    }
135
136
    /**
137
     * Runs a Git command and captures the output.
138
     *
139
     * @param array $args
140
     *   The arguments passed to the command method.
141
     * @param boolean $setDirectory
142
     *   Set the working directory, defaults to true.
143
     *
144
     * @return \GitWrapper\GitWorkingCopy
145
     *
146
     * @throws \GitWrapper\GitException
147
     *
148
     * @see GitWrapper::run()
149
     */
150 152
    public function run($args, $setDirectory = true)
151
    {
152 152
        $command = call_user_func_array(array('GitWrapper\GitCommand', 'getInstance'), $args);
153 152
        if ($setDirectory) {
154 148
            $command->setDirectory($this->directory);
155 148
        }
156 152
        $this->output .= $this->wrapper->run($command);
157 152
        return $this;
158
    }
159
160
    /**
161
     * @defgroup command_helpers Git Command Helpers
162
     *
163
     * Helper methods that wrap common Git commands.
164
     *
165
     * @{
166
     */
167
168
    /**
169
     * Returns the output of a `git status -s` command.
170
     *
171
     * @return string
172
     *
173
     * @throws \GitWrapper\GitException
174
     */
175 20
    public function getStatus()
176
    {
177 20
        return $this->wrapper->git('status -s', $this->directory);
178
    }
179
180
    /**
181
     * Returns true if there are changes to commit.
182
     *
183
     * @return bool
184
     *
185
     * @throws \GitWrapper\GitException
186
     */
187 12
    public function hasChanges()
188
    {
189 12
        $output = $this->getStatus();
190 12
        return !empty($output);
191
    }
192
193
    /**
194
     * Returns whether HEAD has a remote tracking branch.
195
     *
196
     * @return bool
197
     */
198 20
    public function isTracking()
199
    {
200
        try {
201 20
            $this->run(array('rev-parse @{u}'));
202 20
        } catch (GitException $e) {
203 4
            return false;
204
        }
205 20
        return true;
206
    }
207
208
    /**
209
     * Returns whether HEAD is up-to-date with its remote tracking branch.
210
     *
211
     * @return bool
212
     *
213
     * @throws \GitWrapper\GitException
214
     *   Thrown when HEAD does not have a remote tracking branch.
215
     */
216 4
    public function isUpToDate()
217
    {
218 4
        if (!$this->isTracking()) {
219
            throw new GitException('Error: HEAD does not have a remote tracking branch. Cannot check if it is up-to-date.');
220
        }
221 4
        $this->clearOutput();
222 4
        $merge_base = (string) $this->run(array('merge-base @ @{u}'));
223 4
        $remote_sha = (string) $this->run(array('rev-parse @{u}'));
224 4
        return $merge_base === $remote_sha;
225
    }
226
227
    /**
228
     * Returns whether HEAD is ahead of its remote tracking branch.
229
     *
230
     * If this returns true it means that commits are present locally which have
231
     * not yet been pushed to the remote.
232
     *
233
     * @return bool
234
     *
235
     * @throws \GitWrapper\GitException
236
     *   Thrown when HEAD does not have a remote tracking branch.
237
     */
238 4 View Code Duplication
    public function isAhead()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
239
    {
240 4
        if (!$this->isTracking()) {
241
            throw new GitException('Error: HEAD does not have a remote tracking branch. Cannot check if it is ahead.');
242
        }
243 4
        $this->clearOutput();
244 4
        $merge_base = (string) $this->run(array('merge-base @ @{u}'));
245 4
        $local_sha = (string) $this->run(array('rev-parse @'));
246 4
        $remote_sha = (string) $this->run(array('rev-parse @{u}'));
247 4
        return $merge_base === $remote_sha && $local_sha !== $remote_sha;
248
    }
249
250
    /**
251
     * Returns whether HEAD is behind its remote tracking branch.
252
     *
253
     * If this returns true it means that a pull is needed to bring the branch
254
     * up-to-date with the remote.
255
     *
256
     * @return bool
257
     *
258
     * @throws \GitWrapper\GitException
259
     *   Thrown when HEAD does not have a remote tracking branch.
260
     */
261 4 View Code Duplication
    public function isBehind()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
262
    {
263 4
        if (!$this->isTracking()) {
264
            throw new GitException('Error: HEAD does not have a remote tracking branch. Cannot check if it is behind.');
265
        }
266 4
        $this->clearOutput();
267 4
        $merge_base = (string) $this->run(array('merge-base @ @{u}'));
268 4
        $local_sha = (string) $this->run(array('rev-parse @'));
269 4
        $remote_sha = (string) $this->run(array('rev-parse @{u}'));
270 4
        return $merge_base === $local_sha && $local_sha !== $remote_sha;
271
    }
272
273
    /**
274
     * Returns whether HEAD needs to be merged with its remote tracking branch.
275
     *
276
     * If this returns true it means that HEAD has diverged from its remote
277
     * tracking branch; new commits are present locally as well as on the
278
     * remote.
279
     *
280
     * @return bool
281
     *   true if HEAD needs to be merged with the remote, false otherwise.
282
     *
283
     * @throws \GitWrapper\GitException
284
     *   Thrown when HEAD does not have a remote tracking branch.
285
     */
286 4 View Code Duplication
    public function needsMerge()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
287
    {
288 4
        if (!$this->isTracking()) {
289
            throw new GitException('Error: HEAD does not have a remote tracking branch. Cannot check if it is behind.');
290
        }
291 4
        $this->clearOutput();
292 4
        $merge_base = (string) $this->run(array('merge-base @ @{u}'));
293 4
        $local_sha = (string) $this->run(array('rev-parse @'));
294 4
        $remote_sha = (string) $this->run(array('rev-parse @{u}'));
295 4
        return $merge_base !== $local_sha && $merge_base !== $remote_sha;
296
    }
297
298
    /**
299
     * Returns a GitBranches object containing information on the repository's
300
     * branches.
301
     *
302
     * @return GitBranches
303
     */
304 4
    public function getBranches()
305
    {
306 4
        return new GitBranches($this);
307
    }
308
309
    /**
310
     * Helper method that pushes a tag to a repository.
311
     *
312
     * This is synonymous with `git push origin tag v1.2.3`.
313
     *
314
     * @param string $tag
315
     *   The tag being pushed.
316
     * @param string $repository
317
     *   The destination of the push operation, which is either a URL or name of
318
     *   the remote. Defaults to "origin".
319
     * @param array $options
320
     *   (optional) An associative array of command line options.
321
     *
322
     * @see GitWorkingCopy::push()
323
     */
324 4
    public function pushTag($tag, $repository = 'origin', array $options = array())
325
    {
326 4
        return $this->push($repository, 'tag', $tag, $options);
327
    }
328
329
    /**
330
     * Helper method that pushes all tags to a repository.
331
     *
332
     * This is synonymous with `git push --tags origin`.
333
     *
334
     * @param string $repository
335
     *   The destination of the push operation, which is either a URL or name of
336
     *   the remote. Defaults to "origin".
337
     * @param array $options
338
     *   (optional) An associative array of command line options.
339
     *
340
     * @see GitWorkingCopy::push()
341
     */
342 144
    public function pushTags($repository = 'origin', array $options = array())
343
    {
344 144
        $options['tags'] = true;
345 144
        return $this->push($repository, $options);
346
    }
347
348
    /**
349
     * Fetches all remotes.
350
     *
351
     * This is synonymous with `git fetch --all`.
352
     *
353
     * @param array $options
354
     *   (optional) An associative array of command line options.
355
     *
356
     * @see GitWorkingCopy::fetch()
357
     */
358 4
    public function fetchAll(array $options = array())
359
    {
360 4
        $options['all'] = true;
361 4
        return $this->fetch($options);
362
    }
363
364
    /**
365
     * Create a new branch and check it out.
366
     *
367
     * This is synonymous with `git checkout -b`.
368
     *
369
     * @param string $branch
370
     *   The new branch being created.
371
     *
372
     * @see GitWorkingCopy::checkout()
373
     */
374 144
    public function checkoutNewBranch($branch, array $options = array())
375
    {
376 144
        $options['b'] = true;
377 144
        return $this->checkout($branch, $options);
378
    }
379
380
    /**
381
     * Adds a remote to the repository.
382
     *
383
     * @param string $name
384
     *   The name of the remote to add.
385
     * @param string $url
386
     *   The URL of the remote to add.
387
     * @param array $options
388
     *   An associative array of options, with the following keys:
389
     *   - -f: Boolean, set to true to run git fetch immediately after the
390
     *     remote is set up. Defaults to false.
391
     *   - --tags: Boolean, set to true to import every tag from the remote
392
     *     repository when git fetch is run. Defaults to false.
393
     *   - --no-tags: Boolean, when set to true, git fetch does not import tags
394
     *     from the remote repository. Defaults to false.
395
     *   - -t: Optional array of branch names to track. If left empty, all
396
     *     branches will be tracked.
397
     *   - -m: Optional name of the master branch to track. This will set up a
398
     *     symbolic ref 'refs/remotes/<name>/HEAD which points at the specified
399
     *     master branch on the remote. When omitted, no symbolic ref will be
400
     *     created.
401
     *
402
     * @return \GitWrapper\GitWorkingCopy
403
     *
404
     * @throws \GitWrapper\GitException
405
     *   Thrown when the name or URL are missing.
406
     */
407
    public function addRemote($name, $url, $options = array()) {
408
        if (empty($name)) {
409
            throw new GitException('Cannot add remote without a name.');
410
        }
411
        if (empty($url)) {
412
            throw new GitException('Cannot add remote without a URL.');
413
        }
414
415
        $args = array('add');
416
417
        // Add boolean options.
418
        foreach (array('-f', '--tags', '--no-tags') as $option) {
419
            if (!empty($options[$option])) {
420
                $args[] = $option;
421
            }
422
        }
423
424
        // Add tracking branches.
425
        if (!empty($options['-t'])) {
426
            foreach ($options['-t'] as $branch) {
427
                array_push($args, '-t', $branch);
428
            }
429
        }
430
431
        // Add master branch.
432
        if (!empty($options['-m'])) {
433
            array_push($args, '-m', $options['-m']);
434
        }
435
436
        // Add remote name and URL.
437
        array_push($args, $name, $url);
438
439
        return call_user_func_array(array($this, 'remote'), $args);
440
    }
441
442
    /**
443
     * Removes the given remote.
444
     *
445
     * @param string $name
446
     *   The name of the remote to remove.
447
     *
448
     * @return \GitWrapper\GitWorkingCopy
449
     */
450
    public function removeRemote($name) {
451
        return $this->remote('rm', $name);
452
    }
453
454
    /**
455
     * Checks if the given remote exists.
456
     *
457
     * @param string $name
458
     *   The name of the remote to check.
459
     *
460
     * @return bool
461
     */
462
    public function hasRemote($name) {
463
        return array_key_exists($name, $this->getRemotes());
464
    }
465
466
    /**
467
     * Returns the given remote.
468
     *
469
     * @param string $name
470
     *   The name of the remote.
471
     *
472
     * @return array
473
     *   An associative array with the following keys:
474
     *   - fetch: the fetch URL.
475
     *   - push: the push URL.
476
     *
477
     * @throws \GitWrapper\GitException
478
     *   Thrown when the remote does not exist.
479
     */
480
    public function getRemote($name) {
481
        if (!$this->hasRemote($name)) {
482
            throw new GitException('The remote "' . $name . '" does not exist.');
483
        }
484
        $remotes = $this->getRemotes();
485
        return $remotes[$name];
486
    }
487
488
    /**
489
     * Returns all existing remotes.
490
     *
491
     * @return array
492
     *   An associative array, keyed by remote name, containing an associative
493
     *   array with the following keys:
494
     *   - fetch: the fetch URL.
495
     *   - push: the push URL.
496
     */
497
    public function getRemotes() {
498
        $remotes = array();
499
        foreach (explode("\n", rtrim($this->remote()->getOutput())) as $remote) {
500
            $remotes[$remote]['fetch'] = rtrim($this->remote('get-url', $remote)->getOutput());
501
            $remotes[$remote]['push'] = rtrim($this->remote('get-url', '--push', $remote)->getOutput());
502
        }
503
        return $remotes;
504
    }
505
506
    /**
507
     * @} End of "defgroup command_helpers".
508
     */
509
510
    /**
511
     * @defgroup commands Git Commands
512
     *
513
     * All methods in this group correspond with Git commands, for example
514
     * "git add", "git commit", "git push", etc.
515
     *
516
     * @{
517
     */
518
519
    /**
520
     * Executes a `git add` command.
521
     *
522
     * Add file contents to the index.
523
     *
524
     * @code
525
     * $git->add('some/file.txt');
526
     * @endcode
527
     *
528
     * @param string $filepattern
529
     *   Files to add content from. Fileglobs (e.g.  *.c) can be given to add
530
     *   all matching files. Also a leading directory name (e.g.  dir to add
531
     *   dir/file1 and dir/file2) can be given to add all files in the
532
     *   directory, recursively.
533
     * @param array $options
534
     *   An optional array of command line options.
535
     *
536
     * @return \GitWrapper\GitWorkingCopy
537
     *
538
     * @throws \GitWrapper\GitException
539
     */
540 144
    public function add($filepattern, array $options = array())
541
    {
542
        $args = array(
543 144
            'add',
544 144
            $filepattern,
545 144
            $options,
546 144
        );
547 144
        return $this->run($args);
548
    }
549
550
    /**
551
     * Executes a `git apply` command.
552
     *
553
     * Apply a patch to files and/or to the index
554
     *
555
     * @code
556
     * $git->apply('the/file/to/read/the/patch/from');
557
     * @endcode
558
     *
559
     * @param string ...
560
     *   (optional) Additional command line arguments.
561
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
562
     *   (optional) An associative array of command line options.
563
     *
564
     * @return GitWorkingCopy
565
     *
566
     * @throws GitException
567
     */
568 4
    public function apply()
569
    {
570 4
        $args = func_get_args();
571 4
        array_unshift($args, 'apply');
572 4
        return $this->run($args);
573
    }
574
575
    /**
576
     * Executes a `git bisect` command.
577
     *
578
     * Find by binary search the change that introduced a bug.
579
     *
580
     * @code
581
     * $git->bisect('good', '2.6.13-rc2');
582
     * $git->bisect('view', array('stat' => true));
583
     * @endcode
584
     *
585
     * @param string $sub_command
586
     *   The subcommand passed to `git bisect`.
587
     * @param string ...
588
     *   (optional) Additional command line arguments.
589
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
590
     *   (optional) An associative array of command line options.
591
     *
592
     * @return \GitWrapper\GitWorkingCopy
593
     *
594
     * @throws \GitWrapper\GitException
595
     */
596 4
    public function bisect($sub_command)
597
    {
598 4
        $args = func_get_args();
599 4
        $args[0] = 'bisect ' . ProcessUtils::escapeArgument($sub_command);
600 4
        return $this->run($args);
601
    }
602
603
    /**
604
     * Executes a `git branch` command.
605
     *
606
     * List, create, or delete branches.
607
     *
608
     * @code
609
     * $git->branch('my2.6.14', 'v2.6.14');
610
     * $git->branch('origin/html', 'origin/man', array('d' => true, 'r' => 'origin/todo'));
611
     * @endcode
612
     *
613
     * @param string ...
614
     *   (optional) Additional command line arguments.
615
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
616
     *   (optional) An associative array of command line options.
617
     *
618
     * @return \GitWrapper\GitWorkingCopy
619
     *
620
     * @throws \GitWrapper\GitException
621
     */
622 8
    public function branch()
623
    {
624 8
        $args = func_get_args();
625 8
        array_unshift($args, 'branch');
626 8
        return $this->run($args);
627
    }
628
629
    /**
630
     * Executes a `git checkout` command.
631
     *
632
     * Checkout a branch or paths to the working tree.
633
     *
634
     * @code
635
     * $git->checkout('new-branch', array('b' => true));
636
     * @endcode
637
     *
638
     * @param string ...
639
     *   (optional) Additional command line arguments.
640
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
641
     *   (optional) An associative array of command line options.
642
     *
643
     * @return \GitWrapper\GitWorkingCopy
644
     *
645
     * @throws \GitWrapper\GitException
646
     */
647 144
    public function checkout()
648
    {
649 144
        $args = func_get_args();
650 144
        array_unshift($args, 'checkout');
651 144
        return $this->run($args);
652
    }
653
654
    /**
655
     * Executes a `git clone` command.
656
     *
657
     * Clone a repository into a new directory. Use GitWorkingCopy::clone()
658
     * instead for more readable code.
659
     *
660
     * @code
661
     * $git->clone('git://github.com/cpliakas/git-wrapper.git');
662
     * @endcode
663
     *
664
     * @param string $repository
665
     *   The Git URL of the repository being cloned.
666
     * @param array $options
667
     *   (optional) An associative array of command line options.
668
     *
669
     * @param string $repository
670
     *   The URL of the repository being cloned.
671
     *
672
     * @return \GitWrapper\GitWorkingCopy
673
     *
674
     * @throws \GitWrapper\GitException
675
     */
676 148
    public function cloneRepository($repository, $options = array())
677
    {
678
        $args = array(
679 148
            'clone',
680 148
            $repository,
681 148
            $this->directory,
682 148
            $options,
683 148
        );
684 148
        return $this->run($args, false);
685
    }
686
687
    /**
688
     * Executes a `git commit` command.
689
     *
690
     * Record changes to the repository. If only one argument is passed, it is
691
     * assumed to be the commit message. Therefore `$git->commit('Message');`
692
     * yields a `git commit -am "Message"` command.
693
     *
694
     * @code
695
     * $git->commit('My commit message');
696
     * $git->commit('Makefile', array('m' => 'My commit message'));
697
     * @endcode
698
     *
699
     * @param string ...
700
     *   (optional) Additional command line arguments.
701
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
702
     *   (optional) An associative array of command line options.
703
     *
704
     * @return \GitWrapper\GitWorkingCopy
705
     *
706
     * @throws \GitWrapper\GitException
707
     */
708 148
    public function commit()
709
    {
710 148
        $args = func_get_args();
711 148
        if (isset($args[0]) && is_string($args[0]) && !isset($args[1])) {
712 148
            $args[0] = array(
713 148
                'm' => $args[0],
714 148
                'a' => true,
715
            );
716 148
        }
717 148
        array_unshift($args, 'commit');
718 148
        return $this->run($args);
719
    }
720
721
    /**
722
     * Executes a `git config` command.
723
     *
724
     * Get and set repository options.
725
     *
726
     * @code
727
     * $git->config('user.email', '[email protected]');
728
     * $git->config('user.name', 'Chris Pliakas');
729
     * @endcode
730
     *
731
     * @param string ...
732
     *   (optional) Additional command line arguments.
733
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
734
     *   (optional) An associative array of command line options.
735
     *
736
     * @return \GitWrapper\GitWorkingCopy
737
     *
738
     * @throws \GitWrapper\GitException
739
     */
740 144
    public function config()
741
    {
742 144
        $args = func_get_args();
743 144
        array_unshift($args, 'config');
744 144
        return $this->run($args);
745
    }
746
747
    /**
748
     * Executes a `git diff` command.
749
     *
750
     * Show changes between commits, commit and working tree, etc.
751
     *
752
     * @code
753
     * $git->diff();
754
     * $git->diff('topic', 'master');
755
     * @endcode
756
     *
757
     * @param string ...
758
     *   (optional) Additional command line arguments.
759
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
760
     *   (optional) An associative array of command line options.
761
     *
762
     * @return \GitWrapper\GitWorkingCopy
763
     *
764
     * @throws \GitWrapper\GitException
765
     */
766 4
    public function diff()
767
    {
768 4
        $args = func_get_args();
769 4
        array_unshift($args, 'diff');
770 4
        return $this->run($args);
771
    }
772
773
    /**
774
     * Executes a `git fetch` command.
775
     *
776
     * Download objects and refs from another repository.
777
     *
778
     * @code
779
     * $git->fetch('origin');
780
     * $git->fetch(array('all' => true));
781
     * @endcode
782
     *
783
     * @param string ...
784
     *   (optional) Additional command line arguments.
785
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
786
     *   (optional) An associative array of command line options.
787
     *
788
     * @return \GitWrapper\GitWorkingCopy
789
     *
790
     * @throws \GitWrapper\GitException
791
     */
792 4
    public function fetch()
793
    {
794 4
        $args = func_get_args();
795 4
        array_unshift($args, 'fetch');
796 4
        return $this->run($args);
797
    }
798
799
    /**
800
     * Executes a `git grep` command.
801
     *
802
     * Print lines matching a pattern.
803
     *
804
     * @code
805
     * $git->grep('time_t', '--', '*.[ch]');
806
     * @endcode
807
     *
808
     * @param string ...
809
     *   (optional) Additional command line arguments.
810
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
811
     *   (optional) An associative array of command line options.
812
     *
813
     * @return \GitWrapper\GitWorkingCopy
814
     *
815
     * @throws \GitWrapper\GitException
816
     */
817 4
    public function grep()
818
    {
819 4
        $args = func_get_args();
820 4
        array_unshift($args, 'grep');
821 4
        return $this->run($args);
822
    }
823
824
    /**
825
     * Executes a `git init` command.
826
     *
827
     * Create an empty git repository or reinitialize an existing one.
828
     *
829
     * @code
830
     * $git->init(array('bare' => true));
831
     * @endcode
832
     *
833
     * @param array $options
834
     *   (optional) An associative array of command line options.
835
     *
836
     * @return \GitWrapper\GitWorkingCopy
837
     *
838
     * @throws \GitWrapper\GitException
839
     */
840 148
    public function init(array $options = array())
841
    {
842
        $args = array(
843 148
            'init',
844 148
            $this->directory,
845 148
            $options,
846 148
        );
847 148
        return $this->run($args, false);
848
    }
849
850
    /**
851
     * Executes a `git log` command.
852
     *
853
     * Show commit logs.
854
     *
855
     * @code
856
     * $git->log(array('no-merges' => true));
857
     * $git->log('v2.6.12..', 'include/scsi', 'drivers/scsi');
858
     * @endcode
859
     *
860
     * @param string ...
861
     *   (optional) Additional command line arguments.
862
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
863
     *   (optional) An associative array of command line options.
864
     *
865
     * @return \GitWrapper\GitWorkingCopy
866
     *
867
     * @throws \GitWrapper\GitException
868
     */
869 8
    public function log()
870
    {
871 8
        $args = func_get_args();
872 8
        array_unshift($args, 'log');
873 8
        return $this->run($args);
874
    }
875
876
    /**
877
     * Executes a `git merge` command.
878
     *
879
     * Join two or more development histories together.
880
     *
881
     * @code
882
     * $git->merge('fixes', 'enhancements');
883
     * @endcode
884
     *
885
     * @param string ...
886
     *   (optional) Additional command line arguments.
887
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
888
     *   (optional) An associative array of command line options.
889
     *
890
     * @return \GitWrapper\GitWorkingCopy
891
     *
892
     * @throws \GitWrapper\GitException
893
     */
894 8
    public function merge()
895
    {
896 8
        $args = func_get_args();
897 8
        array_unshift($args, 'merge');
898 8
        return $this->run($args);
899
    }
900
901
    /**
902
     * Executes a `git mv` command.
903
     *
904
     * Move or rename a file, a directory, or a symlink.
905
     *
906
     * @code
907
     * $git->mv('orig.txt', 'dest.txt');
908
     * @endcode
909
     *
910
     * @param string $source
911
     *   The file / directory being moved.
912
     * @param string $destination
913
     *   The target file / directory that the source is being move to.
914
     * @param array $options
915
     *   (optional) An associative array of command line options.
916
     *
917
     * @return \GitWrapper\GitWorkingCopy
918
     *
919
     * @throws \GitWrapper\GitException
920
     */
921 4
    public function mv($source, $destination, array $options = array())
922
    {
923
        $args = array(
924 4
            'mv',
925 4
            $source,
926 4
            $destination,
927 4
            $options,
928 4
        );
929 4
        return $this->run($args);
930
    }
931
932
    /**
933
     * Executes a `git pull` command.
934
     *
935
     * Fetch from and merge with another repository or a local branch.
936
     *
937
     * @code
938
     * $git->pull('upstream', 'master');
939
     * @endcode
940
     *
941
     * @param string ...
942
     *   (optional) Additional command line arguments.
943
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
944
     *   (optional) An associative array of command line options.
945
     *
946
     * @return \GitWrapper\GitWorkingCopy
947
     *
948
     * @throws \GitWrapper\GitException
949
     */
950 4
    public function pull()
951
    {
952 4
        $args = func_get_args();
953 4
        array_unshift($args, 'pull');
954 4
        return $this->run($args);
955
    }
956
957
    /**
958
     * Executes a `git push` command.
959
     *
960
     * Update remote refs along with associated objects.
961
     *
962
     * @code
963
     * $git->push('upstream', 'master');
964
     * @endcode
965
     *
966
     * @param string ...
967
     *   (optional) Additional command line arguments.
968
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
969
     *   (optional) An associative array of command line options.
970
     *
971
     * @return \GitWrapper\GitWorkingCopy
972
     *
973
     * @throws \GitWrapper\GitException
974
     */
975 144
    public function push()
976
    {
977 144
        $args = func_get_args();
978 144
        array_unshift($args, 'push');
979 144
        return $this->run($args);
980
    }
981
982
    /**
983
     * Executes a `git rebase` command.
984
     *
985
     * Forward-port local commits to the updated upstream head.
986
     *
987
     * @code
988
     * $git->rebase('subsystem@{1}', array('onto' => 'subsystem'));
989
     * @endcode
990
     *
991
     * @param string ...
992
     *   (optional) Additional command line arguments.
993
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
994
     *   (optional) An associative array of command line options.
995
     *
996
     * @return \GitWrapper\GitWorkingCopy
997
     *
998
     * @throws \GitWrapper\GitException
999
     */
1000 4
    public function rebase()
1001
    {
1002 4
        $args = func_get_args();
1003 4
        array_unshift($args, 'rebase');
1004 4
        return $this->run($args);
1005
    }
1006
1007
    /**
1008
     * Executes a `git remote` command.
1009
     *
1010
     * Manage the set of repositories ("remotes") whose branches you track.
1011
     *
1012
     * @code
1013
     * $git->remote('add', 'upstream', 'git://github.com/cpliakas/git-wrapper.git');
1014
     * @endcode
1015
     *
1016
     * @param string ...
1017
     *   (optional) Additional command line arguments.
1018
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1019
     *   (optional) An associative array of command line options.
1020
     *
1021
     * @return \GitWrapper\GitWorkingCopy
1022
     *
1023
     * @throws \GitWrapper\GitException
1024
     */
1025 4
    public function remote()
1026
    {
1027 4
        $args = func_get_args();
1028 4
        array_unshift($args, 'remote');
1029 4
        return $this->run($args);
1030
    }
1031
1032
    /**
1033
     * Executes a `git reset` command.
1034
     *
1035
     * Reset current HEAD to the specified state.
1036
     *
1037
     * @code
1038
     * $git->reset(array('hard' => true));
1039
     * @endcode
1040
     *
1041
     * @param string ...
1042
     *   (optional) Additional command line arguments.
1043
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1044
     *   (optional) An associative array of command line options.
1045
     *
1046
     * @return \GitWrapper\GitWorkingCopy
1047
     *
1048
     * @throws \GitWrapper\GitException
1049
     */
1050 16
    public function reset()
1051
    {
1052 16
        $args = func_get_args();
1053 16
        array_unshift($args, 'reset');
1054 16
        return $this->run($args);
1055
    }
1056
1057
    /**
1058
     * Executes a `git rm` command.
1059
     *
1060
     * Remove files from the working tree and from the index.
1061
     *
1062
     * @code
1063
     * $git->rm('oldfile.txt');
1064
     * @endcode
1065
     *
1066
     * @param string $filepattern
1067
     *   Files to remove from version control. Fileglobs (e.g.  *.c) can be
1068
     *   given to add all matching files. Also a leading directory name (e.g.
1069
     *   dir to add dir/file1 and dir/file2) can be given to add all files in
1070
     *   the directory, recursively.
1071
     * @param array $options
1072
     *   (optional) An associative array of command line options.
1073
     *
1074
     * @return \GitWrapper\GitWorkingCopy
1075
     *
1076
     * @throws \GitWrapper\GitException
1077
     */
1078 4
    public function rm($filepattern, array $options = array())
1079
    {
1080
        $args = array(
1081 4
            'rm',
1082 4
            $filepattern,
1083 4
            $options,
1084 4
        );
1085 4
        return $this->run($args);
1086
    }
1087
1088
    /**
1089
     * Executes a `git show` command.
1090
     *
1091
     * Show various types of objects.
1092
     *
1093
     * @code
1094
     * $git->show('v1.0.0');
1095
     * @endcode
1096
     *
1097
     * @param string $object
1098
     *   The names of objects to show. For a more complete list of ways to spell
1099
     *   object names, see "SPECIFYING REVISIONS" section in gitrevisions(7).
1100
     * @param array $options
1101
     *   (optional) An associative array of command line options.
1102
     *
1103
     * @return \GitWrapper\GitWorkingCopy
1104
     *
1105
     * @throws \GitWrapper\GitException
1106
     */
1107 4
    public function show($object, array $options = array())
1108
    {
1109 4
        $args = array('show', $object, $options);
1110 4
        return $this->run($args);
1111
    }
1112
1113
    /**
1114
     * Executes a `git status` command.
1115
     *
1116
     * Show the working tree status.
1117
     *
1118
     * @code
1119
     * $git->status(array('s' => true));
1120
     * @endcode
1121
     *
1122
     * @param string ...
1123
     *   (optional) Additional command line arguments.
1124
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1125
     *   (optional) An associative array of command line options.
1126
     *
1127
     * @return \GitWrapper\GitWorkingCopy
1128
     *
1129
     * @throws \GitWrapper\GitException
1130
     */
1131 20
    public function status()
1132
    {
1133 20
        $args = func_get_args();
1134 20
        array_unshift($args, 'status');
1135 20
        return $this->run($args);
1136
    }
1137
1138
    /**
1139
     * Executes a `git tag` command.
1140
     *
1141
     * Create, list, delete or verify a tag object signed with GPG.
1142
1143
     * @code
1144
     * $git->tag('v1.0.0');
1145
     * @endcode
1146
     *
1147
     * @param string ...
1148
     *   (optional) Additional command line arguments.
1149
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1150
     *   (optional) An associative array of command line options.
1151
     *
1152
     * @return \GitWrapper\GitWorkingCopy
1153
     *
1154
     * @throws \GitWrapper\GitException
1155
     */
1156 144
    public function tag()
1157
    {
1158 144
        $args = func_get_args();
1159 144
        array_unshift($args, 'tag');
1160 144
        return $this->run($args);
1161
    }
1162
1163
    /**
1164
     * Executes a `git clean` command.
1165
     *
1166
     * Remove untracked files from the working tree
1167
     *
1168
     * @code
1169
     * $git->clean('-d', '-f');
1170
     * @endcode
1171
     *
1172
     * @param string ...
1173
     *   (optional) Additional command line arguments.
1174
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1175
     *   (optional) An associative array of command line options.
1176
     *
1177
     * @return \GitWrapper\GitWorkingCopy
1178
     *
1179
     * @throws \GitWrapper\GitException
1180
     */
1181 4
    public function clean()
1182
    {
1183 4
        $args = func_get_args();
1184 4
        array_unshift($args, 'clean');
1185 4
        return $this->run($args);
1186
    }
1187
1188
     /**
1189
     * Executes a `git archive` command.
1190
     *
1191
     * Create an archive of files from a named tree
1192
     *
1193
     * @code
1194
     * $git->archive('HEAD', array('o' => '/path/to/archive'));
1195
     * @endcode
1196
     *
1197
     * @param string ...
1198
     *   (optional) Additional command line arguments.
1199
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1200
     *   (optional) An associative array of command line options.
1201
     *
1202
     * @return \GitWrapper\GitWorkingCopy
1203
     *
1204
     * @throws \GitWrapper\GitException
1205
     */
1206 4
    public function archive()
1207
    {
1208 4
        $args = func_get_args();
1209 4
        array_unshift($args, 'archive');
1210 4
        return $this->run($args);
1211
    }
1212
1213
    /**
1214
     * @} End of "defgroup command".
1215
     */
1216
1217
    /**
1218
     * Hackish, allows us to use "clone" as a method name.
1219
     *
1220
     * $throws \BadMethodCallException
1221
     * @throws \GitWrapper\GitException
1222
     */
1223 148 View Code Duplication
    public function __call($method, $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1224
    {
1225 148
        if ('clone' == $method) {
1226 148
            return call_user_func_array(array($this, 'cloneRepository'), $args);
1227
        } else {
1228 4
            $class = get_called_class();
1229 4
            $message = "Call to undefined method $class::$method()";
1230 4
            throw new \BadMethodCallException($message);
1231
        }
1232
    }
1233
1234
    /**
1235
     * Gets the output captured by the last run Git commnd(s).
1236
     *
1237
     * @return string
1238
     *
1239
     * @see GitWorkingCopy::getOutput()
1240
     */
1241 88
    public function __toString()
1242
    {
1243 88
        return $this->getOutput();
1244
    }
1245
}
1246