Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Repository"/> class.
        /// </summary>
        /// <param name="libGitRepo">The value of <see cref="libGitRepo"/>.</param>
        /// <param name="commands">The value of <see cref="commands"/>.</param>
        /// <param name="ioMananger">The value of <see cref="ioMananger"/>.</param>
        /// <param name="eventConsumer">The value of <see cref="eventConsumer"/>.</param>
        /// <param name="credentialsProvider">The value of <see cref="credentialsProvider"/>.</param>
        /// <param name="gitRemoteFeaturesFactory">The <see cref="IGitRemoteFeaturesFactory"/> to provide the value of <see cref="gitRemoteFeatures"/>.</param>
        /// <param name="logger">The value of <see cref="logger"/>.</param>
        /// <param name="onDispose">The value if <see cref="onDispose"/>.</param>
        public Repository(
            LibGit2Sharp.IRepository libGitRepo,
            ILibGit2Commands commands,
            IIOManager ioMananger,
            IEventConsumer eventConsumer,
            ICredentialsProvider credentialsProvider,
            IGitRemoteFeaturesFactory gitRemoteFeaturesFactory,
            ILogger <Repository> logger,
            Action onDispose)
        {
            this.libGitRepo          = libGitRepo ?? throw new ArgumentNullException(nameof(libGitRepo));
            this.commands            = commands ?? throw new ArgumentNullException(nameof(commands));
            this.ioMananger          = ioMananger ?? throw new ArgumentNullException(nameof(ioMananger));
            this.eventConsumer       = eventConsumer ?? throw new ArgumentNullException(nameof(eventConsumer));
            this.credentialsProvider = credentialsProvider ?? throw new ArgumentNullException(nameof(credentialsProvider));
            if (gitRemoteFeaturesFactory == null)
            {
                throw new ArgumentNullException(nameof(gitRemoteFeaturesFactory));
            }

            this.logger    = logger ?? throw new ArgumentNullException(nameof(logger));
            this.onDispose = onDispose ?? throw new ArgumentNullException(nameof(onDispose));

            gitRemoteFeatures = gitRemoteFeaturesFactory.CreateGitRemoteFeatures(this);
        }
        /// <summary>
        /// Construct a <see cref="Repository"/>
        /// </summary>
        /// <param name="libGitRepo">The value of <see cref="libGitRepo"/></param>
        /// <param name="commands">The value of <see cref="commands"/>.</param>
        /// <param name="ioMananger">The value of <see cref="ioMananger"/></param>
        /// <param name="eventConsumer">The value of <see cref="eventConsumer"/></param>
        /// <param name="credentialsProvider">The value of <see cref="credentialsProvider"/></param>
        /// <param name="logger">The value of <see cref="logger"/></param>
        /// <param name="onDispose">The value if <see cref="onDispose"/></param>
        public Repository(
            LibGit2Sharp.IRepository libGitRepo,
            ILibGit2Commands commands,
            IIOManager ioMananger,
            IEventConsumer eventConsumer,
            ICredentialsProvider credentialsProvider,
            ILogger <Repository> logger,
            Action onDispose)
        {
            this.libGitRepo          = libGitRepo ?? throw new ArgumentNullException(nameof(libGitRepo));
            this.commands            = commands ?? throw new ArgumentNullException(nameof(commands));
            this.ioMananger          = ioMananger ?? throw new ArgumentNullException(nameof(ioMananger));
            this.eventConsumer       = eventConsumer ?? throw new ArgumentNullException(nameof(eventConsumer));
            this.credentialsProvider = credentialsProvider ?? throw new ArgumentNullException(nameof(credentialsProvider));
            this.logger    = logger ?? throw new ArgumentNullException(nameof(logger));
            this.onDispose = onDispose ?? throw new ArgumentNullException(nameof(onDispose));

            IsGitHubRepository = Origin.Contains(GitHubUrl, StringComparison.InvariantCultureIgnoreCase);

            if (IsGitHubRepository)
            {
                GetRepositoryOwnerName(Origin, out var owner, out var name);
                GitHubOwner    = owner;
                GitHubRepoName = name;
            }
        }
Exemple #3
0
        public Repository(string path)
        {
            Contract.Requires<ArgumentNullException>(path != null, "path");

            RepositoryOptions repositoryOptions = new RepositoryOptions();
            this._git = new LibGit2Sharp.Repository(path, repositoryOptions);
            var navigator = new RepositoryNavigator(this._git);
            this.Root = new Container(navigator);
        }
Exemple #4
0
 /// <summary>
 /// Releases all resource used by the <see cref="Moduni.GitRepository"/> object.
 /// </summary>
 /// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="Moduni.GitRepository"/>. The
 /// <see cref="Dispose"/> method leaves the <see cref="Moduni.GitRepository"/> in an unusable state. After
 /// calling <see cref="Dispose"/>, you must release all references to the <see cref="Moduni.GitRepository"/> so
 /// the garbage collector can reclaim the memory that the <see cref="Moduni.GitRepository"/> was occupying.</remarks>
 public void Dispose()
 {
     foreach (string file in System.IO.Directory.GetFiles(this.RepositoryURL, "*", System.IO.SearchOption.AllDirectories))
     {
         System.IO.File.SetAttributes(file, System.IO.FileAttributes.Normal);
     }
     if (this.gitRepositoryHandle != null)
     {
         this.gitRepositoryHandle.Dispose();
     }
     this.gitRepositoryHandle = null;
 }
 /// <summary>
 /// Construct a <see cref="Repository"/>
 /// </summary>
 /// <param name="repository">The value of <see cref="repository"/></param>
 /// <param name="ioMananger">The value of <see cref="ioMananger"/></param>
 /// <param name="eventConsumer">The value of <see cref="eventConsumer"/></param>
 /// <param name="onDispose">The value if <see cref="onDispose"/></param>
 public Repository(LibGit2Sharp.IRepository repository, IIOManager ioMananger, IEventConsumer eventConsumer, Action onDispose)
 {
     this.repository    = repository ?? throw new ArgumentNullException(nameof(repository));
     this.ioMananger    = ioMananger ?? throw new ArgumentNullException(nameof(ioMananger));
     this.eventConsumer = eventConsumer ?? throw new ArgumentNullException(nameof(eventConsumer));
     this.onDispose     = onDispose ?? throw new ArgumentNullException(nameof(onDispose));
     IsGitHubRepository = Origin.ToUpperInvariant().Contains(GitHubUrl.ToUpperInvariant());
     if (IsGitHubRepository)
     {
         GetRepositoryOwnerName(Origin, out var owner, out var name);
         GitHubOwner    = owner;
         GitHubRepoName = name;
     }
 }
        /// <inheritdoc />
        public void Fetch(
            LibGit2Sharp.IRepository libGit2Repo,
            IEnumerable <string> refSpecs,
            Remote remote,
            FetchOptions fetchOptions,
            string logMessage)
        {
            if (libGit2Repo == null)
            {
                throw new ArgumentNullException(nameof(libGit2Repo));
            }

            if (remote == null)
            {
                throw new ArgumentNullException(nameof(remote));
            }

            Commands.Fetch((LibGit2Sharp.Repository)libGit2Repo, remote.Name, refSpecs, fetchOptions, logMessage);
        }
Exemple #7
0
        /// <summary>
        /// Moves the repository to the path specified as argument.
        /// </summary>
        /// <param name="pathToMoveTo">The new path of the repository.</param>
        public void MoveTo(string pathToMoveTo)
        {
            if (!this.IsRepositoryInitialized)
            {
                throw new ModuniException("The repository is not initialized.");
            }

            // If it is a submodule, we can't move it by our own so we do nothing
            if (System.IO.File.Exists(System.IO.Path.Combine(this.RepositoryURL, ".git")))
            {
                return;
            }

            if (System.IO.Directory.Exists(pathToMoveTo))
            {
                DirectoryExtensions.DeleteCompletely(pathToMoveTo);
            }
            string repositoryURL = this.RepositoryURL;

            this.Dispose();
            System.IO.Directory.Move(repositoryURL, pathToMoveTo);
            this.gitRepositoryHandle = new Repository(pathToMoveTo);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GitRepository"/> class.
        /// </summary>
        /// <param name="folderPath">The folder path.</param>
        /// <param name="fileChangesFactory">The file changes factory.</param>
        /// <param name="blockChangesFactory">The block changes factory.</param>
        /// <exception cref="ArgumentOutOfRangeException">If folderPath is not a directory.</exception>
        /// <exception cref="ArgumentNullException">
        /// fileChangesFactory
        /// or
        /// blockChangesFactory
        /// </exception>
        public GitRepository(string folderPath, IFileChangesFactory fileChangesFactory, IBlockChangeFactory blockChangesFactory)
        {
            // Check if folder exists
            if (!Directory.Exists(folderPath))
            {
                throw new ArgumentOutOfRangeException($"{nameof(folderPath)} with value '{folderPath}' is valid. Directory doesn't exist.");
            }

            if (fileChangesFactory == null)
            {
                throw new ArgumentNullException(nameof(fileChangesFactory));
            }

            if (blockChangesFactory == null)
            {
                throw new ArgumentNullException(nameof(blockChangesFactory));
            }

            _folderPath          = folderPath;
            _fileChangesFactory  = fileChangesFactory;
            _blockChangesFactory = blockChangesFactory;
            _repository          = new LibGit2Sharp.Repository(folderPath);
        }
        /// <inheritdoc />
        public void Fetch(
            LibGit2Sharp.IRepository libGit2Repo,
            IEnumerable <string> refSpecs,
            Remote remote,
            FetchOptions fetchOptions,
            string logMessage)
        {
            if (libGit2Repo == null)
            {
                throw new ArgumentNullException(nameof(libGit2Repo));
            }

            if (!(libGit2Repo is LibGit2Sharp.Repository concreteRepo))
            {
                throw new ArgumentException("libGit2Repo must be an instance of LibGit2Sharp.Repository!", nameof(libGit2Repo));
            }

            if (remote == null)
            {
                throw new ArgumentNullException(nameof(remote));
            }

            Commands.Fetch(concreteRepo, remote.Name, refSpecs, fetchOptions, logMessage);
        }
Exemple #10
0
 //        private GitOBj _object;
 public RepositoryNavigator(LibGit2Sharp.IRepository git, Location location = null)
 {
     this._git = git;
     this._location = location;
       //          this._object
 }
 /// <inheritdoc />
 public void Checkout(LibGit2Sharp.IRepository libGit2Repo, CheckoutOptions checkoutOptions, string commitish)
 => Commands.Checkout(libGit2Repo, commitish, checkoutOptions);
Exemple #12
0
 private Signature GetSignature(LibGit2Sharp.IRepository repo)
 {
     return(repo.Config.BuildSignature(DateTimeOffset.Now));
 }
Exemple #13
0
        /// <summary>
        /// Creates a new working copy of this repository.
        /// </summary>
        /// <returns>The new working copy created.</returns>
        /// <param name="path">The local path where the new working copy should be created.</param>
        public ISourceControlRepository InitOrCloneRepository(string path)
        {
            string actualRepositoryPath;

            if (this.IsRepositoryInitialized)
            {
                try
                {
                    actualRepositoryPath = Repository.Clone(this.RepositoryURL, path, new CloneOptions()
                    {
                        IsBare = false
                    });
                    ISourceControlRepository newRepository = new GitRepository(actualRepositoryPath);
                    newRepository.RemoteOriginURL = this.RepositoryURL;
                    return(newRepository);
                }
                catch (NameConflictException)
                {
                    actualRepositoryPath = Repository.Init(path, false);
                    ISourceControlRepository newRepository = new GitRepository(actualRepositoryPath);
                    newRepository.RemoteOriginURL = this.RepositoryURL;
                    newRepository.FetchAll();
                    try
                    {
                        newRepository.CheckoutReference("master");
                    }
                    catch (ModuniException)
                    {
                    }
                    return(newRepository);
                }
            }
            else
            {
                if (this.remoteOriginURL != null)
                {
                    try
                    {
                        actualRepositoryPath = Repository.Clone(this.remoteOriginURL, path, new CloneOptions()
                        {
                            IsBare = false
                        });
                        this.gitRepositoryHandle = new Repository(actualRepositoryPath);
                    }
                    catch (NameConflictException)
                    {
                        actualRepositoryPath     = Repository.Init(path, false);
                        this.gitRepositoryHandle = new Repository(actualRepositoryPath);
                        this.RemoteOriginURL     = this.remoteOriginURL;
                        this.FetchAll();
                        try
                        {
                            this.CheckoutReference("origin/master");
                        }
                        catch (ModuniException)
                        {
                        }
                    }
                }
                else
                {
                    try
                    {
                        actualRepositoryPath = Repository.Init(path, false);
                    }
                    catch (LibGit2SharpException)
                    {
                        throw new ModuniException("The path to the working copy is invalid.");
                    }
                    this.gitRepositoryHandle = new Repository(actualRepositoryPath);
                }
                return(this);
            }
        }
Exemple #14
0
 public GitRepository(string workingDirectoryPath)
 {
     this.gitRepositoryHandle = new Repository(workingDirectoryPath);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="VersionContext"/> class.
 /// </summary>
 /// <param name="repository">The git repository.</param>
 public VersionContext(Git.IRepository repository)
 {
     Repository = repository ?? throw new ArgumentNullException(nameof(repository));
     Result     = SetIntialResult();
 }