2017-07-13 2 views
0
  • を使用して上流に設定してください。gitの新しいローカルブランチの作成は、リモートブランチ(新しいリモート)を押した後、私は動的にローカルブランチを作成(のような Hotfix_Test1、Hotfix_Test2異なる時刻における各)とリモートにそれをプッシュするつもりですJGIT

    • これらの枝はリリースがすでにgitのを使用してローカルからリモートにプッシュされている別のローカル

    • でリリースと呼ばれるブランチで利用可能なソースが含まれている必要があり

    • Gitチェックアウト-bリリースGitのプッシュコマンド
    • Gitのプッシュ--set-上流起源リリース

    • 私はgitのオブジェクトを作成し、Fをしよう'createBranchCommand.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM);' 実行は

    • この行に来るときに動的に

      public static void main(String[] args) { 
      CreateBranchCommand createBranchCommand = null; 
      CheckoutCommand checkoutCommand = null; 
      Git git = null; 
      String releaseVersion = "Test"; 
      PushCommand pushCommand = null; 
      StoredConfig config = null; 
      try { 
      /* Consider Git object is created */ 
      git = createGitObject(); 
      
      /* Checkout Release branch */ 
      checkoutCommand = git.checkout(); 
      checkoutCommand.setName("Release"); 
      checkoutCommand.call(); 
      
      /* Creating Hotfix Branch */ 
      createBranchCommand = git.branchCreate(); 
      createBranchCommand.setName("hotfix_" + releaseVersion).call(); 
      
      /* Pushing Hotfix Branch to remote 
      * note that the hotfix is not present in remote 
      */ 
      pushCommand = git.push(); 
      pushCommand.setRemote("origin"); 
      pushCommand.setRefSpecs(new RefSpec("hotfix_" + releaseVersion + ":hotfix_" + releaseVersion)); 
      pushCommand.call(); 
      
      /* Trying to set upstream for newly created hotfix branch */ 
      createBranchCommand.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM); 
      createBranchCommand.setStartPoint("origin/" + "hotfix_" + releaseVersion); 
      createBranchCommand.setForce(true); 
      createBranchCommand.call(); 
      checkoutCommand.setName("hotfix_" + releaseVersion); 
      checkoutCommand.call(); 
      
      /* Editing the configuration file in local */ 
      config = git.getRepository().getConfig(); 
      config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "hotfix_" + releaseVersion, "remote", "origin"); 
      config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "hotfix_" + releaseVersion, "merge", 
          "refs/heads/hotfix_" + releaseVersion); 
      config.save(); 
      } catch (Exception exception) { 
      exception.printStackTrace(); 
      } 
      
      } 
      

      をホットフィックスブランチを作成するためのコードをollowing

それは例外

  • java.lang.IllegalStateException投げている:コマンドorg.eclipse.jgit.api.CreateBranchCommandが

間違った状態で呼ばれていたが私はワットが間違いを知っていません。親切にエラーを助ける。

+1

他の人に必要なdを与えるために完全なスタックトレースを投稿してくださいまさにそれが失敗するところです。 – centic

答えて

0

あなたは既にcreatedBranchCommand呼ば:

/* Creating Hotfix Branch */ 
createBranchCommand = git.branchCreate(); 
createBranchCommand.setName("hotfix_" + releaseVersion).call(); 

再度の再利用branchCreate()コマンドを試みる前にプッシュでした:

/* Trying to set upstream for newly created hotfix branch */ 
createBranchCommand.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM); 
createBranchCommand.setStartPoint("origin/" + "hotfix_" + releaseVersion); 
createBranchCommand.setForce(true); 
createBranchCommand.call(); 

はブランチを作成し、中にその上流の設定を設定してみてください一度行ってからそれを押してください:

/* Creating Hotfix Branch */ 
createBranchCommand = git.branchCreate(); 
createBranchCommand.setName("hotfix_" + releaseVersion); 
createBranchCommand.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM); 
createBranchCommand.setStartPoint("origin/" + "hotfix_" + releaseVersion); 
createBranchCommand.setForce(true); 
createBranchCommand.call(); 
関連する問題