2016-09-09 9 views
3

로그 명령에서 이상한 동작 (버그?)을 발견했습니다.병합 후 JGit 로그 이상 동작이 발생했습니다.

아래의 테스트는 repo를 만들고, 분기를 만들고, 일부는 생성 된 분기와 마스터로 커밋 한 다음 master를 생성 된 분기에 병합합니다. 병합 후에 분기와 마스터 간의 커밋 수를 계산합니다. 마스터가 이미되어 있기 때문에 통합 - 분기가 마스터 뒤에 있지, 0

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); 
    } 
} 

위의 테스트가 실패, behind 마스터에 커밋의 수를 얻을 수에서 1을 뺀

해야합니다 수를 커밋에 대응하여 예

또한 43 행의 'sleep'이 주석 처리되지 않은 경우 버그가 사라지고 'behind'가 0과 같습니다.

내가 뭘 잘못 했습니까? 그것은 JGit 라이브러리 또는 내 코드 버그가 있나요?

+0

JGit 추적기의 해당 버그 - https://bugs.eclipse.org/bugs/show_bug.cgi?id=501211 –

답변

1

Windows에서 코드를 실행하면 설명하는 내용을 재현 할 수 있습니다.

이것은 JGit의 버그와 같습니다. open a bugzilla으로 연락하거나 조사 결과를 mailing list에 게시하십시오.

+0

감사합니다. 나는 이미 JGit 포럼에 게시했습니다 : https://www.eclipse.org/forums/index.php/t/1081085/ –