// Path: src/main/java/com/github/danielflower/mavenplugins/release/FileUtils.java
// public static String pathOf(File file) {
//     String path;
//     try {
//         path = file.getCanonicalPath();
//     } catch (IOException e1) {
//         path = file.getAbsolutePath();
//     }
//     return path;
// }


import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.LsRemoteCommand;
import org.eclipse.jgit.api.PushCommand;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.CredentialsProvider;
import java.io.File;
import java.io.IOException;
import java.util.*;
import static com.github.danielflower.mavenplugins.release.FileUtils.pathOf;
package com.github.danielflower.mavenplugins.release;




public class LocalGitRepo {

    public final Git git;
    private boolean hasReverted = false; // A premature optimisation? In the normal case, file reverting occurs twice, which this bool prevents
    private Collection<Ref> tags;

    private final TagFetcher tagFetcher;
    private final TagPusher tagPusher;

    public static class Builder {

        private Set<GitOperations> operationsAllowed = EnumSet.allOf(GitOperations.class);
        private String remoteGitUrl;
        private CredentialsProvider credentialsProvider;

        /**
         * Flag for which remote Git operations are permitted. Local values will
         * be substituted if remote operations are forbidden; this means the
         * local copy of the repository must be up to date!
         */
        public Builder remoteGitOperationsAllowed(Set<GitOperations> operationsAllowed) {
            this.operationsAllowed = EnumSet.copyOf(operationsAllowed);
            return this;
        }

        /**
         * Overrides the URL of remote Git repository.
         */
        public Builder remoteGitUrl(String remoteUrl) {
            this.remoteGitUrl = remoteUrl;
            return this;
        }

        /**
         * Sets the username/password pair for HTTPS URLs or SSH with passwordl
         */
        public Builder credentialsProvider(CredentialsProvider credentialsProvider) {
            this.credentialsProvider = credentialsProvider;
            return this;
        }

        /**
         * Uses the current working dir to open the Git repository.
         * @throws ValidationException if anything goes wrong
         */
        public LocalGitRepo buildFromCurrentDir() throws ValidationException {
            Git git;
            File gitDir = new File(".");
            try {
                git = Git.open(gitDir);
            } catch (RepositoryNotFoundException rnfe) {
// Path: src/main/java/com/github/danielflower/mavenplugins/release/FileUtils.java
// public static String pathOf(File file) {
//     String path;
//     try {
//         path = file.getCanonicalPath();
//     } catch (IOException e1) {
//         path = file.getAbsolutePath();
//     }
//     return path;
// }


// Path: src/main/java/com/github/danielflower/mavenplugins/release/LocalGitRepo.java
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.LsRemoteCommand;
import org.eclipse.jgit.api.PushCommand;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.CredentialsProvider;
import java.io.File;
import java.io.IOException;
import java.util.*;
import static com.github.danielflower.mavenplugins.release.FileUtils.pathOf;

package com.github.danielflower.mavenplugins.release;




public class LocalGitRepo {

    public final Git git;
    private boolean hasReverted = false; // A premature optimisation? In the normal case, file reverting occurs twice, which this bool prevents
    private Collection<Ref> tags;

    private final TagFetcher tagFetcher;
    private final TagPusher tagPusher;

    public static class Builder {

        private Set<GitOperations> operationsAllowed = EnumSet.allOf(GitOperations.class);
        private String remoteGitUrl;
        private CredentialsProvider credentialsProvider;

        /**
         * Flag for which remote Git operations are permitted. Local values will
         * be substituted if remote operations are forbidden; this means the
         * local copy of the repository must be up to date!
         */
        public Builder remoteGitOperationsAllowed(Set<GitOperations> operationsAllowed) {
            this.operationsAllowed = EnumSet.copyOf(operationsAllowed);
            return this;
        }

        /**
         * Overrides the URL of remote Git repository.
         */
        public Builder remoteGitUrl(String remoteUrl) {
            this.remoteGitUrl = remoteUrl;
            return this;
        }

        /**
         * Sets the username/password pair for HTTPS URLs or SSH with passwordl
         */
        public Builder credentialsProvider(CredentialsProvider credentialsProvider) {
            this.credentialsProvider = credentialsProvider;
            return this;
        }

        /**
         * Uses the current working dir to open the Git repository.
         * @throws ValidationException if anything goes wrong
         */
        public LocalGitRepo buildFromCurrentDir() throws ValidationException {
            Git git;
            File gitDir = new File(".");
            try {
                git = Git.open(gitDir);
            } catch (RepositoryNotFoundException rnfe) {
                String fullPathOfCurrentDir = pathOf(gitDir);