Skip to content

Commit

Permalink
[#80] Add hit uncommit command
Browse files Browse the repository at this point in the history
Resolves #80
  • Loading branch information
vrom911 committed Jul 29, 2019
1 parent b334901 commit 2886ecf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ The changelog is available [on GitHub][2].
number).
* [#89](https://github.com/kowainik/hit-on/issues/89):
Add `-p|push` and `-f|force` flags to `hit commit` command.
* [#80](https://github.com/kowainik/hit-on/issues/80):
Add `hit uncommit` command.
* Bump up to GHC 8.6.5.
* Bump up to `relude-0.5.0`.

Expand Down
50 changes: 30 additions & 20 deletions src/Hit/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ module Hit.Cli

import Data.Version (showVersion)
import Development.GitRev (gitCommitDate, gitDirty, gitHash)
import Options.Applicative (Parser, ParserInfo, argument, auto, command, execParser, flag, fullDesc,
help, helper, info, infoOption, long, metavar, progDesc, short,
strArgument, subparser, switch)
import Options.Applicative (CommandFields, Mod, 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 (CommitOptions (..), PushBool (..))
import Hit.Git (getUsername, runAmend, runClone, runCommit, runCurrent, runDiff, runFix, runFresh,
runHop, runNew, runPush, runResolve, runStash, runStatus, runSync, runUnstash)
runHop, runNew, runPush, runResolve, runStash, runStatus, runSync, runUncommit,
runUnstash)
import Hit.Issue (runIssue)

import qualified Data.Text as T
Expand All @@ -34,6 +35,7 @@ hit = execParser cliParser >>= \case
Stash -> runStash
Unstash -> runUnstash
Commit opts -> runCommit opts
Uncommit -> runUncommit
Fix message pushBool -> runFix message pushBool
Amend -> runAmend
Resolve branchName -> runResolve branchName
Expand Down Expand Up @@ -62,6 +64,7 @@ data HitCommand
| Stash
| Unstash
| Commit CommitOptions
| Uncommit
| Fix
(Maybe Text) -- ^ Text of the fix commit
PushBool -- ^ Force push
Expand All @@ -77,22 +80,26 @@ data HitCommand
-- | Commands parser.
hitP :: Parser HitCommand
hitP = subparser
$ command "hop" (info (helper <*> hopP) $ progDesc "Switch to branch and sync it")
<> command "fresh" (info (helper <*> freshP) $ progDesc "Rebase current branch on remote one")
<> command "new" (info (helper <*> newP) $ progDesc "Create new branch from current one")
<> command "stash" (info (helper <*> stashP) $ progDesc "Stash all local changes")
<> command "unstash" (info (helper <*> unstashP) $ progDesc "Unstash previously stashed changes")
<> command "commit" (info (helper <*> commitP) $ progDesc "Commit all local changes and prepend issue number")
<> command "fix" (info (helper <*> fixP) $ progDesc "Fix requested changes to the last commit")
<> command "amend" (info (helper <*> amendP) $ progDesc "Amend changes to the last commit and force push")
<> command "issue" (info (helper <*> issueP) $ progDesc "Show the information about the issue")
<> command "push" (info (helper <*> pushP) $ progDesc "Push the current branch")
<> command "sync" (info (helper <*> syncP) $ progDesc "Sync local branch with its remote")
<> command "resolve" (info (helper <*> resolveP) $ progDesc "Switch to master, sync and delete the branch")
<> command "current" (info (helper <*> currentP) $ progDesc "Show info about current branch and issue (if applicable)")
<> command "status" (info (helper <*> statusP) $ progDesc "Show current branch and beautiful stats with COMMIT_HASH (by default HEAD)")
<> command "diff" (info (helper <*> diffP) $ progDesc "Display beautiful diff with COMMIT_HASH (by default HEAD)")
<> command "clone" (info (helper <*> cloneP) $ progDesc "Clone the repo. Use 'reponame' or 'username/reponame' formats")
$ com "hop" hopP "Switch to branch and sync it"
<> com "fresh" freshP "Rebase current branch on remote one"
<> com "new" newP "Create new branch from current one"
<> com "stash" stashP "Stash all local changes"
<> com "unstash" unstashP "Unstash previously stashed changes"
<> com "commit" commitP "Commit all local changes and prepend issue number"
<> com "uncommit" uncommitP "Reset to the previous commit saving the changes"
<> com "fix" fixP "Fix requested changes to the last commit"
<> com "amend" amendP "Amend changes to the last commit and force push"
<> com "issue" issueP "Show the information about the issue"
<> com "push" pushP "Push the current branch"
<> com "sync" syncP "Sync local branch with its remote"
<> com "resolve" resolveP "Switch to master, sync and delete the branch"
<> com "current" currentP "Show info about current branch and issue (if applicable)"
<> com "status" statusP "Show current branch and beautiful stats with COMMIT_HASH (by default HEAD)"
<> com "diff" diffP "Display beautiful diff with COMMIT_HASH (by default HEAD)"
<> com "clone" cloneP "Clone the repo. Use 'reponame' or 'username/reponame' formats"
where
com :: String -> Parser HitCommand -> String -> Mod CommandFields HitCommand
com name p desc = command name (info (helper <*> p) $ progDesc desc)

hopP :: Parser HitCommand
hopP = Hop <$> maybeBranchP
Expand Down Expand Up @@ -132,6 +139,9 @@ commitP = do
coIsForcePush <- pushBoolP
pure $ Commit CommitOptions{..}

uncommitP :: Parser HitCommand
uncommitP = pure Uncommit

{- HLINT ignore "Use <$>"-}
fixP :: Parser HitCommand
fixP = do
Expand Down
5 changes: 5 additions & 0 deletions src/Hit/Git.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Hit.Git
, runStash
, runUnstash
, runCommit
, runUncommit
, runFix
, runAmend
, runSync
Expand Down Expand Up @@ -102,6 +103,10 @@ runCommit CommitOptions{..} = case coName of
hasIssue :: Bool
hasIssue = not coNoIssueNumber

-- | @hit uncommit@ command
runUncommit :: IO ()
runUncommit = "git" ["reset", "HEAD~1"]

-- | @hit fix@ command
runFix :: Maybe Text -> PushBool -> IO ()
runFix msg pushBool = do
Expand Down

0 comments on commit 2886ecf

Please sign in to comment.