Example #1
0
        /// <summary>
        /// Reads a Git rebase file from disk and returns its details in a <seealso cref="RebaseDocument"/> instance.
        /// </summary>
        /// <param name="filePath">The full path to the Git rebase file. This must not be null or empty.</param>
        /// <returns>A <seealso cref="RebaseDocument"/> object that contains the rebase details.</returns>
        /// <exception cref="ArgumentException">Thrown if filePath is null or empty.</exception>
        /// <exception cref="GitModelException">
        /// Thrown if disk access fails for any reason. Refer to the inner exception for details.
        /// </exception>
        public RebaseDocument FromFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException("File path must not be null or empty", nameof(filePath));
            }

            var allLines    = _fileSystem.ReadAllLines(filePath);
            var rebaseItems = new List <RebaseItem>();

            foreach (string line in allLines)
            {
                int firstSpace  = line.IndexOf(' ');
                int secondSpace = line.IndexOf(' ', firstSpace + 1);

                string firstToken  = line.Substring(0, firstSpace);
                string secondToken = line.Substring(firstSpace + 1, secondSpace - firstSpace - 1);
                string thirdToken  = line.Substring(secondSpace + 1);

                var rebaseItem = new RebaseItem
                {
                    Action     = RebaseActionParser.ToRebaseAction(firstToken),
                    CommitHash = secondToken,
                    Subject    = thirdToken
                };

                rebaseItems.Add(rebaseItem);
            }

            return(new RebaseDocument
            {
                Items = rebaseItems.ToArray()
            });
        }
Example #2
0
 public void ToRebaseAction_ActionStringIsValid_ConvertsToRebaseAction(string actionString, RebaseAction expectedAction)
 {
     RebaseActionParser.ToRebaseAction(actionString).Should().Be(expectedAction);
 }