RepoCommand: don't record new commit if tree did not change
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Change-Id: Ib6509e816684256d723558d5e8f3c37de58a2ff8
This commit is contained in:
parent
446a7096ef
commit
3214171dec
|
@ -185,6 +185,59 @@ public byte[] readFile(String uri, String refName, String path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void runTwiceIsNOP() throws Exception {
|
||||||
|
Repository child = Git.cloneRepository()
|
||||||
|
.setURI(groupADb.getDirectory().toURI().toString())
|
||||||
|
.setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
|
||||||
|
.getRepository();
|
||||||
|
|
||||||
|
Repository dest = Git.cloneRepository()
|
||||||
|
.setURI(db.getDirectory().toURI().toString())
|
||||||
|
.setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
|
||||||
|
.getRepository();
|
||||||
|
|
||||||
|
assertTrue(dest.isBare());
|
||||||
|
assertTrue(child.isBare());
|
||||||
|
|
||||||
|
StringBuilder xmlContent = new StringBuilder();
|
||||||
|
xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
|
||||||
|
.append("<manifest>")
|
||||||
|
.append("<remote name=\"remote1\" fetch=\"..\" />")
|
||||||
|
.append("<default revision=\"master\" remote=\"remote1\" />")
|
||||||
|
.append("<project path=\"base\" name=\"platform/base\" />")
|
||||||
|
.append("</manifest>");
|
||||||
|
RepoCommand cmd = new RepoCommand(dest);
|
||||||
|
|
||||||
|
IndexedRepos repos = new IndexedRepos();
|
||||||
|
repos.put("platform/base", child);
|
||||||
|
|
||||||
|
RevCommit commit = cmd
|
||||||
|
.setInputStream(new ByteArrayInputStream(
|
||||||
|
xmlContent.toString().getBytes(UTF_8)))
|
||||||
|
.setRemoteReader(repos)
|
||||||
|
.setURI("platform/")
|
||||||
|
.setTargetURI("platform/superproject")
|
||||||
|
.setRecordRemoteBranch(true)
|
||||||
|
.setRecordSubmoduleLabels(true)
|
||||||
|
.call();
|
||||||
|
|
||||||
|
String firstIdStr = commit.getId().name() + ":" + ".gitmodules";
|
||||||
|
commit = new RepoCommand(dest)
|
||||||
|
.setInputStream(new ByteArrayInputStream(
|
||||||
|
xmlContent.toString().getBytes(UTF_8)))
|
||||||
|
.setRemoteReader(repos)
|
||||||
|
.setURI("platform/")
|
||||||
|
.setTargetURI("platform/superproject")
|
||||||
|
.setRecordRemoteBranch(true)
|
||||||
|
.setRecordSubmoduleLabels(true)
|
||||||
|
.call();
|
||||||
|
String idStr = commit.getId().name() + ":" + ".gitmodules";
|
||||||
|
assertEquals(firstIdStr, idStr);
|
||||||
|
child.close();
|
||||||
|
dest.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void androidSetup() throws Exception {
|
public void androidSetup() throws Exception {
|
||||||
Repository child = Git.cloneRepository()
|
Repository child = Git.cloneRepository()
|
||||||
|
@ -235,6 +288,7 @@ public void androidSetup() throws Exception {
|
||||||
child.close();
|
child.close();
|
||||||
dest.close();
|
dest.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void recordUnreachableRemotes() throws Exception {
|
public void recordUnreachableRemotes() throws Exception {
|
||||||
StringBuilder xmlContent = new StringBuilder();
|
StringBuilder xmlContent = new StringBuilder();
|
||||||
|
@ -277,8 +331,6 @@ public void recordUnreachableRemotes() throws Exception {
|
||||||
dest.close();
|
dest.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void gerritSetup() throws Exception {
|
public void gerritSetup() throws Exception {
|
||||||
Repository child =
|
Repository child =
|
||||||
|
|
|
@ -643,6 +643,11 @@ public RevCommit call() throws GitAPIException {
|
||||||
|
|
||||||
// Create a Commit object, populate it and write it
|
// Create a Commit object, populate it and write it
|
||||||
ObjectId headId = repo.resolve(targetBranch + "^{commit}"); //$NON-NLS-1$
|
ObjectId headId = repo.resolve(targetBranch + "^{commit}"); //$NON-NLS-1$
|
||||||
|
if (headId != null && rw.parseCommit(headId).getTree().getId().equals(treeId)) {
|
||||||
|
// No change. Do nothing.
|
||||||
|
return rw.parseCommit(headId);
|
||||||
|
}
|
||||||
|
|
||||||
CommitBuilder commit = new CommitBuilder();
|
CommitBuilder commit = new CommitBuilder();
|
||||||
commit.setTreeId(treeId);
|
commit.setTreeId(treeId);
|
||||||
if (headId != null)
|
if (headId != null)
|
||||||
|
|
Loading…
Reference in New Issue