diff --git a/SourceGit/Git/Repository.cs b/SourceGit/Git/Repository.cs index 9df6827c..689a7edf 100644 --- a/SourceGit/Git/Repository.cs +++ b/SourceGit/Git/Repository.cs @@ -23,6 +23,7 @@ namespace SourceGit.Git { [XmlIgnore] public Action OnStashChanged = null; [XmlIgnore] public Action OnBranchChanged = null; [XmlIgnore] public Action OnCommitsChanged = null; + [XmlIgnore] public Action OnSubmoduleChanged = null; #endregion #region PROPERTIES_SAVED @@ -57,6 +58,8 @@ namespace SourceGit.Git { #endregion #region PROPERTIES_RUNTIME + [XmlIgnore] public Repository Parent = null; + private List cachedRemotes = new List(); private List cachedBranches = new List(); private List cachedTags = new List(); @@ -306,6 +309,7 @@ namespace SourceGit.Git { OnStashChanged = null; OnWorkingCopyChanged = null; OnNavigateCommit = null; + OnSubmoduleChanged = null; cachedBranches.Clear(); cachedRemotes.Clear(); @@ -718,7 +722,7 @@ namespace SourceGit.Git { /// Changes. public List LocalChanges() { List changes = new List(); - RunCommand("status -uall --porcelain", line => { + RunCommand("status -uall --ignore-submodules=dirty --porcelain", line => { if (!string.IsNullOrEmpty(line)) { var change = Change.Parse(line); if (change != null) changes.Add(change); @@ -833,6 +837,46 @@ namespace SourceGit.Git { return stashes; } + /// + /// Get all submodules + /// + /// + public List Submodules() { + var test = new Regex(@"^[\-\+ ][0-9a-f]+\s(.*)\(.*\)$"); + var modules = new List(); + + var errs = RunCommand("submodule status", line => { + var match = test.Match(line); + if (!match.Success) return; + + modules.Add(match.Groups[1].Value); + }); + + return modules; + } + + /// + /// Add submodule + /// + /// + /// + /// + /// + public void AddSubmodule(string url, string localPath, bool recursive, Action onProgress) { + isWatcherDisabled = true; + + var errs = RunCommand($"submodule add {url} {localPath}", onProgress, true); + if (errs == null) { + if (recursive) RunCommand($"submodule update --init --recursive -- {localPath}", onProgress, true); + OnWorkingCopyChanged?.Invoke(); + OnSubmoduleChanged?.Invoke(); + } else { + App.RaiseError(errs); + } + + isWatcherDisabled = false; + } + /// /// Blame file. /// diff --git a/SourceGit/Helpers/Validations.cs b/SourceGit/Helpers/Validations.cs index ceaf48fc..a92425b7 100644 --- a/SourceGit/Helpers/Validations.cs +++ b/SourceGit/Helpers/Validations.cs @@ -121,4 +121,16 @@ namespace SourceGit.Helpers { return !succ ? new ValidationResult(false, "Invalid path for patch file") : ValidationResult.ValidResult; } } + + /// + /// Required for submodule path. + /// + public class SubmodulePathRequiredRule : ValidationRule { + public override ValidationResult Validate(object value, CultureInfo cultureInfo) { + var regex = new Regex(@"^[\w\-\._/]+$"); + var path = value as string; + var succ = !string.IsNullOrEmpty(path) && regex.IsMatch(path.Trim()); + return !succ ? new ValidationResult(false, "Invalid path for submodules") : ValidationResult.ValidResult; + } + } } diff --git a/SourceGit/Resources/Icons.xaml b/SourceGit/Resources/Icons.xaml index 84f55548..2bd56a25 100644 --- a/SourceGit/Resources/Icons.xaml +++ b/SourceGit/Resources/Icons.xaml @@ -1,6 +1,7 @@ M1004.824 466.4L557.72 19.328c-25.728-25.76-67.488-25.76-93.28 0L360.568 123.2l78.176 78.176c12.544-5.984 26.56-9.376 41.376-9.376 53.024 0 96 42.976 96 96 0 14.816-3.36 28.864-9.376 41.376l127.968 127.968c12.544-5.984 26.56-9.376 41.376-9.376 53.024 0 96 42.976 96 96s-42.976 96-96 96-96-42.976-96-96c0-14.816 3.36-28.864 9.376-41.376L521.496 374.624a88.837 88.837 0 0 1-9.376 3.872v266.976c37.28 13.184 64 48.704 64 90.528 0 53.024-42.976 96-96 96s-96-42.976-96-96c0-41.792 26.72-77.344 64-90.528V378.496c-37.28-13.184-64-48.704-64-90.528 0-14.816 3.36-28.864 9.376-41.376l-78.176-78.176L19.416 464.288c-25.76 25.792-25.76 67.52 0 93.28l447.136 447.072c25.728 25.76 67.488 25.76 93.28 0l444.992-444.992c25.76-25.76 25.76-67.552 0-93.28z + M557.696 545.347L789.873 402.66c23.998-14.999 31.297-46.496 16.398-70.493-14.798-23.798-45.995-31.197-69.993-16.699L506.501 456.555 277.123 315.37c-24.098-14.798-55.595-7.3-70.493 16.799-14.799 24.097-7.3 55.594 16.798 70.493l231.778 142.586V819.12c0 28.297 22.897 51.195 51.195 51.195 28.297 0 51.195-22.898 51.195-51.195V545.347h0.1zM506.5 0l443.356 255.975v511.95L506.501 1023.9 63.144 767.925v-511.95L506.5 0z F1M0,6L0,9 9,9 9,6 0,6z F1M0,0L0,9 9,9 9,0 0,0 0,3 8,3 8,8 1,8 1,3z diff --git a/SourceGit/UI/AddSubmodule.xaml b/SourceGit/UI/AddSubmodule.xaml new file mode 100644 index 00000000..a6bd9a53 --- /dev/null +++ b/SourceGit/UI/AddSubmodule.xaml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + +