/// <summary> /// Gets all stashes for current repositoty. /// </summary> /// <param name="stashes">List of stashes for current repositoty.</param> /// <param name="errorMessage">Error message.</param> /// <returns>Bool value that indicates whether command execution was succeeded.</returns> public bool TryGetAllStashes(out IList <Stash> stashes, out string errorMessage) { var commandResult = Execute(GitCommandConstants.StashList); if (commandResult.IsError) { errorMessage = commandResult.ErrorMessage; stashes = null; return(false); } stashes = GitResultParser.ParseStashListResult(commandResult.OutputMessage); errorMessage = string.Empty; return(true); }
/// <summary> /// Gets stash info by id. /// </summary> /// <param name="id">Stash id.</param> /// <param name="stash">Stash model.</param> /// <param name="errorMessage">Error message.</param> /// <returns>Bool value that indicates whether command execution was succeeded.</returns> public bool TryGetStashInfo(int id, out Stash stash, out string errorMessage) { var infoCommand = string.Format(GitCommandConstants.StashInfoFormatted, id); var commandResult = Execute(infoCommand); if (commandResult.IsError) { errorMessage = commandResult.ErrorMessage; stash = null; return(false); } errorMessage = string.Empty; stash = GitResultParser.ParseStashInfoResult(commandResult.OutputMessage); return(true); }
/// <summary> /// Gets stash info by id. /// </summary> /// <param name="id">Stash id.</param> /// <param name="stash">Stash model.</param> /// <param name="errorMessage">Error message.</param> /// <returns>Bool value that indicates whether command execution was succeeded.</returns> public bool TryGetStashInfo(int id, out Stash stash, out string errorMessage) { var infoCommand = string.Format(GitCommandConstants.StashInfoFormatted, id); var commandResult = Execute(infoCommand); if (commandResult.IsError) { errorMessage = commandResult.ErrorMessage; stash = null; return(false); } errorMessage = string.Empty; stash = GitResultParser.ParseStashInfoResult(commandResult.OutputMessage); if (AreUntrackedFilesExist(id)) { if (!TryGetStashUntrackedContent(id, out var untrackedInfo, out errorMessage)) { return(false); } foreach (var file in untrackedInfo.ChangedFiles) { stash.ChangedFiles.Add(file); } } if (AreStagedFilesExist(id)) { if (!TryGetStashStagedContent(id, out var stagedInfo, out errorMessage)) { return(false); } foreach (var file in stagedInfo.ChangedFiles) { stash.ChangedFiles.Add(file); } } return(true); }
/// <summary> /// Gets stash info by id. /// </summary> /// <param name="id">Stash id.</param> /// <param name="stash">Stash model.</param> /// <param name="errorMessage">Error message.</param> /// <returns>Bool value that indicates whether command execution was succeeded.</returns> public bool TryGetStashStagedContent(int id, out Stash stash, out string errorMessage) { var infoCommand = string.Format(GitCommandConstants.StashStagedInfoFormatted, id); var commandResult = ExecuteWithCmd(infoCommand); if (commandResult.IsError) { errorMessage = commandResult.ErrorMessage; stash = null; return(false); } errorMessage = string.Empty; stash = GitResultParser.ParseStashInfoResult(commandResult.OutputMessage); infoCommand = string.Format(GitCommandConstants.StashUntrackedAndStagedInfoFormatted, id); commandResult = ExecuteWithCmd(infoCommand); if (commandResult.IsError) { errorMessage = commandResult.ErrorMessage; stash = null; return(false); } errorMessage = string.Empty; var stashWithOnlyUntrackedFiles = GitResultParser.ParseStashInfoResult(commandResult.OutputMessage); var untrackedFilesNames = stashWithOnlyUntrackedFiles.ChangedFiles.Select(f => f.Path).ToList(); foreach (var file in stash.ChangedFiles) { if (untrackedFilesNames.Contains(file.Path)) { file.IsNew = true; } file.IsStaged = true; } return(true); }