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

Commit 092e13c

Browse files
authored
Merge pull request #1061 from github-for-unity/fixes/dont-commit-things-that-arent-selected
Show staged status of files, and don't commit any files that aren't checked
2 parents da9d116 + 3466ec7 commit 092e13c

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

Diff for: src/GitHub.Api/Git/TreeData.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public interface ITreeData
77
{
88
string Path { get; }
99
bool IsActive { get; }
10+
bool IsChecked { get; }
1011
}
1112

1213
[Serializable]
@@ -64,6 +65,7 @@ public bool Equals(GitBranchTreeData other)
6465

6566
public string Path => GitBranch.Name;
6667
public bool IsActive => isActive;
68+
public bool IsChecked => false;
6769
}
6870

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

7476
public GitStatusEntry gitStatusEntry;
7577
public bool isLocked;
78+
public bool isChecked;
7679

7780
public GitStatusEntryTreeData(GitStatusEntry gitStatusEntry, bool isLocked = false)
7881
{
7982
this.isLocked = isLocked;
8083
this.gitStatusEntry = gitStatusEntry;
84+
isChecked = gitStatusEntry.Staged;
8185
}
8286

8387
public override int GetHashCode()
@@ -127,5 +131,6 @@ public bool Equals(GitStatusEntryTreeData other)
127131
public GitStatusEntry GitStatusEntry => gitStatusEntry;
128132
public GitFileStatus FileStatus => gitStatusEntry.Status;
129133
public bool IsLocked => isLocked;
134+
public bool IsChecked => isChecked;
130135
}
131-
}
136+
}

Diff for: src/GitHub.Api/UI/TreeBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void Load(IEnumerable<TData> treeDatas)
118118
{
119119
isActive = treeData.IsActive;
120120
treeNodeTreeData = treeData;
121-
isChecked = isCheckable && checkedFiles.Contains(nodePath);
121+
isChecked = isCheckable && (checkedFiles.Contains(nodePath) || treeData.IsChecked);
122122
}
123123

124124
isSelected = selectedNodePath != null && nodePath == selectedNodePath;

Diff for: src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -478,19 +478,26 @@ private void Commit()
478478
{
479479
isBusy = true;
480480
var files = treeChanges.GetCheckedFiles().ToList();
481-
ITask addTask;
481+
ITask addTask = null;
482482

483483
if (files.Count == gitStatusEntries.Count)
484484
{
485485
addTask = Repository.CommitAllFiles(commitMessage, commitBody);
486486
}
487487
else
488488
{
489-
addTask = Repository.CommitFiles(files, commitMessage, commitBody);
489+
ITask commit = Repository.CommitFiles(files, commitMessage, commitBody);
490+
491+
// if there are files that have been staged outside of Unity, but they aren't selected for commit, remove them
492+
// from the index before commiting, otherwise the commit will take them along.
493+
var filesStagedButNotChecked = gitStatusEntries.Where(x => x.Staged).Select(x => x.Path).Except(files).ToList();
494+
if (filesStagedButNotChecked.Count > 0)
495+
addTask = GitClient.Remove(filesStagedButNotChecked);
496+
addTask = addTask == null ? commit : addTask.Then(commit);
490497
}
491498

492499
addTask
493-
.FinallyInUI((success, exception) =>
500+
.FinallyInUI((success, exception) =>
494501
{
495502
if (success)
496503
{

Diff for: src/tests/UnitTests/UI/TreeBaseTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public struct TestTreeData : ITreeData
3535

3636
public string Path { get; set; }
3737
public bool IsActive { get; set; }
38+
public bool IsChecked { get; set; }
3839

3940
public override string ToString()
4041
{

0 commit comments

Comments
 (0)