If it doesn\'t exist you can initiate a blank repository by clicking here or you can clone a remote repo over here' ); ?>
Click here to view your SSH key. If an SSH key cannot be found in the SSH path specified above, AceIDE will create this key for you. You\'ll need to pass this key to github or any other services/servers you need Git push access to.' ); ?>
setPublicKeyFormat( 'OPENSSH' );
extract( $rsa->createKey() ); // == $rsa->createKey(1024) where 1024 is the key size - $privatekey and $publickey
// create private key
file_put_contents( $gitpath . "/id_rsa", $privatekey );
chmod( $gitpath . "/id_rsa", 0700 );
// create public key
file_put_contents( $gitpath . "/id_rsa.pub", $publickey );
chmod( $gitpath . "/id_rsa.pub", 0700 );
}
// return public key
echo "\n\n" . file_get_contents( $gitpath . "/id_rsa.pub" ) . "\n\n";
die();
}
protected function git_open_repo() {
// check the user has the permissions
IDE::check_perms();
// errors need to be on while experimental
error_reporting( E_ALL );
ini_set( "display_errors", 1 );
$root = apply_filters( 'aceide_filesystem_root', WP_CONTENT_DIR );
$root = trailingslashit($root);
// check repo path entered or die
if ( ! strlen( $_POST['gitpath'] ) ) {
die( __( "Error: Path to your git repository is required! (see settings)" ) );
}
$this->git_repo_path = $root . sanitize_text_field( $_POST['gitpath'] );
$gitbinary = sanitize_text_field( stripslashes( $_POST['gitbinary'] ) );
/*
if ( $gitbinary==="I'll guess.." ) { // the binary path
$thebinary = TQ\Git\Cli\Binary::locateBinary();
$this->git = TQ\Git\Repository\Repository::open( $this->git_repo_path, new TQ\Git\Cli\Binary( $thebinary ), 0755 );
} else {
$thebinary = $_POST['gitbinary'];
$this->git = TQ\Git\Repository\Repository::open( $this->git_repo_path, new TQ\Git\Cli\Binary( $thebinary ), 0755 );
}
*/
}
public function git_status() {
// check the user has the permissions
IDE::check_perms();
$this->git_open_repo(); // make sure git repo is open
// echo branch
$branch = $this->git->getCurrentBranch();
echo '
';
die(); // this is required to return a proper result
}
public function git_log() {
// check the user has the permissions
IDE::check_perms();
$this->git_open_repo(); // make sure git repo is open
$log = $this->git->getLog(50);
echo '
";
die(); // this is required to return a proper result
}
public function git_init() {
// check the user has the permissions
IDE::check_perms();
$this->git_open_repo(); // make sure git repo is open
// create the local repo path if it doesn't exist
if ( ! file_exists( $this->git->getRepositoryPath() ) ) {
mkdir( $this->git->getRepositoryPath() );
}
$result = $this->git->getBinary()->{'init'}( $this->git->getRepositoryPath(), array(
// What do we put here?
) );
// return $result->getStdOut(); // still not getting enough output from the push...
if ( $result->getStdErr() === '' ) {
echo $result->getStdOut();
} else {
echo $result->getStdErr();
}
die(); // this is required to return a proper result
}
public function git_clone() {
// check the user has the permissions
IDE::check_perms();
$this->git_open_repo(); // make sure git repo is open
// just incase it's a private repo we will setup the keys
$sshpath = preg_replace( "#/$#", "", $_POST['sshpath'] ); // get path replacing end slash if entered
putenv( 'GIT_SSH=' . plugin_dir_path( __FILE__ ) . 'git-wrapper-nohostcheck.sh' ); // tell Git about our wrapper script
/* See note on git_push re wrapper */
putenv( 'ACEIDE_SSH_PATH=' . $sshpath ); // no trailing slash - pass wp-content path to Git wrapper script
putenv( 'HOME='. plugin_dir_path( __FILE__ ) . 'git' ); // no trailing slash - set home to the git directory (this may not be needed)
if ( $_POST['repo_path'] === '' || is_null( $_POST['repo_path'] ) ) {
echo '' . __( 'It will be cloned into the repository path/folder defined in the Git settings.' ) . '
';
die();
}
$path = sanitize_text_field( $_POST['repo_path'] );
// create the local repo path if it doesn't exist
if ( ! file_exists( $this->git->getRepositoryPath() ) ) {
mkdir( $this->git->getRepositoryPath() );
}
$result = $this->git->getBinary()->{'clone'}( $this->git->getRepositoryPath(), array (
$path,
$this->git->getRepositoryPath(),
'--recursive'
) );
// return $result->getStdOut(); // still not getting enough output from the push...
if ( $result->getStdErr() === '' ) {
$result = $result->getStdOut();
// format the output a little better
$result = str_replace( '...', '... ', $result );
echo $result;
} else {
echo $result->getStdErr();
}
die(); // this is required to return a proper result
}
public function git_push() {
// check the user has the permissions
IDE::check_perms();
$this->git_open_repo(); // make sure git repo is open
$sshpath = preg_replace( "#/$#", "", $_POST['sshpath'] ); // get path replacing end slash if entered
putenv( 'GIT_SSH=' . plugin_dir_path( __FILE__ ) . 'git-wrapper-nohostcheck.sh' ); // tell Git about our wrapper script
/*
The wrapper we use above doesn't do a host check which means we can't guarentee the other side is who we think it is
We have this other wrapper which does a host check which we should swap to after the initial push/connection has been made
and the entry automatically added to known hosts but that logic isn't in place yet.
putenv("GIT_SSH=". plugin_dir_path(__FILE__) . 'git/git-wrapper.sh');
*/
putenv( 'ACEIDE_SSH_PATH=' . $sshpath ); // no trailing slash - pass wp-content path to Git wrapper script
putenv( 'HOME=' . plugin_dir_path( __FILE__ ) . 'git' ); // no trailing slash - set home to the git directory (this may not be needed)
echo '
';
$push_result = $this->git->push();
echo '
';
if ( $push_result === '' ) {
echo __( "Sucessfully pushed to your remote repo" );
} else {
echo $push_result;
}
echo __( "
Git push completed.
" );
die(); // this is required to return a proper result
}
public function git_diff() {
// check the user has the permissions
IDE::check_perms();
$this->git_open_repo(); // make sure git repo is open
$file = sanitize_text_field( base64_decode( $_POST['file']) );
$result = $this->git->getBinary()->{'diff'}( $this->git->getRepositoryPath(), array (
$file
));
// return $result->getStdOut(); // still not getting enough output from the push...
if ( $result->getStdErr() === '' ) {
$diff_lines = explode( "\n", $result->getStdOut() );
foreach ( $diff_lines as $a_line ) {
if ( preg_match( "#^\+#", $a_line ) ) {
$a_class = 'plus';
} elseif ( preg_match("#^\-#", $a_line ) ) {
$a_class = 'minus';
} else {
$a_class = '';
}
echo "{$a_line}";
}
} else {
echo $result->getStdErr();
}
echo '' . __( 'Diff' ) . '' . $diff_table;
die(); // this is required to return a proper result
}
public function git_commit() {
// check the user has the permissions
IDE::check_perms();
$this->git_open_repo(); // make sure git repo is open
// putenv("GIT_AUTHOR_NAME=AceIDE"); // author can be set using env but for now we set it during the commit
// putenv("GIT_AUTHOR_EMAIL=shanept@iinet.net.au");
putenv( "GIT_COMMITTER_NAME=AceIDE" ); // commiter details, shows under author on github
putenv( "GIT_COMMITTER_EMAIL=shanept@iinet.net.au" );
$files = array();
foreach ( $_POST['files'] as $file ) {
$files[] = base64_decode( $file );
}
// get the current user to be used for the commit
$current_user = wp_get_current_user();
$this->git->add( $files );
$this->git->commit( sanitize_text_field( stripslashes( $_POST['gitmessage'] ) ) , $files, "{$current_user->user_firstname} {$current_user->user_lastname} <{$current_user->user_email}>" );
// output our status
$this->git_status();
die(); // this is required to return a proper result
}
}