Skip to content

Commit eb3579d

Browse files
author
Andrew Witte
committed
fixed lots of refresh / file state bugs
1 parent 15d04c8 commit eb3579d

File tree

8 files changed

+172
-140
lines changed

8 files changed

+172
-140
lines changed

GitCommander/Changes.cs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,59 @@ public class FileState
3737
public string filename {get; internal set;}
3838
public FileStates state {get; internal set;}
3939

40-
public bool IsState(FileStates state)
40+
public static bool IsAllStates(FileStates stateFlag, FileStates[] states)
41+
{
42+
foreach (var state in states)
43+
{
44+
if ((stateFlag & state) == 0) return false;
45+
}
46+
47+
return true;
48+
}
49+
50+
public static bool IsAnyStates(FileStates stateFlag, FileStates[] states)
51+
{
52+
foreach (var state in states)
53+
{
54+
if ((stateFlag & state) != 0) return true;
55+
}
56+
57+
return false;
58+
}
59+
60+
public bool IsAllStates(FileStates[] states)
61+
{
62+
return IsAllStates(state, states);
63+
}
64+
65+
public bool IsAnyStates(FileStates[] states)
66+
{
67+
return IsAnyStates(state, states);
68+
}
69+
70+
public bool HasState(FileStates state)
4171
{
4272
return (this.state & state) != 0;
4373
}
4474

75+
public bool IsUnstaged()
76+
{
77+
return
78+
HasState(FileStates.NewInWorkdir) ||
79+
HasState(FileStates.DeletedFromWorkdir) ||
80+
HasState(FileStates.ModifiedInWorkdir) ||
81+
HasState(FileStates.RenamedInWorkdir) ||
82+
HasState(FileStates.TypeChangeInWorkdir);
83+
}
84+
4585
public bool IsStaged()
4686
{
4787
return
48-
IsState(FileStates.NewInIndex) ||
49-
IsState(FileStates.DeletedFromIndex) ||
50-
IsState(FileStates.ModifiedInIndex) ||
51-
IsState(FileStates.RenamedInIndex) ||
52-
IsState(FileStates.TypeChangeInIndex);
88+
HasState(FileStates.NewInIndex) ||
89+
HasState(FileStates.DeletedFromIndex) ||
90+
HasState(FileStates.ModifiedInIndex) ||
91+
HasState(FileStates.RenamedInIndex) ||
92+
HasState(FileStates.TypeChangeInIndex);
5393
}
5494

5595
public override string ToString()

GitItGUI.Core/BranchManager.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public static BranchState[] GetNonActiveBranches(bool getRemotes)
7272

7373
public static bool Checkout(BranchState branch)
7474
{
75+
bool success = true;
7576
try
7677
{
7778
if (activeBranch.name != branch.name)
@@ -81,17 +82,17 @@ public static bool Checkout(BranchState branch)
8182
else
8283
{
8384
Debug.LogError("Already on branch: " + branch.name, true);
84-
return false;
85+
success = false;
8586
}
8687
}
8788
catch (Exception e)
8889
{
8990
Debug.LogError("BranchManager.Checkout Failed: " + e.Message, true);
90-
return false;
91+
success = false;
9192
}
9293

9394
RepoManager.Refresh();
94-
return true;
95+
return success;
9596
}
9697

9798
public static MergeResults MergeBranchIntoActive(BranchState srcBranch)
@@ -108,7 +109,7 @@ public static MergeResults MergeBranchIntoActive(BranchState srcBranch)
108109
catch (Exception e)
109110
{
110111
Debug.LogError("BranchManager.Merge Failed: " + e.Message, true);
111-
return MergeResults.Error;
112+
mergeResult = MergeResults.Error;
112113
}
113114

114115
RepoManager.Refresh();
@@ -117,6 +118,7 @@ public static MergeResults MergeBranchIntoActive(BranchState srcBranch)
117118

118119
public static bool CheckoutNewBranch(string branchName, string remoteName = null)
119120
{
121+
bool success = true;
120122
try
121123
{
122124
// create branch
@@ -138,77 +140,81 @@ public static bool CheckoutNewBranch(string branchName, string remoteName = null
138140
catch (Exception e)
139141
{
140142
Debug.LogError("Add new Branch Error: " + e.Message, true);
141-
return false;
143+
success = false;
142144
}
143145

144146
RepoManager.Refresh();
145-
return true;
147+
return success;
146148
}
147149

148150
public static bool DeleteNonActiveBranch(BranchState branch)
149151
{
152+
bool success = true;
150153
try
151154
{
152155
if (!Repository.DeleteBranch(branch.name)) throw new Exception(Repository.lastError);
153156
}
154157
catch (Exception e)
155158
{
156159
Debug.LogError("Delete new Branch Error: " + e.Message, true);
157-
return false;
160+
success = false;
158161
}
159162

160163
RepoManager.Refresh();
161-
return true;
164+
return success;
162165
}
163166

164167
public static bool RenameActiveBranch(string newBranchName)
165168
{
169+
bool success = true;
166170
try
167171
{
168172
if (!Repository.RenameActiveBranch(newBranchName)) throw new Exception(Repository.lastError);
169173
}
170174
catch (Exception e)
171175
{
172176
Debug.LogError("Rename new Branch Error: " + e.Message, true);
173-
return false;
177+
success = false;
174178
}
175179

176180
RepoManager.Refresh();
177-
return true;
181+
return success;
178182
}
179183

180184
public static bool CopyTracking(BranchState srcRemoteBranch)
181185
{
186+
bool success = true;
182187
try
183188
{
184189
if (!Repository.SetActiveBranchTracking(srcRemoteBranch.fullname)) throw new Exception(Repository.lastError);
185190
}
186191
catch (Exception e)
187192
{
188193
Debug.LogError("Add/Update tracking Branch Error: " + e.Message, true);
189-
return false;
194+
success = false;
190195
}
191196

192197
RepoManager.Refresh();
193-
return true;
198+
return success;
194199
}
195200

196201
public static bool RemoveTracking()
197202
{
198203
if (!activeBranch.isTracking) return true;
199204

205+
bool success = true;
200206
try
201207
{
202208
if (!Repository.RemoveActiveBranchTracking()) throw new Exception(Repository.lastError);
203209
}
204210
catch (Exception e)
205211
{
206212
Debug.LogError("Remove Branch Error: " + e.Message, true);
207-
return false;
213+
success = false;
208214
}
209215

210216
RepoManager.Refresh();
211-
return true;
217+
return success;
212218
}
213219

214220
public static bool IsUpToDateWithRemote(out bool yes)

0 commit comments

Comments
 (0)