private $status;
private $relativeCommit = null;
+ private $repositoryHasNoCommits = false;
const SEARCH_LENGTH_FOR_PARENT_REVISIONS = 16;
/**
return 'git';
}
+ public function getHasCommits() {
+ return !$this->repositoryHasNoCommits;
+ }
+
public function setRelativeCommit($relative_commit) {
$this->relativeCommit = $relative_commit;
return $this;
}
public function getLocalCommitInformation() {
+ if ($this->repositoryHasNoCommits) {
+ // Zero commits.
+ throw new Exception(
+ "You can't get local commit information for a repository with no ".
+ "commits.");
+ } else if ($this->relativeCommit == self::GIT_MAGIC_ROOT_COMMIT) {
+ // One commit.
+ $against = 'HEAD';
+ } else {
+ // 2..N commits.
+ $against = $this->getRelativeCommit().'..HEAD';
+ }
+
list($info) = execx(
- '(cd %s && git log %s..%s --format=%s --)',
+ '(cd %s && git log %s --format=%s --)',
$this->getPath(),
- $this->getRelativeCommit(),
- 'HEAD',
+ $against,
'%H%x00%T%x00%P%x00%at%x00%an%x00%s');
$commits = array();
'(cd %s; git rev-parse --verify HEAD^)',
$this->getPath());
if ($err) {
+ list($err) = exec_manual(
+ '(cd %s; git rev-parse --verify HEAD)',
+ $this->getPath());
+ if ($err) {
+ $this->repositoryHasNoCommits = true;
+ }
$this->relativeCommit = self::GIT_MAGIC_ROOT_COMMIT;
+
} else {
$this->relativeCommit = 'HEAD^';
}
public function getGitCommitLog() {
$relative = $this->getRelativeCommit();
- if ($relative == self::GIT_MAGIC_ROOT_COMMIT) {
+ if ($this->repositoryHasNoCommits) {
+ // No commits yet.
+ return '';
+ } else if ($relative == self::GIT_MAGIC_ROOT_COMMIT) {
+ // First commit.
list($stdout) = execx(
'(cd %s; git log --format=medium HEAD)',
$this->getPath());
} else {
+ // 2..N commits.
list($stdout) = execx(
'(cd %s; git log --first-parent --format=medium %s..HEAD)',
$this->getPath(),
// Find uncommitted changes.
$uncommitted_future = new ExecFuture(
- "(cd %s; git diff {$options} --raw HEAD --)",
- $this->getPath());
+ "(cd %s; git diff {$options} --raw %s --)",
+ $this->getPath(),
+ $this->repositoryHasNoCommits
+ ? self::GIT_MAGIC_ROOT_COMMIT
+ : 'HEAD');
// Untracked files
$untracked_future = new ExecFuture(
$base);
if ($err) {
throw new ArcanistUsageException(
- "Unable to parse git commit name '{$base}'.");
+ "Unable to find any git commit named '{$base}' in this repository.");
}
}
$this->setRelativeCommit(trim($merge_base));
$repository_api,
$paths);
} else if ($repository_api instanceof ArcanistGitAPI) {
-
$diff = $repository_api->getFullGitDiff();
if (!strlen($diff)) {
- list($base, $tip) = $repository_api->getCommitRange();
- if ($tip == 'HEAD') {
- if (preg_match('/\^+HEAD/', $base)) {
- $more = 'Did you mean HEAD^ instead of ^HEAD?';
- } else {
- $more = 'Did you specify the wrong relative commit?';
- }
- } else {
- $more = 'Did you specify the wrong commit range?';
- }
- throw new ArcanistUsageException("No changes found. ({$more})");
+ throw new ArcanistUsageException(
+ "No changes found. (Did you specify the wrong commit range?)");
}
$changes = $parser->parseDiff($diff);
-
} else if ($repository_api instanceof ArcanistMercurialAPI) {
$diff = $repository_api->getFullMercurialDiff();
$changes = $parser->parseDiff($diff);
$parser = new ArcanistDiffParser();
$commit_messages = $repository_api->getGitCommitLog();
+
+ if (!strlen($commit_messages)) {
+ if (!$repository_api->getHasCommits()) {
+ throw new ArcanistUsageException(
+ "This git repository doesn't have any commits yet. You need to ".
+ "commit something before you can diff against it.");
+ } else {
+ throw new ArcanistUsageException(
+ "The commit range doesn't include any commits. (Did you diff ".
+ "against the wrong commit?)");
+ }
+ }
+
$commit_messages = $parser->parseDiff($commit_messages);
$problems = array();