Skip to content

Commit

Permalink
Fix up some file listing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bobfloats committed May 4, 2016
1 parent dc39659 commit 03f6a35
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 14 deletions.
27 changes: 25 additions & 2 deletions src/VersionControl/GitCommandBundle/Entity/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,47 @@ class FileInfo extends \SplFileInfo{
*/
protected $gitLog;


/**
* Gets the git log for the file
* @return \VersionControl\GitCommandBundle\Entity\GitLog
*/
public function getGitLog() {
return $this->gitLog;
}

/**
* Sets the git log for the file
* @param \VersionControl\GitCommandBundle\Entity\GitLog $gitLog
* @return \VersionControl\GitCommandBundle\Entity\FileInfo
*/
public function setGitLog(GitLog $gitLog) {
$this->gitLog = $gitLog;
return $this;
}

/**
* Gets absolute path to file. Wrapper for SplFileInfo::getRealPath
*
* @link http://php.net/manual/en/splfileinfo.getrealpath.php
* @return string
*/
public function getFullPath() {
return $this->getRealPath();
}


/**
* Gets the file path relative to the .git folder
* @return string
*/
public function getGitPath() {
return $this->gitPath;
}

/**
* Sets the file path relative to the .git folder
* @param string $gitPath
* @return \VersionControl\GitCommandBundle\Entity\FileInfo
*/
public function setGitPath($gitPath) {
$this->gitPath = $gitPath;
return $this;
Expand Down
35 changes: 31 additions & 4 deletions src/VersionControl/GitCommandBundle/Entity/RemoteFileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,45 @@
class RemoteFileInfo{

/**
* File full path to file
* Absolute path to file
* @var string
*/
protected $fullPath;

/**
* File Extension
* @var string
*/
protected $extension;

/**
* File name without any path information
* @var string
*/
protected $filename;

/**
* Path without the filename
* @var string
*/
protected $path;

/**
* File permissions
* @var string
*/
protected $perms;

/**
* Filesize in bytes
* @var integer
*/
protected $size;

/**
*
* @var type
*/
protected $uid;
protected $gid;
protected $mode;
Expand All @@ -40,9 +69,7 @@ class RemoteFileInfo{

protected $gitPath;





/**
* Git log Entity
* @var GitLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ protected function getFileInfo($path){


$fileData = $sftp->stat($basePath.$path);
$fileData['filename'] = basename($path);
$fileData['fullPath'] = $basePath.$path;
$fileData['gitPath'] = $basePath.$path;
$fileData['gitPath'] = $path;
$fileInfo = new RemoteFileInfo($fileData);

}else{
Expand Down Expand Up @@ -168,7 +169,7 @@ public function getFilesInDirectory($dir){

foreach($sftp->rawlist($basePath.$relativePath) as $filename => $fileData) {
if($filename !== '.' && $filename !== '..' && $filename !== '.git'){
$fileData['fullPath'] = rtrim($relativePath,'/').'/'.$filename;
$fileData['fullPath'] = $basePath.rtrim($relativePath,'/').'/'.$filename;
$fileData['gitPath'] = $relativePath.$filename;

$remoteFileInfo = new RemoteFileInfo($fileData);
Expand Down Expand Up @@ -386,7 +387,7 @@ public function filePathIsIgnored($filePath){
public function getGitIgnoreFile(){
$ignoreFiles = array();


$basePath = trim($this->addEndingSlash($this->command->getGitEnvironment()->getPath()));
$fileData['fullPath'] = '.gitignore';
$fileData['gitPath'] = '.gitignore';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,24 @@ public function fileListAction($id,$currentDir = ''){
public function viewFileAction($id,$currentFile = ''){
$filePath = '';
$dir = '';
$currentDir = '';
if($currentFile){
$filePath = trim(urldecode($currentFile));


$file = $this->gitFilesCommands->getFile($filePath, $this->branchName);

$fileContents = $this->gitFilesCommands->readFile($file);

$pathParts = pathinfo($filePath);
$dir = $pathParts['dirname'];

$pathParts = pathinfo($filePath);
$currentDir = ($pathParts['dirname'] !== '.')?$pathParts['dirname']:'';
}

return array_merge($this->viewVariables, array(
'currentDir' => $filePath,
'currentDir' => $currentDir,
'filePath' => $filePath,
'fileContents' => $fileContents,
'file' => $file
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
{% if(currentDir) %}
<div class="list-group-item">
<div class="row">
<div class="col-md-12">

<div class="col-md-12">
<a href="{{ path('project_filelist', { 'id': project.id, 'currentDir': currentDir|parentDir() | url_encode()})}}" title="Back to {{currentDir|parentDir()}}">
<strong class="str-truncated">..</strong>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,25 @@
<div class="box-body">
<p>Shows file contents of the current working directory.</p>
<div class="list-group">
<div class="list-group-item">
<div class="row">
<div class="col-md-12">
{% if(currentDir) %}
<a href="{{ path('project_filelist', { 'id': project.id, 'currentDir': currentDir | url_encode()})}}" title="Back to /{{currentDir}}">
<strong class="str-truncated">Back to /{{currentDir}}</strong>
</a>
{% else %}
<a href="{{ path('project_filelist', { 'id': project.id})}}" title="Back to home folder">
<strong class="str-truncated">Back to /</strong>
</a>
{% endif %}
</div>
</div>
</div>
<div class="list-group-item">
<div class="row">
<div class="col-md-12">
<strong>Path:</strong>/{{currentDir}}
<strong>Path:</strong>/{{filePath}}
</div>
</div>
</div>
Expand Down

0 comments on commit 03f6a35

Please sign in to comment.