private void AddItemsToGit(bool initialCheckin)
        {


            var directories = Directory.GetDirectories(GitRepositoryFolder, "*.*", SearchOption.AllDirectories).ToList();

            directories.RemoveAll(r => r.Contains(".git") || r.Contains("\\Logs"));
            directories.Add(GitRepositoryFolder);

            var files = new List<string>();

            directories.ForEach(dir => files.AddRange(Directory.GetFiles(dir)));

            using (var frmStatus = new Status())
            {

                frmStatus.Show();

                frmStatus.SetStatusText("Gathering Items to Add to Source Control");
                if (initialCheckin)
                    frmStatus.SetMaximum(files.Count);
                else
                    frmStatus.SetMaximum(files.Count + repo.Status.Added.Count + repo.Status.Removed.Count +
                                       repo.Status.Modified.Count);
               
                frmStatus.SetStatusText("Adding Items");
                string commitMessage = initialCheckin
                    ? "Initial Load of Existing V3 Data Files"
                    : "Updated/Added File to V3 Folders";
                if (initialCheckin)
                    files.ForEach(file =>
                    {
                        repo.Index.Add(file);
                        repo.Commit(commitMessage);
                        frmStatus.SetStatusText(commitMessage);
                        frmStatus.SetValue(frmStatus.Value + 1);
                    });
                // repo.Index.AddAll();

                repo.Status.Added.ToList().ForEach(a =>
                {
                    repo.Index.Add(Path.Combine(GitRepositoryFolder, a));
                    commitMessage = string.Format("Added {0}", new FileInfo(Path.Combine(GitRepositoryFolder, a)).Name);
                    repo.Commit(commitMessage);
                    frmStatus.SetStatusText(commitMessage);
                    frmStatus.SetValue(frmStatus.Value + 1);
                });
                repo.Status.Removed.ToList().ForEach(a =>
                {
                    repo.Index.Add(Path.Combine(GitRepositoryFolder, a));
                    commitMessage = string.Format("Removed {0}", new FileInfo(Path.Combine(GitRepositoryFolder, a)).Name);
                    repo.Commit(commitMessage);
                    frmStatus.SetStatusText(commitMessage);
                    frmStatus.SetValue(frmStatus.Value + 1);
                });
                repo.Status.Modified.ToList().ForEach(a =>
                {
                    repo.Index.Add(Path.Combine(GitRepositoryFolder, a));
                    commitMessage = string.Format("Changed {0}", new FileInfo(Path.Combine(GitRepositoryFolder, a)).Name);
                    repo.Commit(commitMessage);
                    frmStatus.SetStatusText(commitMessage);
                    frmStatus.SetValue(frmStatus.Value + 1);
                });
                frmStatus.Close();

            }

        }
        private void AddItemsToGit(bool initialCheckin)
        {
            using (var frmStatus = new Status())
            {
                frmStatus.Show();

                if (initialCheckin)
                {
                    frmStatus.SetStatusText("Gathering items to add to version control");

                    Git git    = new Git(_repo);
                    var status = git.Status().Call();

                    frmStatus.SetMaximum(status.GetUntracked().Count);

                    var add = git.Add();

                    foreach (var item in status.GetUntracked().ToList())
                    {
                        add.AddFilepattern(item);
                        frmStatus.SetValue(frmStatus.Value + 1);
                    }

                    add.Call();

                    frmStatus.SetStatusText("Committing profile items to version control.");
                    git.Commit().SetAll(true).SetMessage(@"Initial commit of existing Vixen profile data files.").Call();
                    frmStatus.SetValue(2);
                    frmStatus.SetStatusText(@"Completed initial load of existing Vixen profile data files.");
                }
                else
                {
                    //This handles checking in any changes that might have happened outside of a Vixen session.
                    frmStatus.SetStatusText("Gathering items that have changed outside of Vixen and updating version control.");
                    Git git = new Git(_repo);

                    try
                    {
                        var status  = git.Status().Call();
                        var changed = status.GetAdded().Count > 0 || status.GetChanged().Count > 0 || status.GetModified().Count > 0 ||
                                      status.GetRemoved().Count > 0 || status.GetUntracked().Count > 0 || status.GetMissing().Count > 0;

                        if (changed)
                        {
                            frmStatus.SetMaximum(status.GetAdded().Count + status.GetRemoved().Count + status.GetModified().Count +
                                                 status.GetChanged().Count + status.GetMissing().Count + status.GetUntracked().Count);

                            if (status.GetAdded().Count > 0 || status.GetUntracked().Count > 0 || status.GetModified().Count > 0)
                            {
                                var add = git.Add();
                                status.GetAdded().ToList().ForEach(a =>
                                {
                                    add.AddFilepattern(a);
                                    frmStatus.SetValue(frmStatus.Value + 1);
                                });

                                status.GetModified().ToList().ForEach(a =>
                                {
                                    add.AddFilepattern(a);
                                    frmStatus.SetValue(frmStatus.Value + 1);
                                });

                                status.GetChanged().ToList().ForEach(a =>
                                {
                                    add.AddFilepattern(a);
                                    frmStatus.SetValue(frmStatus.Value + 1);
                                });

                                status.GetUntracked().ToList().ForEach(a =>
                                {
                                    add.AddFilepattern(a);
                                    frmStatus.SetValue(frmStatus.Value + 1);
                                });

                                add.Call();
                            }


                            if (status.GetMissing().Count > 0 || status.GetRemoved().Count > 0)
                            {
                                var removed = git.Rm();

                                status.GetRemoved().ToList().ForEach(a =>
                                {
                                    removed.AddFilepattern(a);
                                    frmStatus.SetValue(frmStatus.Value + 1);
                                });


                                status.GetMissing().ToList().ForEach(a =>
                                {
                                    removed.AddFilepattern(a);
                                    frmStatus.SetValue(frmStatus.Value + 1);
                                });

                                removed.Call();
                            }

                            git.Commit().SetMessage(@"Update of profile changes outside of Vixen.").Call();
                            frmStatus.SetStatusText(@"Committed profile changes outside of Vixen.");
                        }

                        RunCleanup(frmStatus);
                    }
                    catch (Exception e)
                    {
                        Logging.Error(e, "Unable to access repository.");
                    }
                }

                frmStatus.Close();
            }
        }
Example #3
0
        private void AddItemsToGit(bool initialCheckin)
        {
            var directories = Directory.GetDirectories(GitRepositoryFolder, "*.*", SearchOption.AllDirectories).ToList();

            directories.RemoveAll(r => r.Contains(".git") || r.Contains("\\Logs"));
            directories.Add(GitRepositoryFolder);

            var files = new List <string>();

            directories.ForEach(dir => files.AddRange(Directory.GetFiles(dir)));

            using (var frmStatus = new Status())
            {
                frmStatus.Show();

                frmStatus.SetStatusText("Gathering Items to Add to Source Control");
                if (initialCheckin)
                {
                    frmStatus.SetMaximum(files.Count);
                }
                else
                {
                    frmStatus.SetMaximum(files.Count + repo.Status.Added.Count + repo.Status.Removed.Count +
                                         repo.Status.Modified.Count);
                }

                frmStatus.SetStatusText("Adding Items");
                string commitMessage = initialCheckin
                    ? "Initial Load of Existing V3 Data Files"
                    : "Updated/Added File to V3 Folders";
                if (initialCheckin)
                {
                    files.ForEach(file =>
                    {
                        repo.Index.Add(file);
                        repo.Commit(commitMessage);
                        frmStatus.SetStatusText(commitMessage);
                        frmStatus.SetValue(frmStatus.Value + 1);
                    });
                }
                // repo.Index.AddAll();

                repo.Status.Added.ToList().ForEach(a =>
                {
                    repo.Index.Add(Path.Combine(GitRepositoryFolder, a));
                    commitMessage = string.Format("Added {0}", new FileInfo(Path.Combine(GitRepositoryFolder, a)).Name);
                    repo.Commit(commitMessage);
                    frmStatus.SetStatusText(commitMessage);
                    frmStatus.SetValue(frmStatus.Value + 1);
                });
                repo.Status.Removed.ToList().ForEach(a =>
                {
                    repo.Index.Add(Path.Combine(GitRepositoryFolder, a));
                    commitMessage = string.Format("Removed {0}", new FileInfo(Path.Combine(GitRepositoryFolder, a)).Name);
                    repo.Commit(commitMessage);
                    frmStatus.SetStatusText(commitMessage);
                    frmStatus.SetValue(frmStatus.Value + 1);
                });
                repo.Status.Modified.ToList().ForEach(a =>
                {
                    repo.Index.Add(Path.Combine(GitRepositoryFolder, a));
                    commitMessage = string.Format("Changed {0}", new FileInfo(Path.Combine(GitRepositoryFolder, a)).Name);
                    repo.Commit(commitMessage);
                    frmStatus.SetStatusText(commitMessage);
                    frmStatus.SetValue(frmStatus.Value + 1);
                });
                frmStatus.Close();
            }
        }