Skip to content

Commit

Permalink
Show staged status of files, and don't commit any files that aren't c…
Browse files Browse the repository at this point in the history
…hecked

If a file is staged outside of Unity, this makes sure the check box is checked
automatically when listing changed files. If the user unchecks a file that has
been staged for commit outside of Unity, we remove the file from the index
right before commiting all the (other) checked files, to make sure
WICIWIC (What Is Checked Is What Is Commited)
  • Loading branch information
shana committed Jun 20, 2019
1 parent da9d116 commit 3466ec7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
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

0 comments on commit 3466ec7

Please sign in to comment.