Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Show staged status of files, and don't commit any files that aren't checked #1061

Merged
merged 1 commit into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/GitHub.Api/Git/TreeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface ITreeData
{
string Path { get; }
bool IsActive { get; }
bool IsChecked { get; }
}

[Serializable]
Expand Down Expand Up @@ -64,6 +65,7 @@ public bool Equals(GitBranchTreeData other)

public string Path => GitBranch.Name;
public bool IsActive => isActive;
public bool IsChecked => false;
}

[Serializable]
Expand All @@ -73,11 +75,13 @@ public struct GitStatusEntryTreeData : ITreeData

public GitStatusEntry gitStatusEntry;
public bool isLocked;
public bool isChecked;

public GitStatusEntryTreeData(GitStatusEntry gitStatusEntry, bool isLocked = false)
{
this.isLocked = isLocked;
this.gitStatusEntry = gitStatusEntry;
isChecked = gitStatusEntry.Staged;
}

public override int GetHashCode()
Expand Down Expand Up @@ -127,5 +131,6 @@ public bool Equals(GitStatusEntryTreeData other)
public GitStatusEntry GitStatusEntry => gitStatusEntry;
public GitFileStatus FileStatus => gitStatusEntry.Status;
public bool IsLocked => isLocked;
public bool IsChecked => isChecked;
}
}
}
2 changes: 1 addition & 1 deletion src/GitHub.Api/UI/TreeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void Load(IEnumerable<TData> treeDatas)
{
isActive = treeData.IsActive;
treeNodeTreeData = treeData;
isChecked = isCheckable && checkedFiles.Contains(nodePath);
isChecked = isCheckable && (checkedFiles.Contains(nodePath) || treeData.IsChecked);
}

isSelected = selectedNodePath != null && nodePath == selectedNodePath;
Expand Down
13 changes: 10 additions & 3 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,19 +478,26 @@ private void Commit()
{
isBusy = true;
var files = treeChanges.GetCheckedFiles().ToList();
ITask addTask;
ITask addTask = null;

if (files.Count == gitStatusEntries.Count)
{
addTask = Repository.CommitAllFiles(commitMessage, commitBody);
}
else
{
addTask = Repository.CommitFiles(files, commitMessage, commitBody);
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) =>
.FinallyInUI((success, exception) =>
{
if (success)
{
Expand Down
1 change: 1 addition & 0 deletions src/tests/UnitTests/UI/TreeBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public struct TestTreeData : ITreeData

public string Path { get; set; }
public bool IsActive { get; set; }
public bool IsChecked { get; set; }

public override string ToString()
{
Expand Down