Skip to content

Commit dff7aea

Browse files
authored
Merge function (#24)
Solves #23
1 parent 916403b commit dff7aea

File tree

7 files changed

+55
-42
lines changed

7 files changed

+55
-42
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# git-brunch [![Travis](https://travis-ci.org/andys8/git-brunch.svg?branch=master)](https://travis-ci.org/andys8/git-brunch) ![Actions](https://github.com/andys8/git-brunch/workflows/CI/badge.svg)
22

3-
A git branch checkout command-line tool
3+
A git command-line tool to work with branches
44

55
![screenshot](https://raw.githubusercontent.com/andys8/git-brunch/master/screenshot.png)
66

77
## Features
88

9-
- Checkout local or remote branch
10-
- Rebase onto a branch
9+
- Quickly checkout local or remote branch
10+
- Merge or rebase a branch
1111
- Search for a branch
1212
- Delete a branch
1313
- Fetch / Update

app/Git.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module Git
88
, isRemoteBranch
99
, listBranches
1010
, rebaseInteractive
11+
, merge
1112
, toBranches
12-
)
13-
where
13+
) where
1414

1515
import Data.Char ( isSpace )
1616
import Data.List
@@ -64,6 +64,11 @@ rebaseInteractive branch = do
6464
putStrLn $ "Rebase onto " <> fullBranchName branch
6565
spawnGit ["rebase", "--interactive", "--autostash", fullBranchName branch]
6666

67+
merge :: Branch -> IO ExitCode
68+
merge branch = do
69+
putStrLn $ "Merge branch " <> fullBranchName branch
70+
spawnGit ["merge", fullBranchName branch]
71+
6772
deleteBranch :: Branch -> IO ExitCode
6873
deleteBranch (BranchCurrent _ ) = error "Cannot delete current branch"
6974
deleteBranch (BranchLocal n ) = spawnGit ["branch", "-D", n]

app/GitBrunch.hs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
11
{-# LANGUAGE LambdaCase #-}
22
module GitBrunch
33
( main
4-
)
5-
where
4+
) where
65

7-
import Brick.Main ( halt
8-
, continue
6+
import Brick.Main ( continue
7+
, halt
98
, suspendAndResume
109
)
10+
import qualified Brick.Main as M
1111
import Brick.Themes ( themeToAttrMap )
1212
import Brick.Types
13+
import qualified Brick.Widgets.Border as B
14+
import qualified Brick.Widgets.Border.Style as BS
15+
import qualified Brick.Widgets.Center as C
1316
import Brick.Widgets.Core
17+
import qualified Brick.Widgets.Dialog as D
18+
import qualified Brick.Widgets.Edit as E
19+
import qualified Brick.Widgets.List as L
1420
import Control.Exception ( SomeException
1521
, catch
1622
)
1723
import Control.Monad
1824
import Data.Char
1925
import Data.List
2026
import Data.Maybe ( fromMaybe )
27+
import qualified Data.Vector as Vec
2128
import Graphics.Vty hiding ( update )
22-
import Lens.Micro ( (^.)
23-
, (.~)
24-
, (%~)
29+
import Lens.Micro ( (%~)
2530
, (&)
31+
, (.~)
2632
, Lens'
33+
, (^.)
2734
, lens
2835
)
2936
import System.Exit
30-
import qualified Brick.Main as M
31-
import qualified Brick.Widgets.Border as B
32-
import qualified Brick.Widgets.Border.Style as BS
33-
import qualified Brick.Widgets.Center as C
34-
import qualified Brick.Widgets.Dialog as D
35-
import qualified Brick.Widgets.Edit as E
36-
import qualified Brick.Widgets.List as L
37-
import qualified Data.Vector as Vec
3837

3938
import Git ( Branch(..) )
40-
import Theme
4139
import qualified Git
40+
import Theme
4241

4342

4443
data Name = Local | Remote | Filter deriving (Ord, Eq, Show)
4544
data RemoteName = RLocal | RRemote deriving (Eq)
46-
data GitCommand = GitRebase | GitCheckout | GitDeleteBranch deriving (Ord, Eq)
45+
data GitCommand = GitRebase | GitMerge | GitCheckout | GitDeleteBranch deriving (Ord, Eq)
4746
data DialogResult = SetDialog Dialog | EndDialog DialogOption
4847
data DialogOption = Cancel | Confirm
4948
type Dialog = D.Dialog DialogOption
5049

5150
data State = State
52-
{ _focus :: RemoteName
53-
, _gitCommand :: GitCommand
54-
, _branches :: [Branch]
55-
, _localBranches :: L.List Name Branch
56-
, _remoteBranches :: L.List Name Branch
57-
, _dialog :: Maybe Dialog
58-
, _filter :: E.Editor String Name
51+
{ _focus :: RemoteName
52+
, _gitCommand :: GitCommand
53+
, _branches :: [Branch]
54+
, _localBranches :: L.List Name Branch
55+
, _remoteBranches :: L.List Name Branch
56+
, _dialog :: Maybe Dialog
57+
, _filter :: E.Editor String Name
5958
, _isEditingFilter :: Bool
6059
}
6160

6261

63-
instance (Show GitCommand) where
62+
instance Show GitCommand where
6463
show GitCheckout = "checkout"
6564
show GitRebase = "rebase"
65+
show GitMerge = "merge"
6666
show GitDeleteBranch = "delete"
6767

6868

@@ -81,6 +81,7 @@ main = do
8181
gitFunction = \case
8282
GitCheckout -> Git.checkout
8383
GitRebase -> Git.rebaseInteractive
84+
GitMerge -> Git.merge
8485
GitDeleteBranch -> Git.deleteBranch
8586

8687
emptyState :: State
@@ -126,11 +127,11 @@ appDraw state =
126127
, C.hCenter $ toBranchList RRemote remoteBranchesL
127128
]
128129
instructions = maxWidth 100 $ hBox
129-
[ drawInstruction "HJKL" "move"
130-
, drawInstruction "Enter" "checkout"
130+
[ drawInstruction "Enter" "checkout"
131131
, drawInstruction "/" "filter"
132132
, drawInstruction "F" "fetch"
133133
, drawInstruction "R" "rebase"
134+
, drawInstruction "M" "merge"
134135
, drawInstruction "D" "delete"
135136
]
136137

@@ -225,6 +226,7 @@ appHandleEventMain state (VtyEvent e) =
225226
confirmDelete Nothing = continue state
226227
endWithCheckout = halt $ state { _gitCommand = GitCheckout }
227228
endWithRebase = halt $ state { _gitCommand = GitRebase }
229+
endWithMerge = halt $ state { _gitCommand = GitMerge }
228230
focusLocal = focusBranches RLocal state
229231
focusRemote = focusBranches RRemote state
230232
doFetch = suspendAndResume (fetchBranches state)
@@ -245,7 +247,9 @@ appHandleEventMain state (VtyEvent e) =
245247
EvKey (KChar 'f') [MCtrl] -> startEditingFilter
246248
EvKey (KChar 'd') [] -> confirmDelete (selectedBranch state)
247249
EvKey KEnter [] -> endWithCheckout
250+
EvKey (KChar 'c') [] -> endWithCheckout
248251
EvKey (KChar 'r') [] -> endWithRebase
252+
EvKey (KChar 'm') [] -> endWithMerge
249253
EvKey KLeft [] -> focusLocal
250254
EvKey (KChar 'h') [] -> focusLocal
251255
EvKey KRight [] -> focusRemote

app/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Main where
22

3+
import Data.Version ( showVersion )
34
import Options.Applicative
45
import Paths_git_brunch ( version )
5-
import Data.Version ( showVersion )
66

77
import qualified GitBrunch
88

@@ -15,7 +15,7 @@ main = run =<< execParser opts
1515
where
1616
opts = info
1717
(versionParser <|> pure RunGitBrunch <**> helper)
18-
(header "git-brunch - A git checkout and rebase command-line tool")
18+
(header "git-brunch - A git command-line tool to work with branches")
1919

2020

2121
run :: Mode -> IO ()

app/Theme.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import Brick.AttrMap ( AttrName
55
)
66
import Brick.Themes
77
import Brick.Util
8-
import Graphics.Vty
9-
import qualified Brick.Widgets.Dialog as Dialog
10-
import qualified Brick.Widgets.List as List
118
import Brick.Widgets.Border as Border
9+
import qualified Brick.Widgets.Dialog as Dialog
1210
import qualified Brick.Widgets.Edit as Edit
11+
import qualified Brick.Widgets.List as List
12+
import Graphics.Vty
1313

1414
theme :: Theme
1515
theme = newTheme

git-brunch.cabal

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
cabal-version: 1.12
22

3-
-- This file has been generated from package.yaml by hpack version 0.33.0.
3+
-- This file has been generated from package.yaml by hpack version 0.34.4.
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: 643cd917a331afd2c5c769ae081cd6f382eec74c30471e6b5b3ac9315c3df792
7+
-- hash: c32cfb3e007291aaae447a467d7a182f94a45c06f63f0c1cb46886481916468d
88

99
name: git-brunch
1010
version: 1.4.4.0
@@ -39,7 +39,9 @@ executable git-brunch
3939
Paths_git_brunch
4040
hs-source-dirs:
4141
app
42-
default-extensions: StrictData OverloadedStrings
42+
default-extensions:
43+
StrictData
44+
OverloadedStrings
4345
build-depends:
4446
base >=4.7 && <5
4547
, brick
@@ -65,7 +67,9 @@ test-suite git-brunch-test
6567
hs-source-dirs:
6668
test
6769
app
68-
default-extensions: StrictData OverloadedStrings
70+
default-extensions:
71+
StrictData
72+
OverloadedStrings
6973
ghc-options: -threaded -rtsopts -with-rtsopts=-N
7074
build-depends:
7175
base >=4.7 && <5

test/Spec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Test.Hspec
21
import Git
2+
import Test.Hspec
33

44
main :: IO ()
55
main = hspec $ describe "Git.toBranch" $ do

0 commit comments

Comments
 (0)