Update() public static method

public static Update ( string path, LibGit2Sharp.Mode mode = Mode.NonExecutableFile ) : ApplicableChange
path string
mode LibGit2Sharp.Mode
return ApplicableChange
Exemplo n.º 1
0
        /// <summary>
        /// Get all the changes of a changeset to apply
        /// </summary>
        /// <param name="forceGetChanges">true - force get changes ignoring check what should be applied. </param>
        public IEnumerable <ApplicableChange> GetChangesToApply(bool forceGetChanges = false)
        {
            if (DeletesProject)
            {
                return(Enumerable.Empty <ApplicableChange>());
            }

            var compartments = new {
                Deleted = new List <ApplicableChange>(),
                Updated = new List <ApplicableChange>(),
            };

            foreach (var change in NamedChanges)
            {
                // We only need the file changes because git only cares about files and if you make
                // changes to a folder in TFS, the changeset includes changes for all the descendant files anyway.
                if (change.Change.Item.ItemType != TfsItemType.File)
                {
                    continue;
                }

                if (change.Change.ChangeType.IncludesOneOf(TfsChangeType.Delete))
                {
                    if (change.GitPath != null)
                    {
                        compartments.Deleted.Add(ApplicableChange.Delete(change.GitPath));
                    }
                }
                else if (change.Change.ChangeType.IncludesOneOf(TfsChangeType.Rename))
                {
                    var oldInfo = _resolver.GetGitObject(GetPathBeforeRename(change.Change.Item));
                    if (oldInfo != null)
                    {
                        compartments.Deleted.Add(ApplicableChange.Delete(oldInfo.Path));
                    }
                    if (IncludeInApply(change))
                    {
                        compartments.Updated.Add(ApplicableChange.Update(change.GitPath,
                                                                         oldInfo != null ? oldInfo.Mode : Mode.NonExecutableFile));
                    }
                }
                else
                {
                    if (forceGetChanges || IncludeInApply(change))
                    {
                        // for get changes only on first change set
                        forceGetChanges = false;

                        if (change == null)
                        {
                            throw new Exception("(change == null)");
                        }
                        if (change.Info == null)
                        {
                            throw new Exception("(change.Info == null)");
                        }
                        compartments.Updated.Add(ApplicableChange.Update(change.GitPath, change.Info.Mode));
                    }
                }
            }
            return(compartments.Deleted.Concat(compartments.Updated));
        }