mirror of
https://github.com/kowainik/hit-on.git
synced 2024-10-26 11:47:25 +03:00
* [#82] Add force flag to hit fix Resolves #82 * Fix stupid HLint rule * Fix
This commit is contained in:
parent
1c43c48314
commit
ed9969ab36
@ -8,6 +8,8 @@ The changelog is available [on GitHub][2].
|
||||
* [#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.
|
||||
* [#82](https://github.com/kowainik/hit-on/issues/82):
|
||||
Add `--force` flag to `hit fix` command.
|
||||
* Bump up to GHC 8.6.5.
|
||||
* Bump up to `relude-0.5.0`.
|
||||
|
||||
|
@ -52,6 +52,7 @@ library
|
||||
exposed-modules: Hit
|
||||
Hit.Cli
|
||||
Hit.ColorTerminal
|
||||
Hit.Core
|
||||
Hit.Git
|
||||
Hit.Git.Status
|
||||
Hit.Issue
|
||||
|
@ -9,11 +9,12 @@ module Hit.Cli
|
||||
|
||||
import Data.Version (showVersion)
|
||||
import Development.GitRev (gitCommitDate, gitDirty, gitHash)
|
||||
import Options.Applicative (Parser, ParserInfo, argument, auto, command, execParser, fullDesc, help,
|
||||
helper, info, infoOption, long, metavar, progDesc, short, strArgument,
|
||||
subparser, switch)
|
||||
import Options.Applicative (Parser, ParserInfo, argument, auto, command, execParser, flag, fullDesc,
|
||||
help, helper, info, infoOption, long, metavar, progDesc, short,
|
||||
strArgument, subparser, switch)
|
||||
|
||||
import Hit.ColorTerminal (arrow, blueCode, boldCode, redCode, resetCode)
|
||||
import Hit.Core (PushBool (..))
|
||||
import Hit.Git (getUsername, runAmend, runClone, runCommit, runCurrent, runFix, runFresh, runHop,
|
||||
runNew, runPush, runResolve, runStatus, runSync)
|
||||
import Hit.Issue (runIssue)
|
||||
@ -31,7 +32,7 @@ hit = execParser cliParser >>= \case
|
||||
then getUsername >>= runIssue issueNum . Just
|
||||
else runIssue issueNum Nothing
|
||||
Commit message noIssue -> runCommit message noIssue
|
||||
Fix message -> runFix message
|
||||
Fix message pushBool -> runFix message pushBool
|
||||
Amend -> runAmend
|
||||
Resolve branchName -> runResolve branchName
|
||||
Push isForce -> runPush isForce
|
||||
@ -56,10 +57,12 @@ data HitCommand
|
||||
| New Int
|
||||
| Issue (Maybe Int) Bool
|
||||
| Commit Text Bool
|
||||
| Fix (Maybe Text)
|
||||
| Fix
|
||||
(Maybe Text) -- ^ Text of the fix commit
|
||||
PushBool -- ^ Force push
|
||||
| Amend
|
||||
| Resolve (Maybe Text)
|
||||
| Push Bool
|
||||
| Push PushBool
|
||||
| Sync
|
||||
| Current
|
||||
| Status (Maybe Text)
|
||||
@ -109,18 +112,18 @@ commitP = do
|
||||
<> help "Do not add [#ISSUE_NUMBER] prefix when specified"
|
||||
pure $ Commit msg noIssue
|
||||
|
||||
{- HLINT ignore "Use <$>"-}
|
||||
fixP :: Parser HitCommand
|
||||
fixP = Fix <$> commitMessageP
|
||||
fixP = do
|
||||
commitMsg <- commitMessageP
|
||||
isForce <- pushBoolP
|
||||
pure $ Fix commitMsg isForce
|
||||
|
||||
amendP :: Parser HitCommand
|
||||
amendP = pure Amend
|
||||
|
||||
pushP :: Parser HitCommand
|
||||
pushP = Push <$> switch
|
||||
( long "force"
|
||||
<> short 'f'
|
||||
<> help "Force push"
|
||||
)
|
||||
pushP = Push <$> pushBoolP
|
||||
|
||||
syncP :: Parser HitCommand
|
||||
syncP = pure Sync
|
||||
@ -141,10 +144,18 @@ cloneP = Clone <$> strArgument (metavar "REPOSITORY")
|
||||
maybeBranchP :: Parser (Maybe Text)
|
||||
maybeBranchP = optional $ strArgument (metavar "BRANCH_NAME")
|
||||
|
||||
-- / Parse optional commit message as an argument
|
||||
-- | Parse optional commit message as an argument
|
||||
commitMessageP :: Parser (Maybe Text)
|
||||
commitMessageP = optional $ strArgument (metavar "COMMIT_MESSAGE")
|
||||
|
||||
-- | Parse flag of force push.
|
||||
pushBoolP :: Parser PushBool
|
||||
pushBoolP = flag Simple Force
|
||||
( long "force"
|
||||
<> short 'f'
|
||||
<> help "Force push"
|
||||
)
|
||||
|
||||
-- | Parse issue number as an argument.
|
||||
issueNumP :: Parser Int
|
||||
issueNumP = argument auto $ metavar "ISSUE_NUMBER"
|
||||
|
13
src/Hit/Core.hs
Normal file
13
src/Hit/Core.hs
Normal file
@ -0,0 +1,13 @@
|
||||
{- | This module contains core data types used in the package.
|
||||
-}
|
||||
|
||||
module Hit.Core
|
||||
( PushBool (..)
|
||||
) where
|
||||
|
||||
|
||||
-- | Data type to represent the type of @push@: force-push or not.
|
||||
data PushBool
|
||||
= Simple
|
||||
| Force
|
||||
deriving (Show, Eq)
|
@ -23,6 +23,7 @@ import Data.Char (isAlphaNum, isDigit, isSpace)
|
||||
import Shellmet (($|))
|
||||
|
||||
import Hit.ColorTerminal (arrow, errorMessage, greenCode, resetCode)
|
||||
import Hit.Core (PushBool (..))
|
||||
import Hit.Git.Status (showPrettyDiff)
|
||||
import Hit.Issue (getIssueTitle, mkIssueId)
|
||||
|
||||
@ -75,14 +76,15 @@ runCommit (T.strip -> msg) (not -> hasIssue)
|
||||
let issue = "#" <> show n
|
||||
in "[" <> issue <> "] " <> msg <> "\n\nResolves " <> issue
|
||||
|
||||
-- / @hit fix@ command
|
||||
runFix :: Maybe Text -> IO ()
|
||||
runFix msg = do
|
||||
-- | @hit fix@ command
|
||||
runFix :: Maybe Text -> PushBool -> IO ()
|
||||
runFix msg pushBool = do
|
||||
"git" ["add", "."]
|
||||
"git" ["commit", "-m", message]
|
||||
runPush False
|
||||
runPush pushBool
|
||||
where
|
||||
message = fromMaybe "Fix after review" msg
|
||||
message :: Text
|
||||
message = fromMaybe "Fix" msg
|
||||
|
||||
|
||||
-- | @hit amend@ command.
|
||||
@ -90,17 +92,18 @@ runAmend :: IO ()
|
||||
runAmend = do
|
||||
"git" ["add", "."]
|
||||
"git" ["commit", "--amend", "--no-edit"]
|
||||
runPush True
|
||||
runPush Force
|
||||
|
||||
-- | @hit push@ command.
|
||||
runPush :: Bool -> IO ()
|
||||
runPush :: PushBool -> IO ()
|
||||
runPush isForce = getCurrentBranch >>= \branch ->
|
||||
"git" $ ["push", "--set-upstream", "origin", branch]
|
||||
++ ["--force" | isForce]
|
||||
++ ["--force" | isForce == Force]
|
||||
|
||||
-- | @hit sync@ command.
|
||||
runSync :: IO ()
|
||||
runSync = getCurrentBranch >>= \branch -> "git" ["pull", "--rebase", "origin", branch]
|
||||
runSync = getCurrentBranch >>= \branch ->
|
||||
"git" ["pull", "--rebase", "origin", branch]
|
||||
|
||||
-- | @hit resolve@ command.
|
||||
runResolve :: Maybe Text -> IO ()
|
||||
|
Loading…
Reference in New Issue
Block a user