コード例 #1
0
        public override Task CloneAsync(GitCloneOptions options)
        {
            try
            {
                this.BeginOperation();

                this.log.LogDebug($"Cloning '{this.repository.RemoteRepositoryUrl}' into '{this.repository.LocalRepositoryPath}'...");
                this.log.LogDebug("Clone options: " + options);
                try
                {
                    Repository.Clone(
                        this.repository.RemoteRepositoryUrl,
                        this.repository.LocalRepositoryPath,
                        new CloneOptions
                    {
                        BranchName          = options.Branch,
                        CredentialsProvider = this.CredentialsHandler,
                        RecurseSubmodules   = options.RecurseSubmodules
                    }
                        );
                }
                catch (Exception ex)
                {
                    // gitsharp exceptions are not always serializable
                    throw new ExecutionFailureException("Clone failed: " + ex.Message);
                }

                return(Complete);
            }
            finally
            {
                this.EndOperation();
            }
        }
コード例 #2
0
 public async override Task CloneAsync(GitCloneOptions options)
 {
     await this.ExecuteRemoteAsync(
         ClientCommand.Clone,
         new RemoteLibGitSharpContext { CloneOptions = options }
         ).ConfigureAwait(false);
 }
コード例 #3
0
 public override Task CloneAsync(GitCloneOptions options)
 {
     return(this.ExecuteRemoteAsync(
                ClientCommand.Clone,
                new RemoteLibGitSharpContext {
         CloneOptions = options
     }
                ));
 }
コード例 #4
0
        private void Tag(string cloneDirectory, ClientType type)
        {
            string fullCloneDirectory = PathEx.Combine(this.rootDir, cloneDirectory);
            string tag = "tag-" + DateTime.Now.ToString("yyMMddhhmmss");

            var client = this.CreateClient(type, fullCloneDirectory);

            var options = new GitCloneOptions();

            client.CloneAsync(options).GetAwaiter().GetResult();

            client.TagAsync(tag).GetAwaiter().GetResult();
        }
コード例 #5
0
        private void Clone(string cloneDirectory, ClientType type)
        {
            string fullCloneDirectory = PathEx.Combine(this.rootDir, cloneDirectory);

            var client = this.CreateClient(type, fullCloneDirectory);

            var options = new GitCloneOptions();

            client.CloneAsync(options).GetAwaiter().GetResult();

            string examplePath = PathEx.Combine(fullCloneDirectory, @"TestConsoleApplication\TestConsoleApplication\Resources\output.txt");

            Assert.IsTrue(this.fileOps.FileExists(examplePath));
        }
コード例 #6
0
        public override Task CloneAsync(GitCloneOptions options)
        {
            this.log.LogDebug($"Cloning '{this.repository.RemoteRepositoryUrl}' into '{this.repository.LocalRepositoryPath}'...");
            this.log.LogDebug("Clone options: " + options);
            Repository.Clone(
                this.repository.RemoteRepositoryUrl,
                this.repository.LocalRepositoryPath,
                new CloneOptions
            {
                BranchName          = options.Branch,
                CredentialsProvider = this.CredentialsHandler,
                RecurseSubmodules   = options.RecurseSubmodules
            }
                );

            return(Complete);
        }
コード例 #7
0
ファイル: Repository.cs プロジェクト: philhack/libgit2sharp
        /// <summary>
        /// Clone with specified options.
        /// </summary>
        /// <param name="sourceUrl">URI for the remote repository</param>
        /// <param name="workdirPath">Local path to clone into</param>
        /// <param name="bare">True will result in a bare clone, false a full clone.</param>
        /// <param name="checkout">If true, the origin's HEAD will be checked out. This only applies
        /// to non-bare repositories.</param>
        /// <param name="onTransferProgress">Handler for network transfer and indexing progress information</param>
        /// <param name="onCheckoutProgress">Handler for checkout progress information</param>
        /// <param name="credentials">Credentials to use for user/pass authentication</param>
        /// <returns>The path to the created repository.</returns>
        public static string Clone(string sourceUrl, string workdirPath,
                                   bool bare     = false,
                                   bool checkout = true,
                                   TransferProgressHandler onTransferProgress = null,
                                   CheckoutProgressHandler onCheckoutProgress = null,
                                   Credentials credentials = null)
        {
            CheckoutCallbacks checkoutCallbacks = CheckoutCallbacks.GenerateCheckoutCallbacks(onCheckoutProgress, null);

            var cloneOpts = new GitCloneOptions
            {
                Bare = bare ? 1 : 0,
                TransferProgressCallback = TransferCallbacks.GenerateCallback(onTransferProgress),
                CheckoutOpts             =
                {
                    version     = 1,
                    progress_cb =
                        checkoutCallbacks.CheckoutProgressCallback,
                    checkout_strategy = checkout
                                            ? CheckoutStrategy.GIT_CHECKOUT_SAFE_CREATE
                                            : CheckoutStrategy.GIT_CHECKOUT_NONE
                },
            };

            if (credentials != null)
            {
                cloneOpts.CredAcquireCallback =
                    (out IntPtr cred, IntPtr url, IntPtr username_from_url, uint types, IntPtr payload) =>
                    NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password);
            }

            FilePath repoPath;

            using (RepositorySafeHandle repo = Proxy.git_clone(sourceUrl, workdirPath, cloneOpts))
            {
                repoPath = Proxy.git_repository_path(repo);
            }

            // To be safe, make sure the credential callback is kept until
            // alive until at least this point.
            GC.KeepAlive(cloneOpts.CredAcquireCallback);

            return(repoPath.Native);
        }
コード例 #8
0
        public override async Task CloneAsync(GitCloneOptions options)
        {
            var args = new GitArgumentsBuilder("clone");

            if (options.Branch != null)
            {
                args.Append("-b");
                args.AppendQuoted(options.Branch);
            }
            if (options.RecurseSubmodules)
            {
                args.Append("--recursive");
            }

            args.AppendSensitive(this.repository.GetRemoteUrlWithCredentials());
            args.AppendQuoted(this.repository.LocalRepositoryPath);

            await this.ExecuteCommandLineAsync(args, this.repository.LocalRepositoryPath).ConfigureAwait(false);
        }
コード例 #9
0
ファイル: GitTests.cs プロジェクト: Falcon-Punch/inedox-git
        private void Tag(string baseDirectory, string cloneDirectory, ClientType type)
        {
            string baseCloneDirectory = PathEx.Combine(this.rootDir, baseDirectory);
            string fullCloneDirectory = PathEx.Combine(this.rootDir, cloneDirectory);
            string baseGitDirectory   = PathEx.Combine(baseCloneDirectory, ".git");
            string tag = "tag-" + DateTime.Now.ToString("yyMMddhhmmss");

            var client = this.CreateClient(type, baseCloneDirectory);

            var options = new GitCloneOptions();

            client.CloneAsync(options).GetAwaiter().GetResult();

            // HACK: pretend we just made a bare clone
            var configFile = PathEx.Combine(baseGitDirectory, "config");

            File.WriteAllText(configFile, File.ReadAllText(configFile).Replace("bare = false", "bare = true"));

            client = this.CreateClient(type, fullCloneDirectory, baseGitDirectory);

            client.CloneAsync(options).GetAwaiter().GetResult();

            client.TagAsync(tag, null, null).GetAwaiter().GetResult();

            bool failed = false;

            try
            {
                client.TagAsync(tag, null, null, false).GetAwaiter().GetResult();
            }
            catch
            {
                failed = true;
            }
            Assert.IsTrue(failed, "Creating an existing tag with force=false should fail.");

            client.TagAsync(tag, null, null, true).GetAwaiter().GetResult();
        }
コード例 #10
0
        /// <summary>
        /// Clone with specified options.
        /// </summary>
        /// <param name="sourceUrl">URI for the remote repository</param>
        /// <param name="workdirPath">Local path to clone into</param>
        /// <param name="bare">True will result in a bare clone, false a full clone.</param>
        /// <param name="checkout">If true, the origin's HEAD will be checked out. This only applies
        /// to non-bare repositories.</param>
        /// <param name="onTransferProgress">Handler for network transfer and indexing progress information</param>
        /// <param name="onCheckoutProgress">Handler for checkout progress information</param>
        /// <param name="credentials">Credentials to use for user/pass authentication</param>
        /// <returns>The path to the created repository.</returns>
        public static string Clone(string sourceUrl, string workdirPath,
                                   bool bare     = false,
                                   bool checkout = true,
                                   TransferProgressHandler onTransferProgress = null,
                                   CheckoutProgressHandler onCheckoutProgress = null,
                                   Credentials credentials = null)
        {
            CheckoutCallbacks checkoutCallbacks = CheckoutCallbacks.GenerateCheckoutCallbacks(onCheckoutProgress, null);

            var callbacks = new RemoteCallbacks(null, onTransferProgress, null, credentials);
            GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks();

            var cloneOpts = new GitCloneOptions
            {
                Bare         = bare ? 1 : 0,
                CheckoutOpts =
                {
                    version     = 1,
                    progress_cb =
                        checkoutCallbacks.CheckoutProgressCallback,
                    checkout_strategy = checkout
                                            ? CheckoutStrategy.GIT_CHECKOUT_SAFE_CREATE
                                            : CheckoutStrategy.GIT_CHECKOUT_NONE
                },
                RemoteCallbacks = gitCallbacks,
            };

            FilePath repoPath;

            using (RepositorySafeHandle repo = Proxy.git_clone(sourceUrl, workdirPath, cloneOpts))
            {
                repoPath = Proxy.git_repository_path(repo);
            }

            return(repoPath.Native);
        }