Ejemplo n.º 1
0
        private void Commit()
        {
            isBusy = true;
            var   files   = treeChanges.GetCheckedFiles().ToList();
            ITask addTask = null;

            if (files.Count == gitStatusEntries.Count)
            {
                addTask = Repository.CommitAllFiles(commitMessage, commitBody);
            }
            else
            {
                ITask commit = Repository.CommitFiles(files, commitMessage, commitBody);

                // if there are files that have been staged outside of Unity, but they aren't selected for commit, remove them
                // from the index before commiting, otherwise the commit will take them along.
                var filesStagedButNotChecked = gitStatusEntries.Where(x => x.Staged).Select(x => x.Path).Except(files).ToList();
                if (filesStagedButNotChecked.Count > 0)
                {
                    addTask = GitClient.Remove(filesStagedButNotChecked);
                }
                addTask = addTask == null ? commit : addTask.Then(commit);
            }

            addTask
            .FinallyInUI((success, exception) =>
            {
                if (success)
                {
                    UsageTracker.IncrementChangesViewButtonCommit();

                    commitMessage = "";
                    commitBody    = "";
                }
                isBusy = false;
            }).Start();
        }