packages feed

git-brunch 1.1.2.0 → 1.2.0.0

raw patch · 6 files changed

+99/−28 lines, 6 filesdep +optparse-applicativesetup-changed

Dependencies added: optparse-applicative

Files

README.md view
@@ -23,6 +23,11 @@ 1. `chmod +x git-brunch` 1. Add to `PATH` +### Arch Linux++`git-brunch` is in the [AUR](https://aur.archlinux.org/packages/git-brunch).+Install it with e.g. `yay -S git-brunch` or `pamac install git-brunch`.+ ### [Stack](https://haskellstack.org)  #### Install@@ -60,13 +65,13 @@ ### Run application  ```shell-./run.sh+stack build --exec git-brunch ```  ### Run tests  ```shell-stack test --fast --file-watch+stack test --file-watch ```  ### Build statically linked@@ -74,3 +79,18 @@ ```shell stack install --flag git-brunch:static ```++### Generate nix++```sh+cabal2nix --shell . > default.nix+```++## Release++- Bump version in `package.yaml` and `default.nix`+- Create a tag `v0.0.0` locally and push it+- Release on github will be created by CI+- Update release description+- `stack upload .`+- Update [AUR](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=git-brunch#n3)
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
app/Git.hs view
@@ -1,6 +1,7 @@ module Git   ( listBranches   , checkout+  , fetch   , rebaseInteractive   , toBranches   , Branch(..)@@ -38,6 +39,8 @@     ]     [] +fetch :: IO String+fetch = readProcess "git" ["fetch", "--all"] []  toBranches :: String -> [Branch] toBranches input = toBranch <$> filter (not . isHead) (lines input)@@ -58,8 +61,9 @@   rebaseInteractive :: Branch -> IO ExitCode-rebaseInteractive branch =-  spawnGit ["rebase", "--interactive", "--autostash", branchName branch]+rebaseInteractive branch = do+  putStrLn $ "Rebase onto " <> fullBranchName branch+  spawnGit ["rebase", "--interactive", "--autostash", fullBranchName branch]   spawnGit :: [String] -> IO ExitCode@@ -78,6 +82,10 @@ branchName (BranchLocal   n ) = n branchName (BranchRemote _ n) = n +fullBranchName :: Branch -> String+fullBranchName (BranchCurrent n ) = n+fullBranchName (BranchLocal   n ) = n+fullBranchName (BranchRemote r n) = r <> "/" <> n  isHead :: String -> Bool isHead = isInfixOf "HEAD"
app/GitBrunch.hs view
@@ -45,9 +45,14 @@ import           Theme                          ( theme )  -data State = State { _focus :: Name, _gitCommand :: GitCommand,  _localBranches :: L.List Name Branch, _remoteBranches :: L.List Name Branch } data Name = Local | Remote deriving (Ord, Eq, Show) data GitCommand = GitRebase | GitCheckout deriving (Ord, Eq)+data State = State+  { _focus :: Name+  , _gitCommand :: GitCommand+  , _localBranches :: L.List Name Branch+  , _remoteBranches :: L.List Name Branch+  }  instance (Show GitCommand) where   show GitCheckout = "checkout"@@ -56,7 +61,7 @@ main :: IO a main = do   branches <- Git.listBranches-  state    <- M.defaultMain app $ initialState branches+  state    <- M.defaultMain app $ setBranches branches initialState   let gitCommand = _gitCommand state   let branch     = selectedBranch state   let runGit = \case@@ -94,7 +99,7 @@     [ drawInstruction "HJKL"  "navigate"     , drawInstruction "Enter" "checkout"     , drawInstruction "R"     "rebase"-    , drawInstruction "Esc/Q" "exit"+    , drawInstruction "F"     "fetch"     ]  @@ -134,22 +139,33 @@       focusRemote     = M.continue $ focusBranches Remote state       deleteSelection = focussedBranchesL %~ L.listClear       quit            = M.halt $ deleteSelection state+      updateBranches  = M.suspendAndResume (updateBranchList state)   in  case lowerCaseEvent e of-        V.EvKey V.KEsc        [] -> quit-        V.EvKey (V.KChar 'q') [] -> quit-        V.EvKey V.KEnter      [] -> endWithCheckout-        V.EvKey (V.KChar 'r') [] -> endWithRebase-        V.EvKey V.KLeft       [] -> focusLocal-        V.EvKey (V.KChar 'h') [] -> focusLocal-        V.EvKey V.KRight      [] -> focusRemote-        V.EvKey (V.KChar 'l') [] -> focusRemote-        event                    -> navigate state event+        V.EvKey V.KEsc        []        -> quit+        V.EvKey (V.KChar 'q') []        -> quit+        V.EvKey (V.KChar 'c') [V.MCtrl] -> quit+        V.EvKey (V.KChar 'd') [V.MCtrl] -> quit+        V.EvKey V.KEnter      []        -> endWithCheckout+        V.EvKey (V.KChar 'r') []        -> endWithRebase+        V.EvKey V.KLeft       []        -> focusLocal+        V.EvKey (V.KChar 'h') []        -> focusLocal+        V.EvKey V.KRight      []        -> focusRemote+        V.EvKey (V.KChar 'l') []        -> focusRemote+        V.EvKey (V.KChar 'f') []        -> updateBranches+        event                           -> navigate state event  where   lowerCaseEvent (V.EvKey (V.KChar c) []) = V.EvKey (V.KChar (toLower c)) []   lowerCaseEvent e'                       = e'  appHandleEvent state _ = M.continue state +updateBranchList :: State -> IO State+updateBranchList state = do+  putStrLn "Fetching branches"+  output <- fetch+  putStr output+  branches <- listBranches+  return $ setBranches branches state  focusBranches :: Name -> State -> State focusBranches target state = if state ^. focusL == target@@ -169,17 +185,21 @@   M.continue newState  -initialState :: [Branch] -> State-initialState branches = State-  { _focus          = Local-  , _gitCommand     = GitCheckout-  , _localBranches  = L.list Local (Vec.fromList local) 1-  , _remoteBranches = L.list Remote (Vec.fromList remote) 1-  }+initialState :: State+initialState =+  State Local GitCheckout (L.list Local Vec.empty 1) (L.list Remote Vec.empty 1)+++setBranches :: [Branch] -> State -> State+setBranches branches state = newState  where   (remote, local) = partition isRemote branches   isRemote (BranchRemote _ _) = True   isRemote _                  = False+  toList n xs = L.list n (Vec.fromList xs) 1+  newState = state { _localBranches  = toList Local local+                   , _remoteBranches = toList Remote remote+                   }   selectedBranch :: State -> Maybe Branch
app/Main.hs view
@@ -1,7 +1,29 @@ module Main where +import           Options.Applicative+import           Paths_git_brunch               ( version )+import           Data.Version                   ( showVersion )+ import qualified GitBrunch ++data Mode = RunGitBrunch | ShowVersion++ main :: IO ()-main = GitBrunch.main+main = run =<< execParser opts+ where+  opts = info+    (versionParser <|> pure RunGitBrunch <**> helper)+    (header "git-brunch - A git checkout and rebase command-line tool")+++run :: Mode -> IO ()+run ShowVersion  = putStrLn $ showVersion version+run RunGitBrunch = GitBrunch.main+++versionParser :: Parser Mode+versionParser =+  flag' ShowVersion (long "version" <> short 'v' <> help "Show version") 
git-brunch.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 5b7eb71a309f48faa9be9042e708c49c0f820ed08b4058d60050cdedd65e5278+-- hash: 22a15a4c423b8a74ed7792d569b01d8dd5213d7fbd8986b8f9d632f6497cbee5  name:           git-brunch-version:        1.1.2.0+version:        1.2.0.0 synopsis:       git checkout command-line tool description:    Please see the README on GitHub at <https://github.com/andys8/git-brunch#readme> category:       Git@@ -42,7 +42,9 @@   build-depends:       base >=4.7 && <5     , brick+    , hspec     , microlens+    , optparse-applicative     , process     , vector     , vty@@ -68,6 +70,7 @@     , brick     , hspec     , microlens+    , optparse-applicative     , process     , vector     , vty