Example #1
0
        public ITask DiscardChanges(GitStatusEntry[] gitStatusEntries)
        {
            Guard.ArgumentNotNullOrEmpty(gitStatusEntries, "gitStatusEntries");

            ActionTask <GitStatusEntry[]> task = null;

            task = new ActionTask <GitStatusEntry[]>(token, (_, entries) =>
            {
                var itemsToDelete = new List <NPath>();
                var itemsToRevert = new List <string>();

                foreach (var gitStatusEntry in gitStatusEntries)
                {
                    if (gitStatusEntry.WorkTreeStatus == GitFileStatus.Added || gitStatusEntry.WorkTreeStatus == GitFileStatus.Untracked)
                    {
                        itemsToDelete.Add(gitStatusEntry.path.ToNPath().MakeAbsolute());
                    }
                    else
                    {
                        itemsToRevert.Add(gitStatusEntry.path);
                    }
                }

                if (itemsToDelete.Any())
                {
                    foreach (var itemToDelete in itemsToDelete)
                    {
                        itemToDelete.DeleteIfExists();
                    }
                }

                if (itemsToRevert.Any())
                {
                    task.Then(GitClient.Discard(itemsToRevert));
                }
            }
                                                     , () => gitStatusEntries)
            {
                Message = "Discarding changes..."
            };

            return(HookupHandlers(task, true));
        }
Example #2
0
        public ITask DiscardChanges(GitStatusEntry[] gitStatusEntries)
        {
            Guard.ArgumentNotNullOrEmpty(gitStatusEntries, "gitStatusEntries");

            ActionTask <GitStatusEntry[]> task = null;

            task = new ActionTask <GitStatusEntry[]>(token, (_, entries) =>
            {
                var itemsToDelete = new List <string>();
                var itemsToRevert = new List <string>();

                foreach (var gitStatusEntry in gitStatusEntries)
                {
                    if (gitStatusEntry.status == GitFileStatus.Added || gitStatusEntry.status == GitFileStatus.Untracked)
                    {
                        itemsToDelete.Add(gitStatusEntry.path);
                    }
                    else
                    {
                        itemsToRevert.Add(gitStatusEntry.path);
                    }
                }

                if (itemsToDelete.Any())
                {
                    foreach (var itemToDelete in itemsToDelete)
                    {
                        fileSystem.FileDelete(itemToDelete);
                    }
                }

                ITask <string> gitDiscardTask = null;
                if (itemsToRevert.Any())
                {
                    gitDiscardTask = GitClient.Discard(itemsToRevert);
                    task.Then(gitDiscardTask);
                }
            }
                                                     , () => gitStatusEntries);


            return(HookupHandlers(task, true, true));
        }