Allow Diffusion to display the initial commit in Git repositories
Summary: See T507. Since you can't do "xxxxxxxx^" where "xxxxxxxx" is the first commit in a repository, fall back to diffing against the empty tree if we fail to diff against the parent commit. Test Plan: Looked at the first commit in libphutil on my local. Reviewers: edward, jungejason, nh, tuomaspelkonen, aran Reviewed By: nh CC: aran, edward, epriestley, nh Differential Revision: 953
This commit is contained in:
@@ -44,12 +44,36 @@ final class DiffusionGitDiffQuery extends DiffusionDiffQuery {
|
||||
);
|
||||
$options = implode(' ', $options);
|
||||
|
||||
list($raw_diff) = execx(
|
||||
"(cd %s && git diff {$options} %s^ %s -- %s)",
|
||||
$repository->getDetail('local-path'),
|
||||
$effective_commit,
|
||||
$effective_commit,
|
||||
$drequest->getPath());
|
||||
try {
|
||||
list($raw_diff) = execx(
|
||||
"(cd %s && git diff %C %s^ %s -- %s)",
|
||||
$repository->getDetail('local-path'),
|
||||
$options,
|
||||
$effective_commit,
|
||||
$effective_commit,
|
||||
$drequest->getPath());
|
||||
} catch (CommandException $ex) {
|
||||
// Check if this is the root commit by seeing if it has parents.
|
||||
list($parents) = execx(
|
||||
'(cd %s && git log --format=%s %s --)',
|
||||
$repository->getDetail('local-path'),
|
||||
'%P', // "parents"
|
||||
$effective_commit);
|
||||
if (!strlen(trim($parents))) {
|
||||
// No parents means we're looking at the root revision. Diff against
|
||||
// the empty tree hash instead, since there is no parent so "^" does
|
||||
// not work. See ArcanistGitAPI for more discussion.
|
||||
list($raw_diff) = execx(
|
||||
'(cd %s && git diff %C %s %s -- %s)',
|
||||
$repository->getDetail('local-path'),
|
||||
$options,
|
||||
ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT,
|
||||
$effective_commit,
|
||||
$drequest->getPath());
|
||||
} else {
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
$parser = new ArcanistDiffParser();
|
||||
$parser->setDetectBinaryFiles(true);
|
||||
|
||||
Reference in New Issue
Block a user