]> dgit.raspbian.org Git - git-annex.git/commitdiff
uninit edge cases
authorJoey Hess <joeyh@joeyh.name>
Mon, 8 Nov 2021 20:47:00 +0000 (16:47 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 8 Nov 2021 20:47:00 +0000 (16:47 -0400)
* 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
CHANGELOG
Command/Uninit.hs
doc/bugs/uninit_errors_out_on_repo_without_commits.mdwn

index 104285efcf6e7fc6bbbac8ce1a49926b1b2f1606..4a0c58b277d25554391bd766260ca7ac2e86bf16 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
     also makes git add of large annexed files slower. Use it by running:
     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
 
index 473040c2c4c4bb04288c5d38e6d55b598b0f5f52..3da4de4f9cf6d3fac9e8955ee6ea0dbba1832df5 100644 (file)
@@ -1,6 +1,6 @@
 {- 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.
  -}
@@ -11,6 +11,7 @@ import Command
 import qualified Annex
 import qualified Git
 import qualified Git.Command
+import qualified Git.Ref
 import qualified Command.Unannex
 import qualified Annex.Branch
 import qualified Annex.Queue
@@ -30,14 +31,18 @@ cmd = addCheck check $
 check :: Annex ()
 check = do
        b <- current_branch
-       when (b == Annex.Branch.name) $ giveup $
-               "cannot uninit when the " ++ Git.fromRef b ++ " branch is checked out"
+       when (b == Just Annex.Branch.name) $ giveup $
+               "cannot uninit when the " ++ Git.fromRef Annex.Branch.name ++ " branch is checked out"
        top <- fromRepo Git.repoPath
        currdir <- liftIO R.getCurrentDirectory
        whenM ((/=) <$> liftIO (absPath top) <*> liftIO (absPath currdir)) $
                giveup "can only run uninit from the top of the git repository"
   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
                [Param "rev-parse", Param "--abbrev-ref", Param "HEAD"]
 
@@ -93,8 +98,9 @@ finish = do
        uninitialize
        -- avoid normal shutdown
        saveState False
-       inRepo $ Git.Command.run
-               [Param "branch", Param "-D", Param $ Git.fromRef Annex.Branch.name]
+       whenM (inRepo $ Git.Ref.exists Annex.Branch.fullname) $
+               inRepo $ Git.Command.run
+                       [Param "branch", Param "-D", Param $ Git.fromRef Annex.Branch.name]
        liftIO exitSuccess
 
 {- Turn on write bits in all remaining files in the annex directory, in
index da2e78eb9f1b6ae878f5a4bd05c65954fa1e038f..f6296c2bcede563ebeef0c979a6319ad75fcdca3 100644 (file)
@@ -31,3 +31,6 @@ operating system: linux x86_64
 supported repository versions: 8
 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]]