public function indexAction() { $result = ''; $request = $this->getRequest(); $io = new RawIO(); //handle file navagation $validFile = false; $fileNavigation = new FileNavigation(); $branchNavigation = new BranchNavigation(); $historyNavigation = new HistoryNavigation(); $remotes = new Remotes(); $remotes->setUid($this->_user->loggedIn->uid); $status = new Status(); $status->setUid($this->_user->loggedIn->uid); $git = new Git(); if ($request->isGet()) { //===begin file navigation=== if ($request->getQuery('updir') != NULL) { $updirs = (int) $request->getQuery('updir'); $fileNavigation->upDir($updirs); } if ($request->getQuery('dir') != NULL) { $fileNavigation->enterDir($request->getQuery('dir')); } if ($request->getQuery('file') != NULL) { if ($fileNavigation->validFile($request->getQuery('file'))) { $io->setFile($fileNavigation->getPath(), $request->getQuery('file')); $status->addStatus('open: /' . $fileNavigation->getDir() . $request->getQuery('file')); } } //===end file navigation=== if ($request->getQuery('branch') != NULL) { $result = $branchNavigation->setBranch($request->getQuery('branch')); $status->addStatus('branch: ' . $request->getQuery('branch')); } if ($request->getQuery('sha') != NULL) { $result = $historyNavigation->setRev($request->getQuery('sha')); $status->addStatus('history: ' . $request->getQuery('sha')); } //===begin merger=== if ($request->getQuery('merge') != NULL) { $result = $git->merge($request->getQuery('merge')); $status->addStatus('merge: ' . $request->getQuery('merge')); } if ($request->getQuery('pull') != NULL) { $result = $remotes->pullRemote($request->getQuery('pull')); $status->addStatus('pull: ' . $request->getQuery('pull')); } if ($request->getQuery('avail') != NULL) { $result = $remotes->addRemote($request->getQuery('avail')); $status->addStatus('add remote: ' . $request->getQuery('avail')); } //===end merger=== } if (isset($_POST['code'])) { $code = $_POST['code']; if ($io->getFile() !== NULL) { $io->saveContent($code); $status->addStatus('save: ' . $io->getFile()); } if (isset($_POST['commitMessage']) && $_POST['commitMessage'] != '') { $msg = $_POST['commitMessage']; $result = $git->autoCommit($msg); $status->addStatus('commit: ' . $msg); } } $this->view->result = $result; $this->view->content = $io->getContent(); $this->view->editing = $io->getFile(); $this->view->path = '/' . $fileNavigation->getDir(); $this->view->files = $fileNavigation->ls(); $this->view->branch = $branchNavigation->getActiveBranch(); $this->view->branches = $branchNavigation->getBranches(); $this->view->state = $branchNavigation->getState(); $this->view->history = $historyNavigation->getHistory(); $this->view->headName = $historyNavigation->getHeadName(); $this->view->status = $status->getStatusMessages(); $this->view->avail = $remotes->getRepos(); $this->view->remotes = $remotes->getRemotes(); $this->view->newFileForm = new NewFileForm(); $this->view->newDirForm = new NewDirForm(); $this->view->newBranchForm = new NewBranchForm(); }
function testMergeFromFork() { $Cleanup = new Folder(TMP . 'tests/git'); if ($Cleanup->pwd() == TMP . 'tests/git') { $Cleanup->delete(); } $Git = new Git($this->__repos[1]); $this->assertTrue($Git->create()); $this->assertTrue(file_exists(TMP . 'tests/git/repo/test.git')); $this->assertTrue(file_exists(TMP . 'tests/git/working/test/master/.git')); $result = $Git->fork("gwoo"); $this->assertTrue(file_exists(TMP . 'tests/git/repo/forks/gwoo/test.git')); $this->assertTrue(file_exists(TMP . 'tests/git/working/forks/gwoo/test/master/.git')); $File = new File(TMP . 'tests/git/working/forks/gwoo/test/master/new.text', true); $File->write('this is something new'); $Git->commit(array("-m", "'Pushing to fork'")); $Git->push('origin', 'master'); $Git = new Git($this->__repos[1]); $File = new File(TMP . 'tests/git/working/test/master/other.text', true); $File->write('this is something elese is new'); $Git->commit(array("-m", "'Pushing to parent'")); $Git->push('origin', 'master'); /* $Git->update('origin', 'master'); $Git->before(array("cd {$Git->working}")); $Git->remote(array('add', 'gwoo', TMP . 'tests/git/repo/forks/gwoo/test.git')); $Git->update('gwoo', 'master'); $Git->push('origin', 'master'); */ $Git->logResponse = true; $Git->merge('test', 'gwoo'); $this->assertTrue(file_exists(TMP . 'tests/git/working/test/master/new.text')); $this->assertTrue(file_exists(TMP . 'tests/git/working/test/master/other.text')); $data = $Git->read(); $this->assertTrue($data['message'], 'Merge from forks/gwoo/test.git'); //pr($Git->debug); //pr($Git->response); }
break; case 'renameBranch': if (isset($_GET['path']) && isset($_GET['name']) && isset($_GET['newName'])) { $result = $git->renameBranch(getWorkspacePath($_GET['path']), $_GET['name'], $_GET['newName']); if ($result === false) { echo '{"status":"error","message":"Failed to rename branch!"}'; } else { echo '{"status":"success","message":"Branch renamed!"}'; } } else { echo '{"status":"error","message":"Missing parameter!"}'; } break; case 'merge': if (isset($_GET['path']) && isset($_GET['name'])) { $result = $git->merge(getWorkspacePath($_GET['path']), $_GET['name']); if ($result === false) { echo '{"status":"error","message":"Failed to merge branch!"}'; } else { echo '{"status":"success","message":"Branch merged!"}'; } } else { echo '{"status":"error","message":"Missing parameter!"}'; } break; case 'push': if (isset($_GET['path']) && isset($_GET['remote']) && isset($_GET['branch'])) { echo $git->push(getWorkspacePath($_GET['path']), $_GET['remote'], $_GET['branch']); } else { echo '{"status":"error","message":"Missing parameter!"}'; }