Show an error message if the git or diff EXEs aren't working, bug #57
Show an error message if the git or diff EXEs aren't working, bug #57

--- a/include/git/DiffExe.class.php
+++ b/include/git/DiffExe.class.php
@@ -66,6 +66,19 @@
 	}
 
 	/**
+	 * GetBinary
+	 *
+	 * Gets the binary for this executable
+	 *
+	 * @return string binary
+	 * @access public
+	 */
+	public function GetBinary()
+	{
+		return $this->binary;
+	}
+
+	/**
 	 * GetUnified
 	 *
 	 * Gets whether diff is running in unified mode
@@ -174,6 +187,25 @@
 		$args[] = $toFile;
 
 		return shell_exec($this->binary . ' ' . implode(' ', $args));
+	}
+
+	/**
+	 * Valid
+	 *
+	 * Tests if this executable is valid
+	 *
+	 * @access public
+	 * @return boolean true if valid
+	 */
+	public function Valid()
+	{
+		if (empty($this->binary))
+			return false;
+
+		$code = 0;
+		$out = exec($this->binary . ' --version', $tmp, $code);
+
+		return $code == 0;
 	}
 
 	/**

--- a/include/git/GitExe.class.php
+++ b/include/git/GitExe.class.php
@@ -219,6 +219,25 @@
 	}
 
 	/**
+	 * Valid
+	 *
+	 * Tests if this executable is valid
+	 *
+	 * @access public
+	 * @return boolean true if valid
+	 */
+	public function Valid()
+	{
+		if (empty($this->binary))
+			return false;
+
+		$code = 0;
+		$out = exec($this->binary . ' --version', $tmp, $code);
+
+		return $code == 0;
+	}
+
+	/**
 	 * DefaultBinary
 	 *
 	 * Gets the default binary for the platform

file:a/index.php -> file:b/index.php
--- a/index.php
+++ b/index.php
@@ -46,6 +46,10 @@
 
 // Need this include for the compression constants used in the config file
 require_once(GITPHP_GITOBJECTDIR . 'Archive.class.php');
+
+// Test these executables early
+require_once(GITPHP_GITOBJECTDIR . 'GitExe.class.php');
+require_once(GITPHP_GITOBJECTDIR . 'DiffExe.class.php');
 
 date_default_timezone_set('UTC');
 
@@ -120,6 +124,19 @@
 	}
 
 	/*
+	 * Check for required executables
+	 */
+	$exe = new GitPHP_GitExe(null);
+	if (!$exe->Valid()) {
+		throw new GitPHP_MessageException(sprintf(__('Could not run the git executable "%1$s".  You may need to set the "gitbin" config value.'), $exe->GetBinary()), true, 500);
+	}
+	$exe = new GitPHP_DiffExe();
+	if (!$exe->Valid()) {
+		throw new GitPHP_MessageException(sprintf(__('Could not run the diff executable "%1$s".  You may need to set the "diffbin" config value.'), $exe->GetBinary()), true, 500);
+	}
+	unset($exe);
+
+	/*
 	 * Project list
 	 */
 	if (file_exists(GITPHP_CONFIGDIR . 'projects.conf.php')) {

comments