Exemplo n.º 1
0
        /// <summary>
        /// Internal implementation of Checkout that expects the ID of the checkout target
        /// to already be in the form of a canonical branch name or a commit ID.
        /// </summary>
        /// <param name="tree">The <see cref="Tree"/> 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="checkoutNotificationOptions"><see cref="CheckoutNotificationOptions"/> to manage checkout notifications.</param>
        /// <param name="headTarget">Target for the new HEAD.</param>
        /// <param name="refLogHeadSpec">The spec which will be written as target in the reflog.</param>
        /// <param name="writeReflogEntry">Will a reflog entry be created.</param>
        private void Checkout(
            Tree tree,
            CheckoutModifiers checkoutModifiers,
            CheckoutProgressHandler onCheckoutProgress,
            CheckoutNotificationOptions checkoutNotificationOptions,
            string headTarget, string refLogHeadSpec, bool writeReflogEntry)
        {
            var previousHeadName = Info.IsHeadDetached ? Head.Tip.Sha : Head.Name;

            var opts = new CheckoutOptions
            {
                CheckoutModifiers           = checkoutModifiers,
                OnCheckoutProgress          = onCheckoutProgress,
                CheckoutNotificationOptions = checkoutNotificationOptions
            };

            CheckoutTree(tree, null, opts);

            Refs.UpdateTarget("HEAD", headTarget);

            if (writeReflogEntry)
            {
                LogCheckout(previousHeadName, Head.Tip.Id, refLogHeadSpec);
            }
        }
Exemplo n.º 2
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.º 3
0
        /// <summary>
        /// Checkout the tip commit of the specified <see cref="Branch"/> object. 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="repository">The repository to act on</param>
        /// <param name="branch">The <see cref="Branch"/> to check out.</param>
        /// <param name="options"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public static Branch Checkout(IRepository repository, Branch branch, CheckoutOptions options)
        {
            Ensure.ArgumentNotNull(repository, "repository");
            Ensure.ArgumentNotNull(branch, "branch");
            Ensure.ArgumentNotNull(options, "options");

            // Make sure this is not an unborn branch.
            if (branch.Tip == null)
            {
                throw new UnbornBranchException("The tip of branch '{0}' is null. There's nothing to checkout.",
                                                branch.FriendlyName);
            }

            Console.WriteLine("branch: {0}", branch);
            if (!branch.IsRemote && !(branch is DetachedHead) &&
                string.Equals(repository.Refs[branch.CanonicalName].TargetIdentifier, branch.Tip.Id.Sha,
                              StringComparison.OrdinalIgnoreCase))
            {
                Checkout(repository, branch.Tip.Tree, options, branch.CanonicalName);
            }
            else
            {
                Checkout(repository, branch.Tip.Tree, options, branch.Tip.Id.Sha);
            }

            return(repository.Head);
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Checkout the tip commit of the specified <see cref = "Branch" /> object. 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="branch">The <see cref = "Branch" /> to check out. </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(Branch branch, CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
        {
            Ensure.ArgumentNotNull(branch, "branch");

            // Make sure this is not an unborn branch.
            if (branch.Tip == null)
            {
                throw new OrphanedHeadException(
                          string.Format(CultureInfo.InvariantCulture,
                                        "The tip of branch '{0}' is null. There's nothing to checkout.", branch.Name));
            }

            CheckoutTree(branch.Tip.Tree, checkoutOptions, onCheckoutProgress);

            // Update HEAD.
            if (!branch.IsRemote &&
                string.Equals(Refs[branch.CanonicalName].TargetIdentifier, branch.Tip.Id.Sha,
                              StringComparison.OrdinalIgnoreCase))
            {
                Refs.UpdateTarget("HEAD", branch.CanonicalName);
            }
            else
            {
                Refs.UpdateTarget("HEAD", branch.Tip.Id.Sha);
            }

            return(Head);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Checkout the tip commit of the specified <see cref="Branch"/> object. 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="repository">The repository to act on</param>
        /// <param name="branch">The <see cref="Branch"/> to check out.</param>
        /// <param name="options"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public static Branch Checkout(IRepository repository, Branch branch, CheckoutOptions options)
        {
            Ensure.ArgumentNotNull(repository, "repository");
            Ensure.ArgumentNotNull(branch, "branch");
            Ensure.ArgumentNotNull(options, "options");

            // Make sure this is not an unborn branch.
            if (branch.Tip == null)
            {
                throw new UnbornBranchException("The tip of branch '{0}' is null. There's nothing to checkout.",
                    branch.FriendlyName);
            }

            if (!branch.IsRemote && !(branch is DetachedHead) &&
                string.Equals(repository.Refs[branch.CanonicalName].TargetIdentifier, branch.Tip.Id.Sha,
                    StringComparison.OrdinalIgnoreCase))
            {
                Checkout(repository, branch.Tip.Tree, options, branch.CanonicalName);
            }
            else
            {
                Checkout(repository, branch.Tip.Tree, options, branch.Tip.Id.Sha);
            }

            return repository.Head;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Checkout the specified tree.
        /// </summary>
        /// <param name="tree">The <see cref="Tree"/> to checkout.</param>
        /// <param name="paths">The paths to checkout.</param>
        /// <param name="opts">Collection of parameters controlling checkout behavior.</param>
        private void CheckoutTree(
            Tree tree,
            IList <string> paths,
            CheckoutOptions opts)
        {
            CheckoutNotifyHandler onCheckoutNotify    = opts.CheckoutNotificationOptions != null ? opts.CheckoutNotificationOptions.CheckoutNotifyHandler : null;
            CheckoutNotifyFlags   checkoutNotifyFlags = opts.CheckoutNotificationOptions != null ? opts.CheckoutNotificationOptions.NotifyFlags : default(CheckoutNotifyFlags);
            CheckoutCallbacks     checkoutCallbacks   = CheckoutCallbacks.GenerateCheckoutCallbacks(opts.OnCheckoutProgress, onCheckoutNotify);

            GitStrArrayIn strArray = (paths != null && paths.Count > 0) ? GitStrArrayIn.BuildFrom(ToFilePaths(paths)) : null;

            var options = new GitCheckoutOpts
            {
                version           = 1,
                checkout_strategy = CheckoutStrategy.GIT_CHECKOUT_SAFE,
                progress_cb       = checkoutCallbacks.CheckoutProgressCallback,
                notify_cb         = checkoutCallbacks.CheckoutNotifyCallback,
                notify_flags      = checkoutNotifyFlags,
                paths             = strArray
            };

            try
            {
                if (opts.CheckoutModifiers.HasFlag(CheckoutModifiers.Force))
                {
                    options.checkout_strategy = CheckoutStrategy.GIT_CHECKOUT_FORCE;
                }

                Proxy.git_checkout_tree(Handle, tree.Id, ref options);
            }
            finally
            {
                options.Dispose();
            }
        }
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="repository">The repository to act on</param>
        /// <param name="commit">The <see cref="LibGit2Sharp.Commit"/> to check out.</param>
        /// <param name="options"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public static Branch Checkout(IRepository repository, Commit commit, CheckoutOptions options)
        {
            Ensure.ArgumentNotNull(repository, "repository");
            Ensure.ArgumentNotNull(commit, "commit");
            Ensure.ArgumentNotNull(options, "options");

            Checkout(repository, commit.Tree, options, commit.Id.Sha);

            return(repository.Head);
        }
Exemplo n.º 8
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.º 9
0
        public void Reset()
        {
            // Undo potential impact from earlier tests
            using (var repository = new LibGit2Sharp.Repository(Module.WorkingDir))
            {
                var options = new LibGit2Sharp.CheckoutOptions();
                repository.Reset(LibGit2Sharp.ResetMode.Hard, (LibGit2Sharp.Commit)repository.Lookup(CommitHash, LibGit2Sharp.ObjectType.Commit), options);
                repository.RemoveUntrackedFiles();
            }

            new CommitMessageManager(Module.WorkingDirGitDir, Module.CommitEncoding).ResetCommitMessage();
        }
        public void Reset()
        {
            // Undo potential impact from earlier tests
            using (var repository = new LibGit2Sharp.Repository(Module.WorkingDir))
            {
                var options = new LibGit2Sharp.CheckoutOptions();
                repository.Reset(LibGit2Sharp.ResetMode.Hard, (LibGit2Sharp.Commit)repository.Lookup(CommitHash, LibGit2Sharp.ObjectType.Commit), options);
                repository.RemoveUntrackedFiles();
            }

            CommitHelper.SetCommitMessage(Module, commitMessageText: null, amendCommit: false);
        }
Exemplo n.º 11
0
        private void FastForward(Commit fastForwardCommit)
        {
            var checkoutOpts = new CheckoutOptions
            {
                CheckoutModifiers = CheckoutModifiers.None,
            };

            CheckoutTree(fastForwardCommit.Tree, null, checkoutOpts);

            var reference = Refs.Head.ResolveToDirectReference();

            Refs.UpdateTarget(reference, fastForwardCommit.Id.Sha);

            // TODO: Update Reflog...
        }
Exemplo n.º 12
0
        /// <summary>
        ///   Internal implementation of Checkout that expects the ID of the checkout target
        ///   to already be in the form of a canonical branch name or a commit ID.
        /// </summary>
        /// <param name="tree">The <see cref="Tree"/> 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>
        private void CheckoutTree(Tree tree, CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
        {
            GitCheckoutOpts options = new GitCheckoutOpts
            {
                version           = 1,
                checkout_strategy = CheckoutStrategy.GIT_CHECKOUT_SAFE,
                progress_cb       = CheckoutCallbacks.GenerateCheckoutCallbacks(onCheckoutProgress)
            };

            if (checkoutOptions.HasFlag(CheckoutOptions.Force))
            {
                options.checkout_strategy = CheckoutStrategy.GIT_CHECKOUT_FORCE;
            }

            Proxy.git_checkout_tree(this.Handle, tree.Id, ref options);
        }
Exemplo n.º 13
0
        public virtual void Checkout(CheckoutModifiers checkoutModifiers, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotificationOptions)
        {
            var options = new CheckoutOptions
            {
                CheckoutModifiers  = checkoutModifiers,
                OnCheckoutProgress = onCheckoutProgress,
            };

            if (checkoutNotificationOptions != null)
            {
                options.OnCheckoutNotify    = checkoutNotificationOptions.CheckoutNotifyHandler;
                options.CheckoutNotifyFlags = checkoutNotificationOptions.NotifyFlags;
            }

            Checkout(options, null);
        }
        /// <inheritdoc />
        public IObservable<Unit> Checkout(
            string commitOrBranchSpec,
            IObserver<Tuple<string, int>> observer)
        {
            var signature = _repository.Config.BuildSignature(DateTimeOffset.Now);

            var options = new CheckoutOptions
            {
                OnCheckoutProgress = ProgressFactory.CreateHandler(observer)
            };

            return Observable.Start(() =>
            {
                _repository.Checkout(commitOrBranchSpec, options, signature);
                SignalCompleted(observer);
            }, Scheduler.Default);
        }
Exemplo n.º 15
0
        public static bool TryCheckout(this Repository repository, Branch branch, bool force = false)
        {
            CheckoutOptions options = new CheckoutOptions();
            if (force)
            {
                options.CheckoutModifiers = CheckoutModifiers.Force;
            }
            try
            {
                var checkoutBranch = repository.Checkout(branch, options);
                GitFlowExtensions.Log("Checked out Branch : " + checkoutBranch.FriendlyName);
            }
            catch (CheckoutConflictException conflict)
            {
                GitFlowExtensions.LogError("Checkout Failed", conflict.Message);
                return false;
            }

            return true;
        }
Exemplo n.º 16
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.º 17
0
        public void Reset()
        {
            // Undo potential impact from earlier tests
            using (var repository = new LibGit2Sharp.Repository(Module.WorkingDir))
            {
                var options = new LibGit2Sharp.CheckoutOptions();
                repository.Reset(LibGit2Sharp.ResetMode.Hard, (LibGit2Sharp.Commit)repository.Lookup(CommitHash, LibGit2Sharp.ObjectType.Commit), options);
                repository.RemoveUntrackedFiles();

                var remoteNames = repository.Network.Remotes.Select(remote => remote.Name).ToArray();
                foreach (var remoteName in remoteNames)
                {
                    repository.Network.Remotes.Remove(remoteName);
                }

                repository.Config.Set(SettingKeyString.UserName, "author");
                repository.Config.Set(SettingKeyString.UserEmail, "*****@*****.**");
            }

            new CommitMessageManager(Module.WorkingDirGitDir, Module.CommitEncoding).ResetCommitMessage();
        }
Exemplo n.º 18
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="repository">The repository to act on</param>
        /// <param name="committishOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
        /// <param name="options"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public static Branch Checkout(IRepository repository, string committishOrBranchSpec, CheckoutOptions options)
        {
            Ensure.ArgumentNotNull(repository, "repository");
            Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec");
            Ensure.ArgumentNotNull(options, "options");

            Reference reference;
            GitObject obj;

            repository.RevParse(committishOrBranchSpec, out reference, out obj);
            if (reference != null && reference.IsLocalBranch)
            {
                Branch branch = repository.Branches[reference.CanonicalName];
                return Checkout(repository, branch, options);
            }

            Commit commit = obj.DereferenceToCommit(true);
            Checkout(repository, commit.Tree,  options, committishOrBranchSpec);

            return repository.Head;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Internal implementation of Checkout that expects the ID of the checkout target
        /// to already be in the form of a canonical branch name or a commit ID.
        /// </summary>
        /// <param name="repository">The repository to act on</param>
        /// <param name="tree">The <see cref="Tree"/> to checkout.</param>
        /// <param name="checkoutOptions"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
        /// <param name="refLogHeadSpec">The spec which will be written as target in the reflog.</param>
        public static void Checkout(IRepository repository, Tree tree, CheckoutOptions checkoutOptions, string refLogHeadSpec)
        {
            repository.Checkout(tree, null, checkoutOptions);

            repository.Refs.MoveHeadTarget(refLogHeadSpec);
        }
Exemplo n.º 20
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="repository">The repository to act on</param>
        /// <param name="commit">The <see cref="LibGit2Sharp.Commit"/> to check out.</param>
        /// <param name="options"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public static Branch Checkout(IRepository repository, Commit commit, CheckoutOptions options)
        {
            Ensure.ArgumentNotNull(repository, "repository");
            Ensure.ArgumentNotNull(commit, "commit");
            Ensure.ArgumentNotNull(options, "options");

            Checkout(repository, commit.Tree, options, commit.Id.Sha);

            return repository.Head;
        }
Exemplo n.º 21
0
 public void CheckoutPaths(string commitishOrBranchSpec, IEnumerable<string> paths, CheckoutOptions options = null)
 {
     Repository.CheckoutPaths(commitishOrBranchSpec, paths, options ?? new CheckoutOptions());
 }
 /// <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="repository">The <see cref="IRepository"/> being worked with.</param>
 /// <param name="committishOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
 /// <param name="options"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
 /// <returns>The <see cref="Branch"/> that was checked out.</returns>
 public static Branch Checkout(this IRepository repository, string committishOrBranchSpec, CheckoutOptions options)
 {
     return(repository.Checkout(committishOrBranchSpec, options, null));
 }
 /// <summary>
 /// Checkout the tip commit of the specified <see cref="Branch"/> object. 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="repository">The <see cref="IRepository"/> being worked with.</param>
 /// <param name="branch">The <see cref="Branch"/> to check out.</param>
 /// <param name="options"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
 /// <returns>The <see cref="Branch"/> that was checked out.</returns>
 public static Branch Checkout(this IRepository repository, Branch branch, CheckoutOptions options)
 {
     return(repository.Checkout(branch, options, null));
 }
Exemplo n.º 24
0
 public NodeBranch Checkout(Commit commit, CheckoutOptions options = null, Signature signature = null)
 {
     return new NodeBranch(Repository.Checkout(commit, options ?? new CheckoutOptions(), signature));
 }
        /// <summary>
        /// Checkout the specified <see cref="Branch"/>, reference or SHA.
        /// </summary>
        /// <param name="repository">The <see cref="Repository"/> being worked with.</param>
        /// <param name="commitOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public static Branch Checkout(this IRepository repository, string commitOrBranchSpec)
        {
            CheckoutOptions options = new CheckoutOptions();

            return(repository.Checkout(commitOrBranchSpec, options));
        }
        /// <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="repository">The <see cref="Repository"/> being worked with.</param>
        /// <param name="commit">The <see cref="LibGit2Sharp.Commit"/> to check out.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public static Branch Checkout(this IRepository repository, Commit commit)
        {
            CheckoutOptions options = new CheckoutOptions();

            return(repository.Checkout(commit, options));
        }
Exemplo n.º 27
0
 public Branch Checkout(Branch branch, CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
 {
     return(Checkout(branch, (CheckoutModifiers)checkoutOptions, onCheckoutProgress, null));
 }
Exemplo n.º 28
0
 public Branch Checkout(string committishOrBranchSpec, CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
 {
     return(Checkout(committishOrBranchSpec, (CheckoutModifiers)checkoutOptions, onCheckoutProgress, null));
 }
Exemplo n.º 29
0
 public void DiscardChanges(IEnumerable<string> paths)
 {
     var enumerable = paths as string[] ?? paths.ToArray();
     _jobQueue.AddJob(
         $"DiscardChanges: {string.Join(",", enumerable)}",
         () =>
         {
             var opts = new CheckoutOptions {CheckoutModifiers = CheckoutModifiers.Force};
             Internal.CheckoutPaths("HEAD", enumerable, opts);
         });
 }
Exemplo n.º 30
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="repository">The repository to act on</param>
        /// <param name="committishOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
        /// <param name="options"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public static Branch Checkout(IRepository repository, string committishOrBranchSpec, CheckoutOptions options)
        {
            Ensure.ArgumentNotNull(repository, "repository");
            Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec");
            Ensure.ArgumentNotNull(options, "options");

            Reference reference;
            GitObject obj;

            Console.WriteLine("revparsing {0}", committishOrBranchSpec);
            repository.RevParse(committishOrBranchSpec, out reference, out obj);
            Console.WriteLine("grabbed ref {0}, obj {1}", reference, obj);
            if (reference != null && reference.IsLocalBranch)
            {
                Branch branch = repository.Branches[reference.CanonicalName];
                Console.WriteLine("grabbed branch {0}", branch);
                return(Checkout(repository, branch, options));
            }

            Commit commit = obj.DereferenceToCommit(true);

            Console.WriteLine("dereferenced to commit {0}", commit);
            Checkout(repository, commit.Tree, options, committishOrBranchSpec);

            return(repository.Head);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Internal implementation of Checkout that expects the ID of the checkout target
        /// to already be in the form of a canonical branch name or a commit ID.
        /// </summary>
        /// <param name="repository">The repository to act on</param>
        /// <param name="tree">The <see cref="Tree"/> to checkout.</param>
        /// <param name="checkoutOptions"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
        /// <param name="refLogHeadSpec">The spec which will be written as target in the reflog.</param>
        public static void Checkout(IRepository repository, Tree tree, CheckoutOptions checkoutOptions, string refLogHeadSpec)
        {
            repository.Checkout(tree, null, checkoutOptions);

            repository.Refs.MoveHeadTarget(refLogHeadSpec);
        }
        public GitActionResult<GitBranchInfo> Checkout(GitBranchInfo info, bool force = false)
        {
            using (var repository = GetRepository())
            {
                var result = new GitActionResult<GitBranchInfo>();

                CheckoutOptions options = new CheckoutOptions();
                var branch = repository.Branches.FirstOrDefault(
                        x => string.Equals(x.CanonicalName, info.CanonicalName, StringComparison.OrdinalIgnoreCase));

                if (force)
                {
                    options.CheckoutModifiers = CheckoutModifiers.Force;

                }
                try
                {
                    var checkoutBranch = repository.Checkout(branch, options);
                    if (checkoutBranch != null)
                    {
                        result.Item = new GitBranchInfo
                        {
                            CanonicalName = checkoutBranch.CanonicalName,
                            RemoteName = checkoutBranch.Remote?.Name,
                            Name = checkoutBranch.FriendlyName,
                            IsRemote = checkoutBranch.IsRemote
                        };
                        result.Succeeded = true;
                        return result;
                    }
                    result.Succeeded = false;
                }
                catch (CheckoutConflictException conflict)
                {
                    result.Succeeded = false;
                    result.ErrorMessage = conflict.Message;
                }

                return result;
            }
        }
Exemplo n.º 33
0
 public NodeBranch Checkout(string commitishOrBranchSpec, CheckoutOptions options = null, Signature signature = null)
 {
     return new NodeBranch(Repository.Checkout(commitishOrBranchSpec, options ?? new CheckoutOptions(), signature));
 }
Exemplo n.º 34
0
 public Branch Checkout(string committishOrBranchSpec, CheckoutOptions options, Signature signature = null)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Checkout the commit pointed at by the tip of the specified <see cref="Branch"/>.
        /// <para>
        ///   If this commit is the current tip of the branch as it exists in the repository, the HEAD
        ///   will point to this branch. Otherwise, the HEAD will be detached, pointing at the commit sha.
        /// </para>
        /// </summary>
        /// <param name="repository">The <see cref="Repository"/> being worked with.</param>
        /// <param name="branch">The <see cref="Branch"/> to check out.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public static Branch Checkout(this IRepository repository, Branch branch)
        {
            CheckoutOptions options = new CheckoutOptions();

            return(repository.Checkout(branch, options));
        }
Exemplo n.º 36
0
 public Branch Checkout(Commit commit, CheckoutOptions options, Signature signature = null)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 37
0
 public void Reset(ResetMode resetMode, Commit commit, CheckoutOptions options)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 38
0
 public Branch Checkout(Commit commit, CheckoutOptions options)
 {
     throw new NotImplementedException();
 }
 public void UndoFileChanges(string filename)
 {
     using (var repository = GetRepository())
     {
         CheckoutOptions options = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force };
         repository.CheckoutPaths("HEAD", new string[] { filename }, options);
     }
 }
Exemplo n.º 40
0
 public void CheckoutPaths(string committishOrBranchSpec, IEnumerable<string> paths, CheckoutOptions checkoutOptions = null)
 {
     throw new NotImplementedException();
 }
        /// <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="repository">The <see cref="Repository"/> being worked with.</param>
        /// <param name="commit">The <see cref="LibGit2Sharp.Commit"/> to check out.</param>
        /// <param name="signature">The identity used for updating the reflog</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public static Branch Checkout(this IRepository repository, Commit commit, Signature signature = null)
        {
            CheckoutOptions options = new CheckoutOptions();

            return(repository.Checkout(commit, options, signature));
        }
Exemplo n.º 42
0
 public void Checkout(Tree tree, IEnumerable<string> paths, CheckoutOptions opts)
 {
     throw new NotImplementedException();
 }
 /// <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="repository">The <see cref="IRepository"/> being worked with.</param>
 /// <param name="commit">The <see cref="LibGit2Sharp.Commit"/> to check out.</param>
 /// <param name="options"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
 /// <returns>The <see cref="Branch"/> that was checked out.</returns>
 public static Branch Checkout(this IRepository repository, Commit commit, CheckoutOptions options)
 {
     return(repository.Checkout(commit, options, null));
 }
Exemplo n.º 44
0
        public MergeResult UpstreamSync()
        {
            // Need to check status before doing this
            MergeResult mergeResult;
            var mergeOptions = new MergeOptions ();
            mergeOptions.FastForwardStrategy = FastForwardStrategy.FastForwardOnly;
            var signature = new Signature ("x", "x", DateTime.Now);
            var checkoutOptions = new CheckoutOptions ();
            checkoutOptions.CheckoutModifiers = CheckoutModifiers.Force;

            try {
                Console.WriteLine ("Checkout master");
                repo.Checkout (master);
                Console.Write ("Any Key");
                Console.ReadKey ();
                Console.WriteLine ("Fetch Upstream");
                Remote remote = repo.Network.Remotes ["upstream"];
                repo.Network.Fetch (remote);
                Console.Write ("Any Key");
                Console.ReadKey ();
                Console.WriteLine ("Merge the fetched Upstream");
                mergeResult = repo.MergeFetchedRefs (signature, mergeOptions);
                Console.WriteLine (mergeResult.Status);
                Console.Write ("Any Key");
                Console.ReadKey ();
            } finally {
                Console.WriteLine ("Checkout prior head");
                repo.Checkout (head);
                Console.Write ("Any Key");
                Console.ReadKey ();
            }
            return mergeResult;
        }
 private static void SetupDevBranch(Repository repository, string branchName, string masterName, Signature author)
 {
     Log("Setting Up Dev Branch");
     var branch = repository.AddGetBranch(branchName,masterName,track:true);
     CheckoutOptions options = new CheckoutOptions();
     options.CheckoutModifiers = CheckoutModifiers.Force;
     repository.TryCheckout(branch, true);
     Log("Checked out Dev Branch");
 }
Exemplo n.º 46
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.º 47
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.º 48
0
 public Branch Checkout(Branch branch, CheckoutOptions options)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 49
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. Will throw if null is passed in. Passing an empty enumeration results in nothing being checked out.</param>
        /// <param name="checkoutOptions">Collection of parameters controlling checkout behavior.</param>
        public void CheckoutPaths(string committishOrBranchSpec, IEnumerable <string> paths, CheckoutOptions checkoutOptions = null)
        {
            Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec");
            Ensure.ArgumentNotNull(paths, "paths");

            // If there are no paths, then there is nothing to do.
            if (!paths.Any())
            {
                return;
            }

            Commit commit = LookupCommit(committishOrBranchSpec);

            CheckoutTree(commit.Tree, paths.ToList(), checkoutOptions ?? new CheckoutOptions());
        }
Exemplo n.º 50
0
        /// <summary>
        /// Get a single file version from the git repository
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <param name="tmpItem">The temporary item table holding the sha commit</param>
        /// <returns>a temporary file path</returns>
        public static string FileGetVersion(string repoPath, string fileName, SysVersionControlTmpItem tmpItem)
        {
            string indexPath = tmpItem.InternalFilename.Replace(repoPath, string.Empty);

            CheckoutOptions options = new CheckoutOptions();
            options.CheckoutModifiers = CheckoutModifiers.Force;

            using (Repository repo = new Repository(repoPath))
            {
                var commit = repo.Lookup<Commit>(tmpItem.GTXSha);
                if (commit != null)
                {
                    try
                    {
                        repo.CheckoutPaths(commit.Id.Sha, new[] { fileName }, options);
                    }
                    catch (MergeConflictException ex)
                    {
                        //should not reach here as we're forcing checkout
                        throw ex;
                    }

                }
            }

            return fileName;
        }
Exemplo n.º 51
0
 public virtual void Checkout(CheckoutOptions checkoutOptions, CheckoutProgressHandler onCheckoutProgress)
 {
     Checkout((CheckoutModifiers)checkoutOptions, onCheckoutProgress, null);
 }
Exemplo n.º 52
0
        /// <summary>
        /// Resets the changes of a file to it's HEAD last commit
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <param name="fileName">The file path</param>
        /// <returns>True if reset was successful false if not</returns>
        public static bool FileUndoCheckout(string repoPath, string fileName, bool forceCheckout)
        {
            FileInfo fileInfo = new FileInfo(fileName);

            using (Repository repo = new Repository(repoPath))
            {
                string indexPath = fileInfo.FullName.Replace(repo.Info.WorkingDirectory, string.Empty);

                CheckoutOptions checkoutOptions = new CheckoutOptions
                {
                    CheckoutModifiers =
                        forceCheckout
                            ? CheckoutModifiers.Force
                            : CheckoutModifiers.None
                };

                var fileCommits = repo.Head.Commits.Where(c => c.Parents.Count() == 1 &&
                                                          c.Tree[indexPath] != null &&
                                                          (c.Parents.FirstOrDefault().Tree[indexPath] == null ||
                                                            c.Tree[indexPath].Target.Id != c.Parents.FirstOrDefault().Tree[indexPath].Target.Id)
                                                          );

                if (fileCommits.Any())
                {
                    var lastCommit = fileCommits.First();
                    repo.CheckoutPaths(lastCommit.Id.Sha, new[] { fileName }, checkoutOptions);
                }

                return true;
            }
        }
Exemplo n.º 53
0
 public virtual void Checkout(CheckoutOptions options, Signature signature = null)
 {
     Ensure.ArgumentNotNull(options, "options");
     repo.Checkout(this, options, signature);
 }
Exemplo n.º 54
0
        /// <summary>
        /// Synchronizes a folder
        /// </summary>
        /// <param name="repoPath">Main repository path</param>
        /// <param name="folderPath">The folder to synchronize (checkout). Could be the model path or the layer path</param>
        /// <param name="forceCheckout">Forces the update from the latest commit (head tip)</param>
        /// <returns>A SysVersionControlItem with all the files that have been affected</returns>
        public static SysVersionControlTmpItem FolderSync(string repoPath, string folderPath, bool forceCheckout)
        {
            SysVersionControlTmpItem tmpItem = new SysVersionControlTmpItem();

            CheckoutOptions checkoutOptions = new CheckoutOptions
            {
                CheckoutModifiers =
                    forceCheckout
                        ? CheckoutModifiers.Force
                        : CheckoutModifiers.None
            };

            string tipSha;
            string folderName = folderPath.Split('\\').Last();

            using (Repository repo = new Repository(repoPath))
            {
                repo.CheckoutPaths(repo.Head.Tip.Id.Sha, new[] { folderPath }, checkoutOptions);
                tipSha = repo.Head.Tip.Id.Sha;

                InitTmpItemFromTree(repoPath, repo.Head.Tip.Tree[folderName].Target as Tree, ref tmpItem);

            }

            return tmpItem;
        }
Exemplo n.º 55
0
 public override void Undo(string filePath)
 {
     try
     {
         var tip = _repo.Branches.First(b => !b.IsRemote && b.IsCurrentRepositoryHead).Tip;
         var options = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force };
         _repo.CheckoutPaths(tip.Sha, new List<string> { filePath }, options);
         base.Undo(filePath);
     }
     catch (LibGit2SharpException ex)
     {
         throw new SourceControlException(SourceControlText.GitUndoFailed, ex);
     }
 }
Exemplo n.º 56
0
 public bool checkoutHead()
 {
     var rval = true;
     if (repo.Head == head) {
         return rval;
     }
     var checkoutOptions = new CheckoutOptions ();
     //            foreach (var sub in repo.Submodules)
     //            {
     //                Console.WriteLine("{0} {1} {2}", sub.Name, sub.RetrieveStatus().IsWorkingDirectoryDirty(), sub.RetrieveStatus().IsUnmodified());
     //            }
     //  Note: There are issues in gitlib2/sharp in the use of .IsWorkingDirectoryDirty() and .IsUnmodified())
     //        Really should open the submodule ourself via a new repo object...
     var dirtySubmodules = repo.Submodules.Where (s => s.RetrieveStatus ().IsWorkingDirectoryDirty ());
     if (!dirtySubmodules.Any ()) {
     //                Console.WriteLine("No submodules dirty, forcing checkout");
         checkoutOptions.CheckoutModifiers = CheckoutModifiers.Force;
     }
     //            foreach (var item in repo.RetrieveStatus().Where(m => m.State == FileStatus.ModifiedInWorkdir))
     //            {
     //                Console.WriteLine("{0} : {1}", item.State, item.FilePath);
     //            }
     //            Console.Write("Any Key");
     //            Console.ReadKey();
     //            Console.WriteLine("Checkout prior head");
     try {
         repo.Checkout (head, checkoutOptions);
     //                Console.Write("Any Key"); Console.ReadKey();
     } catch (Exception e) {
         Console.WriteLine ("HEAD checkout failed");
         Console.WriteLine (e.Message);
         //Console.WriteLine(e.StackTrace);
         rval = false;
     }
     return rval;
 }