-
Notifications
You must be signed in to change notification settings - Fork 899
Introduce StatusOptions.IncludeUnaltered #863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ public class RepositoryStatus : IEnumerable<StatusEntry> | |
private readonly List<StatusEntry> ignored = new List<StatusEntry>(); | ||
private readonly List<StatusEntry> renamedInIndex = new List<StatusEntry>(); | ||
private readonly List<StatusEntry> renamedInWorkDir = new List<StatusEntry>(); | ||
private readonly List<StatusEntry> unaltered = new List<StatusEntry>(); | ||
private readonly bool isDirty; | ||
|
||
private readonly IDictionary<FileStatus, Action<RepositoryStatus, StatusEntry>> dispatcher = Build(); | ||
|
@@ -42,7 +43,7 @@ private static IDictionary<FileStatus, Action<RepositoryStatus, StatusEntry>> Bu | |
{ FileStatus.Removed, (rs, s) => rs.removed.Add(s) }, | ||
{ FileStatus.RenamedInIndex, (rs, s) => rs.renamedInIndex.Add(s) }, | ||
{ FileStatus.Ignored, (rs, s) => rs.ignored.Add(s) }, | ||
{ FileStatus.RenamedInWorkDir, (rs, s) => rs.renamedInWorkDir.Add(s) } | ||
{ FileStatus.RenamedInWorkDir, (rs, s) => rs.renamedInWorkDir.Add(s) }, | ||
}; | ||
} | ||
|
||
|
@@ -81,7 +82,7 @@ internal RepositoryStatus(Repository repo, StatusOptions options) | |
AddStatusEntryForDelta(entry.Status, deltaHeadToIndex, deltaIndexToWorkDir); | ||
} | ||
|
||
isDirty = statusEntries.Any(entry => entry.State != FileStatus.Ignored); | ||
isDirty = statusEntries.Any(entry => entry.State != FileStatus.Ignored && entry.State != FileStatus.Unaltered); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Therzok As we're modifying the behavior of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, we don't quite modify the behaviour. We extend it here. Without IncludeUnaltered, we never had Unaltered file status. I'll add coverage for it though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That said, does having Untracked files mark the status as dirty? Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say no. What does git.git has to say about this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just did a:
Okay, should be good to go now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, the option to take out Untracked files is something else. You can query the git commandline in two ways for status changes: That's for later, yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Dammit! I read it backwards.
👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are exclusive statuses. Unaltered and Ignored can only appear by themselves. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, x & 0 == 0 always. So we can't use bitwise and on Unaltered. |
||
} | ||
} | ||
|
||
|
@@ -134,6 +135,12 @@ private static GitStatusOptions CreateStatusOptions(StatusOptions options) | |
GitStatusOptionFlags.DisablePathspecMatch; | ||
} | ||
|
||
if (options.IncludeUnaltered) | ||
{ | ||
coreOptions.Flags |= | ||
GitStatusOptionFlags.IncludeUnmodified; | ||
} | ||
|
||
return coreOptions; | ||
} | ||
|
||
|
@@ -164,14 +171,21 @@ private void AddStatusEntryForDelta(FileStatus gitStatus, GitDiffDelta deltaHead | |
|
||
StatusEntry statusEntry = new StatusEntry(filePath, gitStatus, headToIndexRenameDetails, indexToWorkDirRenameDetails); | ||
|
||
foreach (KeyValuePair<FileStatus, Action<RepositoryStatus, StatusEntry>> kvp in dispatcher) | ||
if (gitStatus == FileStatus.Unaltered) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we handle the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah - probably not if |
||
{ | ||
if (!gitStatus.HasFlag(kvp.Key)) | ||
unaltered.Add(statusEntry); | ||
} | ||
else | ||
{ | ||
foreach (KeyValuePair<FileStatus, Action<RepositoryStatus, StatusEntry>> kvp in dispatcher) | ||
{ | ||
continue; | ||
} | ||
if (!gitStatus.HasFlag(kvp.Key)) | ||
{ | ||
continue; | ||
} | ||
|
||
kvp.Value(this, statusEntry); | ||
kvp.Value(this, statusEntry); | ||
} | ||
} | ||
|
||
statusEntries.Add(statusEntry); | ||
|
@@ -289,6 +303,14 @@ public virtual IEnumerable<StatusEntry> RenamedInWorkDir | |
get { return renamedInWorkDir; } | ||
} | ||
|
||
/// <summary> | ||
/// List of files that were unmodified in the working directory. | ||
/// </summary> | ||
public virtual IEnumerable<StatusEntry> Unaltered | ||
{ | ||
get { return unaltered; } | ||
} | ||
|
||
/// <summary> | ||
/// True if the index or the working directory has been altered since the last commit. False otherwise. | ||
/// </summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,5 +76,13 @@ public StatusOptions() | |
/// as explicit paths, and NOT as pathspecs containing globs. | ||
/// </summary> | ||
public bool DisablePathSpecMatch { get; set; } | ||
|
||
/// <summary> | ||
/// Include unaltered files when scanning for status | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering this thread, it may be worthwhile to add an explanation regarding what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in a remarks element. |
||
/// </summary> | ||
/// <remarks> | ||
/// Unaltered meaning the file is identical in the working directory, the index and HEAD. | ||
/// </remarks> | ||
public bool IncludeUnaltered { get; set; } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaning stuff first. Even untracked files mark the repo as dirty.