合并后JGit记录奇怪的行为

时间:2016-09-09 16:16:44

标签: git-merge jgit git-log

在日志命令中发现了一个奇怪的行为(bug?)。

以下测试创建一个repo,创建一个分支,对创建的分支和master进行一些提交,然后将master合并到创建的分支。合并后,它会尝试计算分支和主服务器之间的提交数。因为master已经合并 ​​- 分支不在master之后,即相应的commit count应为0。

$_POST

上述测试失败,public class JGitBugTest { @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); @Test public void testJGitLogBug() throws Exception { final String BRANCH_NAME = "TST-2"; final String MASTER_BRANCH_NAME = Constants.MASTER; File folder = tempFolder.newFolder(); // Create a Git repository Git api = Git.init().setBare( false ).setDirectory( folder ).call(); Repository repository = api.getRepository(); // Add an initial commit api.commit().setMessage( "Initial commit" ).call(); // Create a new branch and add some commits to it api.checkout().setCreateBranch( true ).setName( BRANCH_NAME ).call(); api.commit().setMessage( "TST-2 Added files 1" ).call(); // Add some commits to master branch too api.checkout().setName( MASTER_BRANCH_NAME ).call(); api.commit().setMessage( "TST-1 Added files 1" ).call(); api.commit().setMessage( "TST-1 Added files 2" ).call(); // If this delay is commented out -- test fails and // 'behind' is equal to "the number of commits to master - 1". // Thread.sleep(1000); // Checkout the branch and merge master to it api.checkout().setName( BRANCH_NAME ).call(); api.merge() .include( repository.resolve( MASTER_BRANCH_NAME ) ) .setStrategy( MergeStrategy.RECURSIVE ) .call() .getNewHead() .name(); // Calculate the number of commits the branch behind of the master // It should be zero because we have merged master into the branch already. Iterable<RevCommit> iterable = api.log() .add( repository.resolve( MASTER_BRANCH_NAME ) ) .not( repository.resolve( BRANCH_NAME ) ) .call(); int behind = 0; for( RevCommit commit : iterable ) { behind++; } Assert.assertEquals( 0, behind ); } } 产生主设备中的提交数减去1。

此外,如果第43行中的“睡眠”未被注释 - 错误将消失,“后面”等于0。

我做错了什么?它是JGit库或我的代码中的错误吗?

1 个答案:

答案 0 :(得分:1)

在Windows上运行代码,我可以重现您描述的内容。

这看起来像JGit中的一个错误。我建议open a bugzilla或将您的发现发布到mailing list