diff --git a/CHANGELOG.md b/CHANGELOG.md index e22532e..09f1f55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ The changelog is available [on GitHub][2]. ### Unreleased: 0.1.0.0 -* [#63](https://github.com/kowainik/hit-on/issues/63): +* [#63](https://github.com/kowainik/hit-on/issues/63), + [#79](https://github.com/kowainik/hit-on/issues/79): Implement `hit status` command with pretty output. * Bump up to GHC 8.6.5. * Bump up to `relude-0.5.0`. diff --git a/hit-on.cabal b/hit-on.cabal index 4b1bd8f..01c2e7d 100644 --- a/hit-on.cabal +++ b/hit-on.cabal @@ -65,6 +65,7 @@ library , github ^>= 0.20 , gitrev ^>= 1.3 , optparse-applicative ^>= 0.14 + , process ^>= 1.6 , relude ^>= 0.5 , shellmet >= 0.0.0 , text diff --git a/src/Hit/Git/Status.hs b/src/Hit/Git/Status.hs index a30a4d9..ed76d03 100644 --- a/src/Hit/Git/Status.hs +++ b/src/Hit/Git/Status.hs @@ -6,7 +6,8 @@ module Hit.Git.Status ( showPrettyDiff ) where -import Shellmet (($|)) +import Shellmet (($|), ($?)) +import System.Process (callCommand) import Hit.ColorTerminal (blueCode, boldCode, cyanCode, greenCode, magentaCode, redCode, resetCode, yellowCode) @@ -83,6 +84,10 @@ parseDiffStat = \case showPrettyDiff :: Text -> IO () showPrettyDiff commit = do + -- 1. Check rebase in progress and tell about it + whenM isRebaseInProgress $ putTextLn gitRebaseHelp + + -- 2. Output pretty diff diffName <- map words . lines <$> "git" $| ["diff", commit, "--name-status"] diffStat <- map toStats . lines <$> "git" $| ["diff", commit, "--stat", "--color=always"] let fileTypes = sortWith diffNameFile $ mapMaybe parseDiffName diffName @@ -123,3 +128,20 @@ showPrettyDiff commit = do maxOn :: (a -> Text) -> [a] -> Int maxOn f = foldl' (\acc a -> max acc $ T.length $ f a) 0 + +{- | Returns 'True' if rebase is in progress. Calls magic comand and if this +command exits with code 1 then there's no rebase in progress. +-} +isRebaseInProgress :: IO Bool +isRebaseInProgress = do + let checkRebaseCmd = callCommand "ls `git rev-parse --git-dir` | grep rebase > /dev/null 2>&1" + True <$ checkRebaseCmd $? pure False + +gitRebaseHelp :: Text +gitRebaseHelp = unlines + [ "" + , boldCode <> yellowCode <> "Rebase in progress! What you can do:" <> resetCode + , " " <> cyanCode <> "git rebase --continue " <> resetCode <> ": after fixing conflicts" + , " " <> cyanCode <> "git rebase --skip " <> resetCode <> ": to skip this patch" + , " " <> cyanCode <> "git rebase --abort " <> resetCode <> ": to abort to the original branch" + ]