Example #1
0
 /**
  * @expectedException \PHPGit\Exception\GitException
  * @expectedExceptionCode 128
  */
 public function testException()
 {
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $git->add('foo');
 }
Example #2
0
 public function testMergeAbort()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     // branch:master
     $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
     $git->add('test.txt');
     $git->commit('master');
     // branch:develop
     $git->checkout->create('develop');
     $filesystem->dumpFile($this->directory . '/test.txt', 'bar');
     $git->add('test.txt');
     $git->commit('develop');
     // branch:master
     $git->checkout('master');
     $filesystem->dumpFile($this->directory . '/test.txt', 'baz');
     $git->add('test.txt');
     $git->commit('master');
     try {
         $git->merge('develop');
         $this->fail('$git->merge("develop") should fail');
     } catch (Exception $e) {
     }
     $git->merge->abort();
     $this->assertEquals('baz', file_get_contents($this->directory . '/test.txt'));
 }
Example #3
0
 public function testRemotePrune()
 {
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
     $git->remote->prune('origin');
 }
Example #4
0
 public function testPull()
 {
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
     $git->pull('origin', 'master');
     $this->assertFileExists($this->directory . '/README.md');
 }
Example #5
0
 public function testFetchAll()
 {
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
     $git->fetch->all();
     $tags = $git->tag();
     $this->assertContains('v1.0.0', $tags);
 }
Example #6
0
 public function testShow()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/README.md', 'foobar');
     $git->add('README.md');
     $git->commit('Initial commit');
     $git->show('master', array('format' => 'oneline'));
 }
Example #7
0
 public function testSetUrlDelete()
 {
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $git->remote->add('origin', 'http://example.com/test.git');
     $git->remote->url->add('origin', 'https://github.com/kzykhys/Text.git');
     $git->remote->url->delete('origin', 'https://github.com');
     $remotes = $git->remote();
     $this->assertEquals('http://example.com/test.git', $remotes['origin']['fetch']);
 }
Example #8
0
 public function setUp()
 {
     parent::setUp();
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/test.txt', '');
     $git->add('test.txt');
     $git->commit('Initial commit');
 }
Example #9
0
 public function testMv()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
     $git->add('test.txt');
     $git->commit('Initial commit');
     $git->mv('test.txt', 'test2.txt');
     $this->assertFileExists($this->directory . '/test2.txt');
 }
Example #10
0
 public function testCommit()
 {
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem = new Filesystem();
     $filesystem->dumpFile($this->directory . '/test.txt', '');
     $git->add('test.txt');
     $git->commit('Initial commit');
     $logs = $git->log('test.txt');
     $this->assertCount(1, $logs);
 }
Example #11
0
 public function testCatSize()
 {
     $filesystem = new Filesystem();
     $filesystem->mkdir($this->directory);
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
     $git->add('test.txt');
     $git->commit('Initial commit');
     $tree = $git->tree();
     $this->assertEquals(3, $git->cat->size($tree[0]['hash']));
 }
Example #12
0
 public function testArchive()
 {
     $filesystem = new Filesystem();
     $filesystem->mkdir($this->directory);
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/test.txt', 'hello');
     $git->add('test.txt');
     $git->commit('Initial commit');
     $git->archive($this->directory . '/test.zip', 'master', null, array('format' => 'zip', 'prefix' => 'test/'));
     $this->assertFileExists($this->directory . '/test.zip');
 }
Example #13
0
 public function testCreateTagFromCommit()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/README.md', 'hello');
     $git->add('.');
     $git->commit('Initial commit');
     $log = $git->log(null, null, array('limit' => 1));
     $git->tag->create('v1.0.0', $log[0]['hash']);
     $this->assertCount(1, $git->tag());
 }
Example #14
0
 public function testRmCached()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/README.md', 'foo');
     $git->add('README.md');
     $git->commit('Initial commit');
     $git->rm->cached('README.md');
     $git->commit('Delete README.md');
     $this->assertFileExists($this->directory . '/README.md');
     $tree = $git->tree();
     $this->assertEquals(array(), $tree);
 }
Example #15
0
 public function testDetachedHeadStatus()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/item1.txt', '1');
     $git->add('item1.txt');
     $git->commit('initial commit');
     $logs = $git->log();
     $hash = $logs[0]['hash'];
     $git->checkout($hash);
     $status = $git->status();
     $this->assertEquals(null, $status['branch']);
 }
Example #16
0
 public function testPush()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory, array('shared' => true, 'bare' => true));
     $git->clone('file://' . realpath($this->directory), $this->directory . '2');
     $git->setRepository($this->directory . '2');
     $filesystem->dumpFile($this->directory . '2/test.txt', 'foobar');
     $git->add('test.txt');
     $git->commit('test');
     $git->push('origin', 'master');
     $git->clone('file://' . realpath($this->directory), $this->directory . '3');
     $this->assertFileExists($this->directory . '3/test.txt');
     $filesystem->remove($this->directory . '2');
     $filesystem->remove($this->directory . '3');
 }
Example #17
0
 public function testConfigAdd()
 {
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $before = $git->config();
     $git->config->set('user.name', 'John Doe');
     $git->config->add('user.name', 'Foo');
     $config = $git->config();
     $this->assertArrayHasKey('user.name', $config);
     $expected = "John Doe\nFoo";
     if (isset($before['user.name'])) {
         $expected = $before['user.name'] . "\n" . $expected;
     }
     $this->assertEquals($expected, $config['user.name']);
 }
Example #18
0
 public function testDescribeTags()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/README.md', 'hello');
     $git->add('README.md');
     $git->commit('Initial commit');
     $git->tag->create('v1.0.0');
     $version = $git->describe->tags('HEAD');
     $this->assertEquals('v1.0.0', $version);
     $filesystem->dumpFile($this->directory . '/README.md', 'hello2');
     $git->add('README.md');
     $git->commit('Fixes README');
     $version = $git->describe->tags('HEAD');
     $this->assertStringStartsWith('v1.0.0', $version);
     $this->assertStringEndsNotWith('v1.0.0', $version);
 }
Example #19
0
 public function testShortlogSummary()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $git->config->set('user.name', 'Name One');
     $git->config->set('user.email', '*****@*****.**');
     $filesystem->dumpFile($this->directory . '/test.txt', '');
     $git->add('test.txt');
     $git->commit('1');
     $filesystem->dumpFile($this->directory . '/test2.txt', '');
     $git->add('test2.txt');
     $git->commit('2');
     $git->config->set('user.name', 'Name Two');
     $git->config->set('user.email', '*****@*****.**');
     $filesystem->dumpFile($this->directory . '/test3.txt', '');
     $git->add('test3.txt');
     $git->commit('3');
     $summary = $git->shortlog->summary();
     $this->assertEquals(array('Name One <*****@*****.**>' => 2, 'Name Two <*****@*****.**>' => 1), $summary);
 }
Example #20
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testResetInvalidMode()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/README.md', 'foo');
     $git->add('README.md');
     $git->commit('Initial commit');
     $filesystem->dumpFile($this->directory . '/README.md', 'hello');
     $git->reset->mode('foo');
 }
Example #21
0
 public function testStashCreate()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/README.md', 'hello');
     $git->add('.');
     $git->commit('Initial commit');
     $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
     $object = $git->stash->create();
     $this->assertNotEmpty($object);
 }
Example #22
0
 public function testRebaseSkip()
 {
     $filesystem = new Filesystem();
     $git = new Git();
     $git->init($this->directory);
     $git->setRepository($this->directory);
     $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
     $git->add('test.txt');
     $git->commit('initial commit');
     $git->checkout->create('next');
     $filesystem->dumpFile($this->directory . '/test.txt', 'bar');
     $git->add('test.txt');
     $git->commit('next commit');
     $git->checkout('master');
     $filesystem->dumpFile($this->directory . '/test.txt', 'baz');
     $git->add('test.txt');
     $git->commit('master commit');
     try {
         $git->rebase('next');
         $this->fail('GitException should be thrown');
     } catch (\PHPGit\Exception\GitException $e) {
     }
     $git->rebase->skip();
 }