2024-03-13 20:09:05 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Models
|
|
|
|
|
{
|
|
|
|
|
public enum ChangeViewMode
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
List,
|
|
|
|
|
Grid,
|
|
|
|
|
Tree,
|
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public enum ChangeState
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
None,
|
|
|
|
|
Modified,
|
|
|
|
|
Added,
|
|
|
|
|
Deleted,
|
|
|
|
|
Renamed,
|
|
|
|
|
Copied,
|
|
|
|
|
Unmerged,
|
|
|
|
|
Untracked
|
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public class Change
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
public ChangeState Index { get; set; }
|
|
|
|
|
public ChangeState WorkTree { get; set; } = ChangeState.None;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
public string Path { get; set; } = "";
|
|
|
|
|
public string OriginalPath { get; set; } = "";
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool IsConflit
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (Index == ChangeState.Unmerged || WorkTree == ChangeState.Unmerged)
|
|
|
|
|
return true;
|
|
|
|
|
if (Index == ChangeState.Added && WorkTree == ChangeState.Added)
|
|
|
|
|
return true;
|
|
|
|
|
if (Index == ChangeState.Deleted && WorkTree == ChangeState.Deleted)
|
|
|
|
|
return true;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Set(ChangeState index, ChangeState workTree = ChangeState.None)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Index = index;
|
|
|
|
|
WorkTree = workTree;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (index == ChangeState.Renamed || workTree == ChangeState.Renamed)
|
|
|
|
|
{
|
2024-03-13 20:09:05 -07:00
|
|
|
|
var idx = Path.IndexOf('\t', StringComparison.Ordinal);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (idx >= 0)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
OriginalPath = Path.Substring(0, idx);
|
|
|
|
|
Path = Path.Substring(idx + 1);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-03-13 20:09:05 -07:00
|
|
|
|
idx = Path.IndexOf(" -> ", StringComparison.Ordinal);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (idx > 0)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
OriginalPath = Path.Substring(0, idx);
|
|
|
|
|
Path = Path.Substring(idx + 4);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (Path[0] == '"')
|
|
|
|
|
Path = Path.Substring(1, Path.Length - 2);
|
|
|
|
|
if (!string.IsNullOrEmpty(OriginalPath) && OriginalPath[0] == '"')
|
|
|
|
|
OriginalPath = OriginalPath.Substring(1, OriginalPath.Length - 2);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|