Program: 151574
Project: 151574
Buggy source:
@Command(value="String_Node_Str",help="String_Node_Str") public void installFromGit(@Option(description="String_Node_Str",required=true) final String gitRepo,@Option(name="String_Node_Str",description="String_Node_Str") final String refName,@Option(name="String_Node_Str",description="String_Node_Str") final Resource<?> checkoutDir,final ShellPrintWriter out) throws Exception {
  DirectoryResource workspace=shell.getCurrentDirectory().createTempResource();
  try {
    DirectoryResource buildDir=workspace.getChildDirectory("String_Node_Str");
    if (checkoutDir != null) {
      if (!checkoutDir.exists() && (checkoutDir instanceof FileResource<?>)) {
        ((FileResource<?>)checkoutDir).mkdirs();
      }
      buildDir=checkoutDir.reify(DirectoryResource.class);
    }
    if (buildDir.exists()) {
      buildDir.delete(true);
      buildDir.mkdir();
    }
    prepareProxyForJGit();
    ShellMessages.info(out,"String_Node_Str" + buildDir.getFullyQualifiedName() + "String_Node_Str");
    Git repo=GitUtils.clone(buildDir,gitRepo);
    Ref ref=null;
    String targetRef=refName;
    if (targetRef == null) {
      targetRef=environment.getRuntimeVersion();
    }
    if (targetRef != null) {
      Map<String,Ref> tags=repo.getRepository().getTags();
      ref=tags.get(targetRef);
      if (ref == null) {
        List<Ref> refs=GitUtils.getRemoteBranches(repo);
        for (        Ref branchRef : refs) {
          String branchName=branchRef.getName();
          if (branchName != null && branchName.endsWith(targetRef)) {
            ref=repo.branchCreate().setName(targetRef).setUpstreamMode(SetupUpstreamMode.TRACK).setStartPoint("String_Node_Str" + targetRef).call();
          }
        }
      }
      if (ref == null) {
        List<String> sortedVersions=new ArrayList<String>();
        for (        Ref branchRef : GitUtils.getRemoteBranches(repo)) {
          String branchName=branchRef.getName();
          branchName=branchName.replaceFirst("String_Node_Str","String_Node_Str");
          if (InstalledPluginRegistry.isApiCompatible(targetRef,branchName))           sortedVersions.add(branchName);
        }
        for (        String tag : tags.keySet()) {
          if (InstalledPluginRegistry.isApiCompatible(targetRef,tag))           sortedVersions.add(tag);
        }
        Collections.sort(sortedVersions);
        if (!sortedVersions.isEmpty()) {
          String version=sortedVersions.get(sortedVersions.size() - 1);
          if (InstalledPluginRegistry.isApiCompatible(targetRef,version)) {
            ref=tags.get(version);
            if (ref == null) {
              ref=repo.branchCreate().setName(version).setUpstreamMode(SetupUpstreamMode.TRACK).setStartPoint("String_Node_Str" + version).call();
            }
          }
        }
      }
    }
    if (ref == null) {
      ref=repo.getRepository().getRef("String_Node_Str");
    }
    if (ref != null) {
      ShellMessages.info(out,"String_Node_Str" + ref.getName() + "String_Node_Str");
      GitUtils.checkout(repo,ref,false,SetupUpstreamMode.TRACK,false);
    }
 else     if (refName != null) {
      throw new RuntimeException("String_Node_Str" + targetRef + "String_Node_Str"+ repo.getRepository().getDirectory().getAbsolutePath()+ "String_Node_Str");
    }
 else {
      ShellMessages.warn(out,"String_Node_Str" + environment.getRuntimeVersion() + "String_Node_Str");
    }
    buildFromCurrentProject(out,buildDir);
  }
  finally {
    if (checkoutDir != null) {
      ShellMessages.info(out,"String_Node_Str" + workspace.getFullyQualifiedName() + "String_Node_Str");
      workspace.delete(true);
    }
  }
  ShellMessages.success(out,"String_Node_Str" + gitRepo + "String_Node_Str");
  restart();
}

Fixed version (ground truth):
@Command(value="String_Node_Str",help="String_Node_Str") public void installFromGit(@Option(description="String_Node_Str",required=true) final String gitRepo,@Option(name="String_Node_Str",description="String_Node_Str") final String refName,@Option(name="String_Node_Str",description="String_Node_Str") final Resource<?> checkoutDir,final PipeOut out) throws Exception {
  DirectoryResource workspace=shell.getCurrentDirectory().createTempResource();
  try {
    DirectoryResource buildDir=workspace.getChildDirectory("String_Node_Str");
    if (checkoutDir != null) {
      if (!checkoutDir.exists() && (checkoutDir instanceof FileResource<?>)) {
        ((FileResource<?>)checkoutDir).mkdirs();
      }
      buildDir=checkoutDir.reify(DirectoryResource.class);
    }
    if (buildDir.exists()) {
      buildDir.delete(true);
      buildDir.mkdir();
    }
    prepareProxyForJGit();
    ShellMessages.info(out,"String_Node_Str" + buildDir.getFullyQualifiedName() + "String_Node_Str");
    Git repo=GitUtils.clone(buildDir,gitRepo);
    Ref ref=null;
    String targetRef=refName;
    if (targetRef == null) {
      targetRef=environment.getRuntimeVersion();
    }
    if (targetRef != null) {
      Map<String,Ref> tags=repo.getRepository().getTags();
      ref=tags.get(targetRef);
      if (ref == null) {
        List<Ref> refs=GitUtils.getRemoteBranches(repo);
        for (        Ref branchRef : refs) {
          String branchName=branchRef.getName();
          if (branchName != null && branchName.endsWith(targetRef)) {
            ref=repo.branchCreate().setName(targetRef).setUpstreamMode(SetupUpstreamMode.TRACK).setStartPoint("String_Node_Str" + targetRef).call();
          }
        }
      }
      if (ref == null) {
        List<String> sortedVersions=new ArrayList<String>();
        for (        Ref branchRef : GitUtils.getRemoteBranches(repo)) {
          String branchName=branchRef.getName();
          branchName=branchName.replaceFirst("String_Node_Str","String_Node_Str");
          if (InstalledPluginRegistry.isApiCompatible(targetRef,branchName))           sortedVersions.add(branchName);
        }
        for (        String tag : tags.keySet()) {
          if (InstalledPluginRegistry.isApiCompatible(targetRef,tag))           sortedVersions.add(tag);
        }
        Collections.sort(sortedVersions);
        if (!sortedVersions.isEmpty()) {
          String version=sortedVersions.get(sortedVersions.size() - 1);
          if (InstalledPluginRegistry.isApiCompatible(targetRef,version)) {
            ref=tags.get(version);
            if (ref == null) {
              ref=repo.branchCreate().setName(version).setUpstreamMode(SetupUpstreamMode.TRACK).setStartPoint("String_Node_Str" + version).call();
            }
          }
        }
      }
    }
    if (ref == null) {
      ref=repo.getRepository().getRef("String_Node_Str");
    }
    if (ref != null) {
      ShellMessages.info(out,"String_Node_Str" + ref.getName() + "String_Node_Str");
      GitUtils.checkout(repo,ref,false,SetupUpstreamMode.TRACK,false);
    }
 else     if (refName != null) {
      throw new RuntimeException("String_Node_Str" + targetRef + "String_Node_Str"+ repo.getRepository().getDirectory().getAbsolutePath()+ "String_Node_Str");
    }
 else {
      ShellMessages.warn(out,"String_Node_Str" + environment.getRuntimeVersion() + "String_Node_Str");
    }
    buildFromCurrentProject(out,buildDir);
  }
  finally {
    if (checkoutDir != null) {
      ShellMessages.info(out,"String_Node_Str" + workspace.getFullyQualifiedName() + "String_Node_Str");
      workspace.delete(true);
    }
  }
  ShellMessages.success(out,"String_Node_Str" + gitRepo + "String_Node_Str");
  restart();
}