uninit edge cases

* uninit: Avoid error message when no commits have been made to the
  repository yet.
* uninit: Avoid error message when there is no git-annex branch.

Sponsored-by: Svenne Krap on Patreon
This commit is contained in:
Joey Hess 2021-11-08 16:47:00 -04:00
parent 9cb02ca29e
commit 9d3ce224e3
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 18 additions and 6 deletions

View file

@ -8,6 +8,9 @@ git-annex (8.20211029) UNRELEASED; urgency=medium
there are a lot of unlocked annexed files or non-annexed files, but that there are a lot of unlocked annexed files or non-annexed files, but that
also makes git add of large annexed files slower. Use it by running: also makes git add of large annexed files slower. Use it by running:
git config filter.annex.process 'git-annex filter-process' git config filter.annex.process 'git-annex filter-process'
* uninit: Avoid error message when no commits have been made to the
repository yet.
* uninit: Avoid error message when there is no git-annex branch.
-- Joey Hess <id@joeyh.name> Mon, 01 Nov 2021 13:19:46 -0400 -- Joey Hess <id@joeyh.name> Mon, 01 Nov 2021 13:19:46 -0400

View file

@ -1,6 +1,6 @@
{- git-annex command {- git-annex command
- -
- Copyright 2010 Joey Hess <id@joeyh.name> - Copyright 2010-2021 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU AGPL version 3 or higher. - Licensed under the GNU AGPL version 3 or higher.
-} -}
@ -11,6 +11,7 @@ import Command
import qualified Annex import qualified Annex
import qualified Git import qualified Git
import qualified Git.Command import qualified Git.Command
import qualified Git.Ref
import qualified Command.Unannex import qualified Command.Unannex
import qualified Annex.Branch import qualified Annex.Branch
import qualified Annex.Queue import qualified Annex.Queue
@ -30,14 +31,18 @@ cmd = addCheck check $
check :: Annex () check :: Annex ()
check = do check = do
b <- current_branch b <- current_branch
when (b == Annex.Branch.name) $ giveup $ when (b == Just Annex.Branch.name) $ giveup $
"cannot uninit when the " ++ Git.fromRef b ++ " branch is checked out" "cannot uninit when the " ++ Git.fromRef Annex.Branch.name ++ " branch is checked out"
top <- fromRepo Git.repoPath top <- fromRepo Git.repoPath
currdir <- liftIO R.getCurrentDirectory currdir <- liftIO R.getCurrentDirectory
whenM ((/=) <$> liftIO (absPath top) <*> liftIO (absPath currdir)) $ whenM ((/=) <$> liftIO (absPath top) <*> liftIO (absPath currdir)) $
giveup "can only run uninit from the top of the git repository" giveup "can only run uninit from the top of the git repository"
where where
current_branch = Git.Ref . encodeBS . Prelude.head . lines . decodeBS <$> revhead current_branch =
ifM (inRepo Git.Ref.headExists)
( Just . Git.Ref . encodeBS . Prelude.head . lines . decodeBS <$> revhead
, return Nothing
)
revhead = inRepo $ Git.Command.pipeReadStrict revhead = inRepo $ Git.Command.pipeReadStrict
[Param "rev-parse", Param "--abbrev-ref", Param "HEAD"] [Param "rev-parse", Param "--abbrev-ref", Param "HEAD"]
@ -93,8 +98,9 @@ finish = do
uninitialize uninitialize
-- avoid normal shutdown -- avoid normal shutdown
saveState False saveState False
inRepo $ Git.Command.run whenM (inRepo $ Git.Ref.exists Annex.Branch.fullname) $
[Param "branch", Param "-D", Param $ Git.fromRef Annex.Branch.name] inRepo $ Git.Command.run
[Param "branch", Param "-D", Param $ Git.fromRef Annex.Branch.name]
liftIO exitSuccess liftIO exitSuccess
{- Turn on write bits in all remaining files in the annex directory, in {- Turn on write bits in all remaining files in the annex directory, in

View file

@ -31,3 +31,6 @@ operating system: linux x86_64
supported repository versions: 8 supported repository versions: 8
upgrade supported from repository versions: 0 1 2 3 4 5 6 7 upgrade supported from repository versions: 0 1 2 3 4 5 6 7
``` ```
> Fixed both problems, although I don't know how a git-annex branch could
> not exist. [[done]] --[[Joey]]