Exemplo n.º 1
0
        /// <summary>
        ///   Generate a delegate matching the signature of the native progress_cb callback and wraps the <see cref="CheckoutProgressHandler"/> delegate.
        /// </summary>
        /// <param name="onCheckoutProgress"><see cref="CheckoutProgressHandler"/> that should be wrapped in the native callback.</param>
        /// <returns>The delegate with signature matching the expected native callback. </returns>
        internal static progress_cb GenerateCheckoutCallbacks(CheckoutProgressHandler onCheckoutProgress)
        {
            if (onCheckoutProgress == null)
            {
                return null;
            }

            return new CheckoutCallbacks(onCheckoutProgress).OnGitCheckoutProgress;
        }
        public static async Task<bool> Clone(string cloneTo, IProgress<double> progress)
        {
            bool succeeded = true;

            await Task.Run(() =>
            {
                var thandler = new TransferProgressHandler(h =>
                {

                    progress.Report(((double)h.ReceivedObjects / h.TotalObjects) * 100);
                    //progress.Report(String.Format("{0}/{1}", (double)h.ReceivedObjects, (double)h.TotalObjects));

                    return 0;

                });

                var chandler = new CheckoutProgressHandler((path, completedSteps, totalSteps) =>
                {

                    //progress.Report(String.Format("{0}/{1}", (double)completedSteps, (double)totalSteps));

                    progress.Report(((double)completedSteps / totalSteps) * 100);

                });

                try
                {
                    Repository.Clone(TrinityCoreGit, cloneTo, false, true, thandler, chandler);
                }
                catch (LibGit2SharpException)
                {
                    //MessageBox.Show("The selected trunk location is not a valid git repository.", "Something went wrong!", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    succeeded = false;
                }
                catch (Exception)
                {
                    succeeded = false;
                }
            });

            return succeeded;
        }
Exemplo n.º 3
0
 public Branch Checkout(Branch branch, CheckoutModifiers checkoutModifiers, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 4
0
 public Branch Checkout(string committishOrBranchSpec, CheckoutModifiers checkoutModifiers, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 5
0
 /// <summary>
 /// Constructor to set up native callback for given managed delegate.
 /// </summary>
 /// <param name="onCheckoutProgress"><see cref="CheckoutProgressHandler"/> delegate to call in response to checkout progress_cb</param>
 /// <param name="onCheckoutNotify"><see cref="CheckoutNotifyHandler"/> delegate to call in response to checkout notification callback.</param>
 private CheckoutCallbacks(CheckoutProgressHandler onCheckoutProgress, CheckoutNotifyHandler onCheckoutNotify)
 {
     this.onCheckoutProgress = onCheckoutProgress;
     this.onCheckoutNotify = onCheckoutNotify;
 }
Exemplo n.º 6
0
 public Branch Checkout(Commit commit, CheckoutModifiers checkoutModifiers, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Checkout the specified <see cref="LibGit2Sharp.Commit"/>.
        /// <para>
        ///   Will detach the HEAD and make it point to this commit sha.
        /// </para>
        /// </summary>
        /// <param name="commit">The <see cref="LibGit2Sharp.Commit"/> to check out.</param>
        /// <param name="checkoutModifiers"><see cref="CheckoutModifiers"/> controlling checkout behavior.</param>
        /// <param name="onCheckoutProgress"><see cref="CheckoutProgressHandler"/> that checkout progress is reported through.</param>
        /// <param name="checkoutNotificationOptions"><see cref="CheckoutNotificationOptions"/> to manage checkout notifications.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public Branch Checkout(Commit commit, CheckoutModifiers checkoutModifiers, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions)
        {
            Checkout(commit.Tree, checkoutModifiers, onCheckoutProgress, checkoutNotificationOptions, commit.Id.Sha, commit.Id.Sha, true);

            return(Head);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Checkout the tip commit of this <see cref="Branch"/> object
 /// with a callback for progress reporting. If this commit is the
 /// current tip of the branch, will checkout the named branch. Otherwise,
 /// will checkout the tip commit as a detached HEAD.
 /// </summary>
 /// <param name="checkoutModifiers">Options controlling checkout behavior.</param>
 /// <param name="onCheckoutProgress">Callback method to report checkout progress updates through.</param>
 /// <param name="checkoutNotificationOptions"><see cref="CheckoutNotificationOptions"/> to manage checkout notifications.</param>
 public virtual void Checkout(CheckoutModifiers checkoutModifiers, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions)
 {
     repo.Checkout(this, checkoutModifiers, onCheckoutProgress, checkoutNotificationOptions);
 }
Exemplo n.º 9
0
 public Branch Checkout(Commit commit, CheckoutModifiers checkoutModifiers, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions, Signature signature = null)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
        /// <summary>
        ///   Checkout the specified <see cref = "Branch" />, reference or SHA.
        /// </summary>
        /// <param name = "committishOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
        /// <param name="checkoutOptions"><see cref = "CheckoutOptions" /> controlling checkout behavior.</param>
        /// <param name="onCheckoutProgress"><see cref = "CheckoutProgressHandler" /> that checkout progress is reported through.</param>
        /// <returns>The <see cref = "Branch" /> that was checked out.</returns>
        public Branch Checkout(string committishOrBranchSpec, CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
        {
            Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec");

            Branch branch = TryResolveBranch(committishOrBranchSpec);

            if (branch != null)
            {
                return(Checkout(branch, checkoutOptions, onCheckoutProgress));
            }

            var previousHeadName = Info.IsHeadDetached ? Head.Tip.Sha : Head.Name;

            Commit commit = LookupCommit(committishOrBranchSpec);

            CheckoutTree(commit.Tree, checkoutOptions, onCheckoutProgress);

            // Update HEAD.
            Refs.UpdateTarget("HEAD", commit.Id.Sha);
            if (committishOrBranchSpec != "HEAD")
            {
                LogCheckout(previousHeadName, commit.Id, committishOrBranchSpec);
            }

            return(Head);
        }
Exemplo n.º 11
0
 /// <summary>
 ///   Checkout the tip commit of this <see cref = "Branch" /> object
 ///   with a callback for progress reporting. If this commit is the
 ///   current tip of the branch, will checkout the named branch. Otherwise,
 ///   will checkout the tip commit as a detached HEAD.
 /// </summary>
 /// <param name="checkoutOptions">Options controlling checkout behavior.</param>
 /// <param name="onCheckoutProgress">Callback method to report checkout progress updates through.</param>
 public virtual void Checkout(CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
 {
     repo.Checkout(this, checkoutOptions, onCheckoutProgress);
 }
Exemplo n.º 12
0
 /// <summary>
 ///   Constructor to set up native callback for given managed delegate.
 /// </summary>
 /// <param name="onCheckoutProgress"><see cref="CheckoutProgressHandler"/> delegate to call in response to checkout progress_cb</param>
 private CheckoutCallbacks(CheckoutProgressHandler onCheckoutProgress)
 {
     this.onCheckoutProgress = onCheckoutProgress;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Generate a delegate matching the signature of the native progress_cb callback and wraps the <see cref="CheckoutProgressHandler"/> delegate.
 /// </summary>
 /// <param name="onCheckoutProgress"><see cref="CheckoutProgressHandler"/> that should be wrapped in the native callback.</param>
 /// <param name="onCheckoutNotify"><see cref="CheckoutNotifyHandler"/> delegate to call in response to checkout notification callback.</param>
 /// <returns>The delegate with signature matching the expected native callback.</returns>
 internal static CheckoutCallbacks GenerateCheckoutCallbacks(CheckoutProgressHandler onCheckoutProgress, CheckoutNotifyHandler onCheckoutNotify)
 {
     return(new CheckoutCallbacks(onCheckoutProgress, onCheckoutNotify));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Constructor to set up native callback for given managed delegate.
 /// </summary>
 /// <param name="onCheckoutProgress"><see cref="CheckoutProgressHandler"/> delegate to call in response to checkout progress_cb</param>
 /// <param name="onCheckoutNotify"><see cref="CheckoutNotifyHandler"/> delegate to call in response to checkout notification callback.</param>
 private CheckoutCallbacks(CheckoutProgressHandler onCheckoutProgress, CheckoutNotifyHandler onCheckoutNotify)
 {
     this.onCheckoutProgress = onCheckoutProgress;
     this.onCheckoutNotify   = onCheckoutNotify;
 }
Exemplo n.º 15
0
        /// <summary>
        ///   Checkout the specified <see cref = "Branch" />, reference or SHA.
        /// </summary>
        /// <param name = "committishOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
        /// <param name="checkoutOptions"><see cref = "CheckoutOptions" /> controlling checkout behavior.</param>
        /// <param name="onCheckoutProgress"><see cref = "CheckoutProgressHandler" /> that checkout progress is reported through.</param>
        /// <returns>The <see cref = "Branch" /> that was checked out.</returns>
        public Branch Checkout(string committishOrBranchSpec, CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
        {
            Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec");

            var branch = Branches[committishOrBranchSpec];

            if (branch != null)
            {
                return(Checkout(branch, checkoutOptions, onCheckoutProgress));
            }

            Commit commit = LookupCommit(committishOrBranchSpec);

            CheckoutTree(commit.Tree, checkoutOptions, onCheckoutProgress);

            // Update HEAD.
            Refs.UpdateTarget("HEAD", commit.Id.Sha);

            return(Head);
        }
Exemplo n.º 16
0
 /// <summary>
 ///   Constructor to set up native callback for given managed delegate.
 /// </summary>
 /// <param name="onCheckoutProgress"><see cref="CheckoutProgressHandler"/> delegate to call in response to checkout progress_cb</param>
 private CheckoutCallbacks(CheckoutProgressHandler onCheckoutProgress)
 {
     this.onCheckoutProgress = onCheckoutProgress;
 }
Exemplo n.º 17
0
        public void CanRecursivelyCloneSubmodules()
        {
            var    uri = new Uri($"file://{Path.GetFullPath(SandboxSubmoduleSmallTestRepo())}");
            var    scd = BuildSelfCleaningDirectory();
            string relativeSubmodulePath = "submodule_target_wd";

            // Construct the expected URL the submodule will clone from.
            string expectedSubmoduleUrl = Path.Combine(Path.GetDirectoryName(uri.AbsolutePath), relativeSubmodulePath);

            expectedSubmoduleUrl = expectedSubmoduleUrl.Replace('\\', '/');

            Dictionary <string, CloneCallbackInfo> callbacks = new Dictionary <string, CloneCallbackInfo>();

            CloneCallbackInfo currentEntry  = null;
            bool unexpectedOrderOfCallbacks = false;

            CheckoutProgressHandler checkoutProgressHandler = (x, y, z) =>
            {
                if (currentEntry != null)
                {
                    currentEntry.CheckoutProgressCalled = true;
                }
                else
                {
                    // Should not be called if there is not a current
                    // callbackInfo entry.
                    unexpectedOrderOfCallbacks = true;
                }
            };

            UpdateTipsHandler remoteRefUpdated = (x, y, z) =>
            {
                if (currentEntry != null)
                {
                    currentEntry.RemoteRefUpdateCalled = true;
                }
                else
                {
                    // Should not be called if there is not a current
                    // callbackInfo entry.
                    unexpectedOrderOfCallbacks = true;
                }

                return(true);
            };

            RepositoryOperationStarting repositoryOperationStarting = (x) =>
            {
                if (currentEntry != null)
                {
                    // Should not be called if there is a current
                    // callbackInfo entry.
                    unexpectedOrderOfCallbacks = true;
                }

                currentEntry = new CloneCallbackInfo();
                currentEntry.StartingWorkInRepositoryCalled = true;
                currentEntry.RecursionDepth = x.RecursionDepth;
                currentEntry.RemoteUrl      = x.RemoteUrl;
                callbacks.Add(x.RepositoryPath, currentEntry);

                return(true);
            };

            RepositoryOperationCompleted repositoryOperationCompleted = (x) =>
            {
                if (currentEntry != null)
                {
                    currentEntry.FinishedWorkInRepositoryCalled = true;
                    currentEntry = null;
                }
                else
                {
                    // Should not be called if there is not a current
                    // callbackInfo entry.
                    unexpectedOrderOfCallbacks = true;
                }
            };

            CloneOptions options = new CloneOptions()
            {
                RecurseSubmodules            = true,
                OnCheckoutProgress           = checkoutProgressHandler,
                OnUpdateTips                 = remoteRefUpdated,
                RepositoryOperationStarting  = repositoryOperationStarting,
                RepositoryOperationCompleted = repositoryOperationCompleted,
            };

            string clonedRepoPath = Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
            string workDirPath;

            using (Repository repo = new Repository(clonedRepoPath))
            {
                workDirPath = repo.Info.WorkingDirectory.TrimEnd(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
            }

            // Verification:
            // Verify that no callbacks were called in an unexpected order.
            Assert.False(unexpectedOrderOfCallbacks);

            Dictionary <string, CloneCallbackInfo> expectedCallbackInfo = new Dictionary <string, CloneCallbackInfo>();

            expectedCallbackInfo.Add(workDirPath, new CloneCallbackInfo()
            {
                RecursionDepth = 0,
                RemoteUrl      = uri.AbsolutePath,
                StartingWorkInRepositoryCalled = true,
                FinishedWorkInRepositoryCalled = true,
                CheckoutProgressCalled         = true,
                RemoteRefUpdateCalled          = true,
            });

            expectedCallbackInfo.Add(Path.Combine(workDirPath, relativeSubmodulePath), new CloneCallbackInfo()
            {
                RecursionDepth = 1,
                RemoteUrl      = expectedSubmoduleUrl,
                StartingWorkInRepositoryCalled = true,
                FinishedWorkInRepositoryCalled = true,
                CheckoutProgressCalled         = true,
                RemoteRefUpdateCalled          = true,
            });

            // Callbacks for each expected repository that is cloned
            foreach (KeyValuePair <string, CloneCallbackInfo> kvp in expectedCallbackInfo)
            {
                CloneCallbackInfo entry = null;
                Assert.True(callbacks.TryGetValue(kvp.Key, out entry), string.Format("{0} was not found in callbacks.", kvp.Key));

                Assert.Equal(kvp.Value.RemoteUrl, entry.RemoteUrl);
                Assert.Equal(kvp.Value.RecursionDepth, entry.RecursionDepth);
                Assert.Equal(kvp.Value.StartingWorkInRepositoryCalled, entry.StartingWorkInRepositoryCalled);
                Assert.Equal(kvp.Value.FinishedWorkInRepositoryCalled, entry.FinishedWorkInRepositoryCalled);
                Assert.Equal(kvp.Value.CheckoutProgressCalled, entry.CheckoutProgressCalled);
                Assert.Equal(kvp.Value.RemoteRefUpdateCalled, entry.RemoteRefUpdateCalled);
            }

            // Verify the state of the submodule
            using (Repository repo = new Repository(clonedRepoPath))
            {
                var sm = repo.Submodules[relativeSubmodulePath];
                Assert.True(sm.RetrieveStatus().HasFlag(SubmoduleStatus.InWorkDir |
                                                        SubmoduleStatus.InConfig |
                                                        SubmoduleStatus.InIndex |
                                                        SubmoduleStatus.InHead));

                Assert.NotNull(sm.HeadCommitId);
                Assert.Equal("480095882d281ed676fe5b863569520e54a7d5c0", sm.HeadCommitId.Sha);

                Assert.False(repo.RetrieveStatus().IsDirty);
            }
        }
Exemplo n.º 18
0
 public Branch Checkout(string committishOrBranchSpec, CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
 {
     return(Checkout(committishOrBranchSpec, (CheckoutModifiers)checkoutOptions, onCheckoutProgress, null));
 }
Exemplo n.º 19
0
 public void CheckoutPaths(string committishOrBranchSpec, IList <string> paths, CheckoutModifiers checkoutOptions, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 20
0
 public Branch Checkout(Branch branch, CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
 {
     return(Checkout(branch, (CheckoutModifiers)checkoutOptions, onCheckoutProgress, null));
 }
Exemplo n.º 21
0
        public Branch Checkout(Commit commit, CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
        {
            Checkout(commit.Tree, (CheckoutModifiers)checkoutOptions, onCheckoutProgress, null, commit.Id.Sha, commit.Id.Sha, true);

            return(Head);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Checkout the specified <see cref="Branch"/>, reference or SHA.
        /// <para>
        ///   If the committishOrBranchSpec parameter resolves to a branch name, then the checked out HEAD will
        ///   will point to the branch. Otherwise, the HEAD will be detached, pointing at the commit sha.
        /// </para>
        /// </summary>
        /// <param name="committishOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
        /// <param name="checkoutModifiers"><see cref="CheckoutModifiers"/> controlling checkout behavior.</param>
        /// <param name="onCheckoutProgress"><see cref="CheckoutProgressHandler"/> that checkout progress is reported through.</param>
        /// <param name="checkoutNotifications"><see cref="CheckoutNotificationOptions"/> to manage checkout notifications.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public Branch Checkout(string committishOrBranchSpec, CheckoutModifiers checkoutModifiers, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotifications)
        {
            Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec");

            var handles = Proxy.git_revparse_ext(Handle, committishOrBranchSpec);

            if (handles == null)
            {
                Ensure.GitObjectIsNotNull(null, committishOrBranchSpec);
            }

            var       objH = handles.Item1;
            var       refH = handles.Item2;
            GitObject obj;

            try
            {
                if (!refH.IsInvalid)
                {
                    var reference = Reference.BuildFromPtr <Reference>(refH, this);
                    if (reference.IsLocalBranch())
                    {
                        Branch branch = Branches[reference.CanonicalName];
                        return(Checkout(branch, checkoutModifiers, onCheckoutProgress, checkoutNotifications));
                    }
                }

                obj = GitObject.BuildFrom(this, Proxy.git_object_id(objH), Proxy.git_object_type(objH),
                                          PathFromRevparseSpec(committishOrBranchSpec));
            }
            finally
            {
                objH.Dispose();
                refH.Dispose();
            }

            Commit commit = obj.DereferenceToCommit(true);

            Checkout(commit.Tree, checkoutModifiers, onCheckoutProgress, checkoutNotifications, commit.Id.Sha, committishOrBranchSpec,
                     committishOrBranchSpec != "HEAD");

            return(Head);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Updates specifed paths in the index and working directory with the versions from the specified branch, reference, or SHA.
        /// <para>
        /// This method does not switch branches or update the current repository HEAD.
        /// </para>
        /// </summary>
        /// <param name="committishOrBranchSpec">A revparse spec for the commit or branch to checkout paths from.</param>
        /// <param name="paths">The paths to checkout.</param>
        /// <param name="checkoutOptions">Options controlling checkout behavior.</param>
        /// <param name="onCheckoutProgress">Callback method to report checkout progress updates through.</param>
        /// <param name="checkoutNotificationOptions"><see cref="CheckoutNotificationOptions"/> to manage checkout notifications.</param>
        public void CheckoutPaths(string committishOrBranchSpec, IList <string> paths, CheckoutModifiers checkoutOptions, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions)
        {
            Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec");
            Commit commit = LookupCommit(committishOrBranchSpec);

            CheckoutTree(commit.Tree, paths, checkoutOptions, onCheckoutProgress, checkoutNotificationOptions);
        }
Exemplo n.º 24
0
 public virtual void Checkout(CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
 {
     Checkout((CheckoutModifiers)checkoutOptions, onCheckoutProgress, null);
 }
Exemplo n.º 25
0
        public void CheckoutPaths(string committishOrBranchSpec, IList <string> paths, CheckoutModifiers checkoutOptions, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions)
        {
            var opts = new CheckoutOptions
            {
                CheckoutModifiers           = checkoutOptions,
                OnCheckoutProgress          = onCheckoutProgress,
                CheckoutNotificationOptions = checkoutNotificationOptions
            };

            CheckoutPaths(committishOrBranchSpec, paths, opts);
        }
Exemplo n.º 26
0
 public Branch Checkout(Commit commit, CheckoutModifiers checkoutModifiers, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions, Signature signature = null)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 27
0
 public void CheckoutPaths(string committishOrBranchSpec, IList<string> paths, CheckoutModifiers checkoutOptions, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 28
0
 /// <summary>
 /// Generate a delegate matching the signature of the native progress_cb callback and wraps the <see cref="CheckoutProgressHandler"/> delegate.
 /// </summary>
 /// <param name="onCheckoutProgress"><see cref="CheckoutProgressHandler"/> that should be wrapped in the native callback.</param>
 /// <param name="onCheckoutNotify"><see cref="CheckoutNotifyHandler"/> delegate to call in response to checkout notification callback.</param>
 /// <returns>The delegate with signature matching the expected native callback.</returns>
 internal static CheckoutCallbacks From(CheckoutProgressHandler onCheckoutProgress, CheckoutNotifyHandler onCheckoutNotify)
 {
     return new CheckoutCallbacks(onCheckoutProgress, onCheckoutNotify);
 }
Exemplo n.º 29
0
 public Branch Checkout(string committishOrBranchSpec, CheckoutModifiers checkoutModifiers, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions)
 {
     throw new System.NotImplementedException();
 }