Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 510062 - Git log graph is broken on Node
When considering merge commits that affect a given file, a given
branch may be ignored if none of its changes matter for the given
file. In such a case, the common ancestor is used to record when the
code should stop ignoring commits. However, if a merge commit is
between two different unrelated histories, there will be no common
ancestors. In such a case, don't bother flagging the (null) common
ancestor as something to be recorded as the entire branch shall just
be ignored outright.

Signed-off-by: Remy Suen <remy.suen@gmail.com>
  • Loading branch information
rcjsuen committed Apr 22, 2017
1 parent 81097f2 commit 765bbd0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/orionode/lib/git/commit.js
Expand Up @@ -175,7 +175,9 @@ function getCommitLog(req, res) {
}
}
// mark the common ancestor as not to be skipped over
keep.push(base);
if (base !== null) {
keep.push(base);
}
return true;
}
}
Expand Down Expand Up @@ -217,6 +219,13 @@ function getCommitLog(req, res) {
parents.push(base);
return resolveAncestor(parents);
}
})
.catch(function(err) {
if (err.message === "No merge base found") {
// two commits in unrelated histories
return null;
}
throw err;
});
}
var commits = [] , repo;
Expand Down
77 changes: 77 additions & 0 deletions modules/orionode/test/test-git-api.js
Expand Up @@ -3105,6 +3105,83 @@ maybeDescribe("git", function() {
finished(err);
});
});

/**
* 1. Create a file in branch A in commit O.
* 2. Create the same file with the same content in branch B
* with a fresh history in commit O'.
* 3. Add an empty commit in branch B.
* 4. Merge branch B into branch A.
* 5. The returned history should only contain commit O.
*
* Actual repository history:
*
* M
* |\
* | \
* O U
* |
* O'
*
* Returned history for the file:
*
* O
*/
it("unrelated identical content", function(finished) {
var repository;
var initial, indexOid;
var name = "test.txt";

var client = new GitClient("graph-unrelated-identical-content");
client.init();
// create a file with content "A" in it
client.setFileContents(name, "A");
client.stage(name);
client.commit();
client.start().then(function(commit) {
initial = commit.Id;
// open the repository using NodeGit
var testPath = path.join(WORKSPACE, "graph-unrelated-identical-content");
return git.Repository.open(testPath);
})
.then(function(repo) {
repository = repo;
return repository.refreshIndex();
})
.then(function(index) {
// get the oid of the current repository state
return index.writeTree();
})
.then(function(oid) {
indexOid = oid;
// using that oid, create a commit in another branch with no parent commit
return repository.createCommit("refs/heads/other",
git.Signature.default(repository),
git.Signature.default(repository),
"unrelated", indexOid, [ ]);
})
.then(function(commit) {
return repository.createCommit("refs/heads/other",
git.Signature.default(repository),
git.Signature.default(repository),
"unrelated", indexOid, [ commit ])
})
.then(function() {
// merge in the branch with an unrelated history
client.merge("other");
client.log("master", "master", name);
return client.start();
})
.then(function(log) {
assert.equal(log.Children.length, 1);
assert.equal(log.Children[0].Id, initial);
assert.equal(log.Children[0].Parents.length, 1);
finished();
})
.catch(function(err) {
finished(err);
});
});
}) // describe("Graph");
}); // describe("Log")

Expand Down

0 comments on commit 765bbd0

Please sign in to comment.