[#109] Do not fail on 'hit fresh' when unsuccessful rebasing (#188)

Resolves #109
This commit is contained in:
Veronika Romashkina 2020-07-07 15:29:26 +01:00 committed by GitHub
parent e6939b5c81
commit fd36f10767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 5 deletions

View File

@ -64,6 +64,8 @@ The changelog is available [on GitHub][2].
* [#135](https://github.com/kowainik/hit-on/issues/135):
Implement `hit stash diff`, `hit stash list`, `hit stash clear` commands.
Add `--name` option to `hit stash` for named stashes.
* [#109](https://github.com/kowainik/hit-on/issues/109):
Do not fail on `hit fresh` when unsuccessful rebasing.
### 0.1.0.0 — Aug 3, 2019

View File

@ -13,13 +13,25 @@ module Hit.Git.Fresh
( runFresh
) where
import Shellmet ()
import Colourista (errorMessage, infoMessage, warningMessage)
import Shellmet (($?))
import System.IO (hFlush)
import Hit.Git.Common (nameOrMaster)
import Hit.Prompt (Answer (..), arrow, prompt, yesOrNoText)
-- | @hit fresh@ command.
runFresh :: Maybe Text -> IO ()
runFresh (nameOrMaster -> branch) = do
"git" ["fetch", "origin", branch]
"git" ["rebase", "origin/" <> branch]
isRebase <- (True <$ "git" ["rebase", "origin/" <> branch]) $? pure False
unless isRebase $ do
errorMessage " 'git rebase' failed."
putTextLn $ " Do you want to abort the command? " <> yesOrNoText Y
putText arrow >> hFlush stdout
prompt Y >>= \case
Y -> do
infoMessage "Aborting the command."
"git" ["rebase", "--abort"] $? pass
N -> warningMessage "Unsuccessful 'hit fresh' while rebasing."

View File

@ -18,7 +18,8 @@ module Hit.Prompt
, arrow
) where
import Colourista (bold, errorMessage, reset)
import Colourista (errorMessage)
import Colourista.Short (b)
import qualified Data.Text as T
@ -41,8 +42,8 @@ yesOrNoWithDefault def (T.toLower -> answer )
| otherwise = Nothing
yesOrNoText :: Answer -> Text
yesOrNoText N = "y/" <> bold <> "[n]" <> reset
yesOrNoText Y = bold <> "[y]" <> reset <> "/n"
yesOrNoText N = "y/" <> b "[n]"
yesOrNoText Y = b "[y]" <> "/n"
-- | Prompt user for y/n input. Takes a default 'Answer' for the case of empty user input.
prompt :: Answer -> IO Answer