File: CurrentBranch.hs

package info (click to toggle)
git-annex 7.20190129-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 56,292 kB
  • sloc: haskell: 59,105; sh: 1,255; makefile: 225; perl: 136; ansic: 44
file content (41 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{- currently checked out branch
 -
 - Copyright 2018 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU AGPL version 3 or higher.
 -}

module Annex.CurrentBranch where

import Annex.Common
import Types.AdjustedBranch
import Annex.AdjustedBranch.Name
import qualified Annex
import qualified Git
import qualified Git.Branch

type CurrBranch = (Maybe Git.Branch, Maybe Adjustment)

{- Gets the currently checked out branch.
 - When on an adjusted branch, gets the original branch, and the adjustment.
 -
 - Cached for speed.
 -
 - Until a commit is made in a new repository, no branch is checked out.
 - Since git-annex may make the first commit, this does not cache
 - the absence of a branch.
 -}
getCurrentBranch :: Annex CurrBranch
getCurrentBranch = maybe cache return
	=<< Annex.getState Annex.cachedcurrentbranch
  where
	cache = inRepo Git.Branch.current >>= \case
		Just b -> do
			let v = case adjustedToOriginal b of 
                        	Nothing -> (Just b, Nothing) 
                                Just (adj, origbranch) -> 
                                	(Just origbranch, Just adj)
			Annex.changeState $ \s ->
				s { Annex.cachedcurrentbranch = Just v }
			return v
		Nothing -> return (Nothing, Nothing)