Jgit refnotfoundexception при проверке ветви из репозитория Azure DevOps при попытке получить доступ к филиалуJAVA

Программисты JAVA общаются здесь
Anonymous
Jgit refnotfoundexception при проверке ветви из репозитория Azure DevOps при попытке получить доступ к филиалу

Сообщение Anonymous »

Я использую Jgit для клона и взаимодействия с репозиторием GIT, размещенным на Azure DevOps. Моя цель состоит в том, чтобы клонировать главную ветвь, заглянуть в мою указанную филиал (BranchName), обновить значение из файла pom.xml в рамках тега
(с использованием pommanipulations.modifypomfile (pomfilepath) ), а затем подтолкнуть обновленную локальную филиал в реконструкцию. Хотя значение ревизии получено правильно, я сталкиваюсь с RefnotFoundException при попытке проверить ветвь. Это говорит о том, что ссылка на ветвь не может быть разрешена.

Код: Выделить всё

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class AzureDevOpsBranchUpdater {

private static final String PAT_FILE_PATH = "path/to/pat.txt"; // Update with the correct path

public String updatePom(String organization, String project, String repositoryName, String branchName, String Id) {

String repoUrl = "https://dev.azure.com/" + organization + "/" + project + "/_git/" + repositoryName;
String localRepoPath = "C:/Users/" + Id + "/AutomatePipeline/" + repositoryName;
String pomFilePath = localRepoPath + "/pom.xml";

try {
// Read the Personal Access Token (PAT)
String PAT = Files.readString(Paths.get(PAT_FILE_PATH)).trim();

// Clone the repository and checkout master
Git git = Git.cloneRepository()
.setURI(repoUrl)
.setDirectory(new File(localRepoPath))
.setCredentialsProvider(new UsernamePasswordCredentialsProvider("", PAT))
.setBranch("master")
.call();

// Checkout the specified branch
git.checkout().setName(branchName).call();

// Pull the latest changes from master
git.fetch().setCredentialsProvider(new UsernamePasswordCredentialsProvider("", PAT)).call();

MergeResult mergeResult = git.merge()
.include(git.getRepository().findRef("master"))
.call();

if (!mergeResult.getMergeStatus().isSuccessful()) {
return "Merge conflicts occurred: " + mergeResult.getMergeStatus();
}

// Modify the pom.xml file
pomManipulations.modifyPomFile(pomFilePath);

// Commit the changes
git.add().addFilepattern("pom.xml").call();
git.commit().setMessage("Updated pom.xml").call();

// Push the changes to the remote branch
git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider("", PAT)).call();

return "Branch "+ BRANCH +"'s pom.xml updated successfully";

} catch (GitAPIException | IOException e) {
e.printStackTrace();
return "Error: " + e.getMessage();
}
}

private String getRevisionFromPom(String pomFilePath) throws IOException {
XmlMapper xmlMapper = new XmlMapper();
JsonNode root = xmlMapper.readTree(new File(pomFilePath));
JsonNode propertiesNode = root.findPath("properties");
if (propertiesNode.isMissingNode()) {
return null; //  tag not found
}
JsonNode revisionNode = propertiesNode.findPath("revision");
if (revisionNode.isMissingNode()) {
return null; //  tag not found in the  section
}
return revisionNode.asText(); // Return the revision value
}
}

< /code>
Устранение неисправностей, предпринятые: < /p>
[list]
[*] Проверено имя и существование ветви в удаленном репозитории. < /li>
 Убедитесь, что личный токен доступа (PAT) имеет необходимые разрешения. Правильно.
[/list]
[b] Вопрос: [/b] Что может вызвать рефнотфундэкспений 
во время процесса заказа и как я могу его разрешить?


Подробнее здесь: https://stackoverflow.com/questions/796 ... repository

Вернуться в «JAVA»