mirror of
https://github.com/kowainik/hit-on.git
synced 2024-11-03 23:06:10 +03:00
Resolves #136
This commit is contained in:
parent
6ba3edcba6
commit
089f115bde
@ -14,7 +14,7 @@ import Options.Applicative (CommandFields, Mod, Parser, ParserInfo, argument, au
|
||||
execParser, flag, flag', fullDesc, help, helper, info, infoOption, long,
|
||||
metavar, option, progDesc, short, strArgument, subparser, switch)
|
||||
|
||||
import Hit.Core (CommitOptions (..), IssueOptions (..), Milestone (..), PushBool (..),
|
||||
import Hit.Core (CommitOptions (..), ForceFlag (..), IssueOptions (..), Milestone (..),
|
||||
defaultIssueOptions)
|
||||
import Hit.Git (runAmend, runClear, runClone, runCommit, runCurrent, runDiff, runFix, runFresh,
|
||||
runHop, runLog, runNew, runPush, runResolve, runStash, runStatus, runSync,
|
||||
@ -40,9 +40,9 @@ hit = execParser cliParser >>= \case
|
||||
Fix message pushBool -> runFix message pushBool
|
||||
Amend localAmend -> runAmend localAmend
|
||||
Resolve branchName -> runResolve branchName
|
||||
Push isForce -> runPush isForce
|
||||
Sync -> runSync
|
||||
Clear isForce -> runClear isForce
|
||||
Push forceFlag -> runPush forceFlag
|
||||
Sync forceFlag -> runSync forceFlag
|
||||
Clear forceFlag -> runClear forceFlag
|
||||
Current -> runCurrent >>= flip whenJust (\i -> runIssue defaultIssueOptions {ioIssueNumber = Just i})
|
||||
Status commit -> runCurrent >> runStatus commit
|
||||
Diff commit -> runDiff commit
|
||||
@ -73,13 +73,13 @@ data HitCommand
|
||||
| Uncommit
|
||||
| Fix
|
||||
(Maybe Text) -- ^ Text of the fix commit
|
||||
PushBool -- ^ Force push
|
||||
ForceFlag -- ^ Force push
|
||||
| Amend
|
||||
Bool -- ^ Local amend
|
||||
| Resolve (Maybe Text)
|
||||
| Push PushBool
|
||||
| Sync
|
||||
| Clear PushBool
|
||||
| Push ForceFlag
|
||||
| Sync ForceFlag
|
||||
| Clear ForceFlag
|
||||
| Current
|
||||
| Status (Maybe Text)
|
||||
| Diff (Maybe Text)
|
||||
@ -154,7 +154,7 @@ commitP = do
|
||||
$ long "push"
|
||||
<> short 'p'
|
||||
<> help "Push current branch with this commit"
|
||||
coIsForcePush <- pushBoolP
|
||||
coIsForcePush <- forceFlagP
|
||||
pure $ Commit CommitOptions{..}
|
||||
|
||||
uncommitP :: Parser HitCommand
|
||||
@ -164,8 +164,8 @@ uncommitP = pure Uncommit
|
||||
fixP :: Parser HitCommand
|
||||
fixP = do
|
||||
commitMsg <- commitMessageP
|
||||
isForce <- pushBoolP
|
||||
pure $ Fix commitMsg isForce
|
||||
forceFlag <- forceFlagP
|
||||
pure $ Fix commitMsg forceFlag
|
||||
|
||||
amendP :: Parser HitCommand
|
||||
amendP = do
|
||||
@ -176,13 +176,13 @@ amendP = do
|
||||
pure $ Amend localAmend
|
||||
|
||||
pushP :: Parser HitCommand
|
||||
pushP = Push <$> pushBoolP
|
||||
pushP = Push <$> forceFlagP
|
||||
|
||||
syncP :: Parser HitCommand
|
||||
syncP = pure Sync
|
||||
syncP = Sync <$> forceFlagP
|
||||
|
||||
clearP :: Parser HitCommand
|
||||
clearP = Clear <$> pushBoolP
|
||||
clearP = Clear <$> forceFlagP
|
||||
|
||||
currentP :: Parser HitCommand
|
||||
currentP = pure Current
|
||||
@ -217,13 +217,12 @@ maybeCommitP = optional $ strArgument $ metavar "COMMIT_HASH"
|
||||
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 flag of force push or sync.
|
||||
forceFlagP :: Parser ForceFlag
|
||||
forceFlagP = flag Simple Force
|
||||
$ long "force"
|
||||
<> short 'f'
|
||||
<> help "Execute forcefully"
|
||||
|
||||
-- | Parse issue number as an argument.
|
||||
issueNumP :: Parser Int
|
||||
|
@ -2,7 +2,7 @@
|
||||
-}
|
||||
|
||||
module Hit.Core
|
||||
( PushBool (..)
|
||||
( ForceFlag (..)
|
||||
, CommitOptions (..)
|
||||
, IssueOptions (..)
|
||||
, Milestone (..)
|
||||
@ -10,8 +10,10 @@ module Hit.Core
|
||||
) where
|
||||
|
||||
|
||||
-- | Data type to represent the type of @push@: force-push or not.
|
||||
data PushBool
|
||||
{- | Data type to represent the type of @push@ or @sync@: force-push
|
||||
(force-reset) or not.
|
||||
-}
|
||||
data ForceFlag
|
||||
= Simple
|
||||
| Force
|
||||
deriving stock (Show, Eq)
|
||||
@ -27,7 +29,7 @@ data CommitOptions = CommitOptions
|
||||
-- | Push immediately.
|
||||
, coPush :: !Bool
|
||||
-- | Use Force push?
|
||||
, coIsForcePush :: !PushBool
|
||||
, coIsForcePush :: !ForceFlag
|
||||
}
|
||||
|
||||
-- | Options of the @hit issue@ command.
|
||||
|
@ -6,7 +6,7 @@ module Hit.Git.Amend
|
||||
|
||||
import Shellmet ()
|
||||
|
||||
import Hit.Core (PushBool (..))
|
||||
import Hit.Core (ForceFlag (..))
|
||||
import Hit.Git.Push (runPush)
|
||||
|
||||
|
||||
|
@ -7,12 +7,12 @@ module Hit.Git.Clear
|
||||
import Colourista (infoMessage)
|
||||
import Shellmet ()
|
||||
|
||||
import Hit.Core (PushBool (..))
|
||||
import Hit.Core (ForceFlag (..))
|
||||
import Hit.Prompt (Answer (..), prompt, yesOrNoText)
|
||||
|
||||
|
||||
-- | Remove all local changes permanently.
|
||||
runClear :: PushBool -> IO ()
|
||||
runClear :: ForceFlag -> IO ()
|
||||
runClear = \case
|
||||
Force -> clearChanges
|
||||
Simple -> do
|
||||
|
@ -7,7 +7,7 @@ module Hit.Git.Commit
|
||||
import Colourista (errorMessage)
|
||||
import Shellmet ()
|
||||
|
||||
import Hit.Core (CommitOptions (..), PushBool (..))
|
||||
import Hit.Core (CommitOptions (..), ForceFlag (..))
|
||||
import Hit.Formatting (stripRfc)
|
||||
import Hit.Git.Common (getCurrentBranch, issueFromBranch)
|
||||
import Hit.Git.Push (runPush)
|
||||
|
@ -4,18 +4,18 @@ module Hit.Git.Fix
|
||||
( runFix
|
||||
) where
|
||||
|
||||
import Shellmet()
|
||||
import Shellmet ()
|
||||
|
||||
import Hit.Core (PushBool (..))
|
||||
import Hit.Core (ForceFlag (..))
|
||||
import Hit.Git.Push (runPush)
|
||||
|
||||
|
||||
-- | @hit fix@ command
|
||||
runFix :: Maybe Text -> PushBool -> IO ()
|
||||
runFix msg pushBool = do
|
||||
runFix :: Maybe Text -> ForceFlag -> IO ()
|
||||
runFix msg forceFlag = do
|
||||
"git" ["add", "."]
|
||||
"git" ["commit", "-m", message]
|
||||
runPush pushBool
|
||||
runPush forceFlag
|
||||
where
|
||||
message :: Text
|
||||
message = fromMaybe "Fix" msg
|
||||
|
@ -4,14 +4,14 @@ module Hit.Git.Push
|
||||
( runPush
|
||||
) where
|
||||
|
||||
import Shellmet()
|
||||
import Shellmet ()
|
||||
|
||||
import Hit.Core (PushBool (..))
|
||||
import Hit.Core (ForceFlag (..))
|
||||
import Hit.Git.Common (getCurrentBranch)
|
||||
|
||||
|
||||
-- | @hit push@ command.
|
||||
runPush :: PushBool -> IO ()
|
||||
runPush isForce = getCurrentBranch >>= \branch ->
|
||||
runPush :: ForceFlag -> IO ()
|
||||
runPush forceFlag = getCurrentBranch >>= \branch ->
|
||||
"git" $ ["push", "--set-upstream", "origin", branch]
|
||||
++ ["--force" | isForce == Force]
|
||||
++ ["--force" | forceFlag == Force]
|
||||
|
@ -4,12 +4,16 @@ module Hit.Git.Sync
|
||||
( runSync
|
||||
) where
|
||||
|
||||
import Shellmet()
|
||||
import Shellmet ()
|
||||
|
||||
import Hit.Core (ForceFlag (..))
|
||||
import Hit.Git.Common (getCurrentBranch)
|
||||
|
||||
|
||||
-- | @hit sync@ command.
|
||||
runSync :: IO ()
|
||||
runSync = getCurrentBranch >>= \branch ->
|
||||
"git" ["pull", "--rebase", "origin", branch]
|
||||
runSync :: ForceFlag -> IO ()
|
||||
runSync forceFlag = getCurrentBranch >>= \branch -> case forceFlag of
|
||||
Simple -> "git" ["pull", "--rebase", "origin", branch]
|
||||
Force -> do
|
||||
"git" ["fetch", "origin", branch]
|
||||
"git" ["reset", "--hard", "origin/" <> branch]
|
||||
|
@ -10,7 +10,7 @@ module Hit.Git.Wip
|
||||
( runWip
|
||||
) where
|
||||
|
||||
import Hit.Core (CommitOptions (..), PushBool (..))
|
||||
import Hit.Core (CommitOptions (..), ForceFlag (..))
|
||||
import Hit.Git.Commit (runCommit)
|
||||
import Hit.Git.Common (getCurrentBranch)
|
||||
import Hit.Git.New (runNew)
|
||||
|
Loading…
Reference in New Issue
Block a user