2014-07-25 2 views
1

JGit을 사용하여 사용자 정의 git-push ant 태스크를 완료하려고 시도했으나 명시된 분기를 원격 저장소로 푸시해야하지만 작동하지 않는 것으로 보입니다.사용자 정의 git push ant task가 JGit에서 작동하지 않습니다.

다음은 작업에 대한 내 자바 코드입니다 :

public void setRepository(String repository) { 
     this.repository = repository; 
    } 
    public void setPassword(String password) { 
     this.password = password; 
    } 
    public void setUsername(String username) { 
     this.username = username; 
    }  
    public void setUri(String uri) { 
     this.uri = uri; 
    }  
    public void setBranch(String branch) { 
     this.branch = branch; 
    } 


    public void execute() throws BuildException { 
    try{ 

     Git git = Git.open(new File(repository));    
     CredentialsProvider cp = new UsernamePasswordCredentialsProvider(username, password); 
     RefSpec spec = new RefSpec("refs/heads/" + branch + ":refs/heads/" + branch); 

     PushCommand pushCommand = git.push(); 
     pushCommand.setCredentialsProvider(cp).setRemote(uri).setForce(true).setRefSpecs(spec).call(); 


    }catch (Exception e) { 
     log(e, Project.MSG_ERR); 
     throw new BuildException("Could not push repository: " + e.getMessage(), e); 

    } 

그리고 여기에 아파치 개미 빌드 파일에서 줄입니다 :

<gitpush 
    repository="./myrepo" 
    uri="ssh://[email protected]/repo/project.git" 
    branch="mybranch" 
    password="77CJr2xr" /> 

내가 새로운 지점을 생성하고이 작업을 실행 해보십시오. 태스크는 예외없이 실행되지만 원격 저장소에는 영향을 미치지 않습니다. 나는 정말 어리석은 실수 일 수 있기 때문에 자식에게는 아주 새로운 것이다. RefSpec에 문제가 있습니까?

+0

'PushCommand # call()'은'PushResult'를 리턴하고,'PushResult'는'RemoteRefUpdate' 콜렉션을 보유합니다. 이걸 조사 했니? 그들은 당신에게 밀어 넣기가 실제로 한 단서를 제공해야합니다. –

+0

나는 메시지를 받는다 :'error : 정체를 밝히지 않는 ref/head/mybranch를 부정하라. 어쩌면 나는'git checkout --orphan mybranch'을'git rm --cached -r .'과 함께 사용하여 새로운 빈 브랜치를 생성 한 다음 그 파일을 추가함으로써 뭔가 잘못 됐을 까? – JulioBordeaux

답변

2

마지막으로 가져온 후 또는 복제 한 후 푸시하기 전에 누군가 다른 사람이 같은 브랜치에 푸시하면 오류 메시지 denying non-fast-forward refs/heads/...이 반환됩니다.

you> git clone ... 

bob> git clone ... 
bob> git commit 
bob> git push 

you> git commit 
you> git push <<-- error: denying non-fast-forward 

아닌 앞으로 업데이트가 허용되는지 여부를 원격 저장소 컨트롤 receive.denyNonFastForwards 구성 설정. 일반적으로 이것은 원격 저장소의 히스토리를 변경하기 때문에 허용되지 않습니다. 위의 예에서 Bob의 커밋은 손실됩니다.

'빨리 감기를 거부하는 git push 오류'를 검색하여 더 자세히 읽으십시오.