From cb4d9f7b1f8ce251d86f8f0163c0884cb9454603 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 23 Mar 2023 16:23:56 -0400 Subject: [PATCH] run restagePointerFiles in adjustedBranchRefreshFull Avoid failure to update adjusted branch --unlock-present after git-annex drop when annex.adjustedbranchrefresh=1 At higher values, it did flush the queue, which ran restagePointerFiles. But at 1, adjustedBranchRefreshFull gets added to the queue, and while restagePointerFiles is also in the queue, it runs after that. Sponsored-by: Brock Spratlen on Patreon --- Annex/AdjustedBranch.hs | 19 ++++----- CHANGELOG | 2 + ..._08b3eafdabe5f60ec2206584dff5d230._comment | 2 + ..._a947f8afde3d7f63fd33b0b7e5998e43._comment | 42 +++++++++++++++++++ ..._c8ce6c9fc35fa6ad5165ecf9a3592c9d._comment | 23 ++++++++++ ..._f296d4870a6fdef5c57bc8bb1a1e0474._comment | 11 +++++ 6 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_2_a947f8afde3d7f63fd33b0b7e5998e43._comment create mode 100644 doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_3_c8ce6c9fc35fa6ad5165ecf9a3592c9d._comment create mode 100644 doc/forum/How_to_recover_from_failed_branch_updates__63__/comment_1_f296d4870a6fdef5c57bc8bb1a1e0474._comment diff --git a/Annex/AdjustedBranch.hs b/Annex/AdjustedBranch.hs index 1907157e72..7ea5b234aa 100644 --- a/Annex/AdjustedBranch.hs +++ b/Annex/AdjustedBranch.hs @@ -45,7 +45,6 @@ import Annex.Common import Types.AdjustedBranch import Annex.AdjustedBranch.Name import qualified Annex -import qualified Annex.Queue import Git import Git.Types import qualified Git.Branch @@ -312,22 +311,20 @@ adjustedBranchRefresh _af a = do !s' = s { Annex.adjustedbranchrefreshcounter = c' } in pure (s', enough) - update adj origbranch = do - -- Flush the queue, to make any pending changes be written - -- out to disk. But mostly so any pointer files - -- restagePointerFile was called on get updated so git - -- checkout won't fall over. - Annex.Queue.flush - -- This is slow, it would be better to incrementally - -- adjust the AssociatedFile, and only call this once - -- at shutdown to handle cases where not all - -- AssociatedFiles are known. + -- This is slow, it would be better to incrementally + -- adjust the AssociatedFile, and only call this once + -- at shutdown to handle cases where not all + -- AssociatedFiles are known. + update adj origbranch = adjustedBranchRefreshFull adj origbranch {- Slow, but more dependable version of adjustedBranchRefresh that - does not rely on all AssociatedFiles being known. -} adjustedBranchRefreshFull :: Adjustment -> OrigBranch -> Annex () adjustedBranchRefreshFull adj origbranch = do + -- Restage pointer files so modifications to them due to get/drop + -- do not prevent checking out the updated adjusted branch. + restagePointerFiles =<< Annex.gitRepo let adjbranch = originalToAdjusted origbranch adj unlessM (updateAdjustedBranch adj adjbranch origbranch) $ warning $ unwords [ "Updating adjusted branch failed." ] diff --git a/CHANGELOG b/CHANGELOG index c901ffa1a7..33a27d6a02 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ git-annex (10.20230322) UNRELEASED; urgency=medium * sync: Fix parsing of gcrypt::rsync:// urls that use a relative path. + * Avoid failure to update adjusted branch --unlock-present after git-annex + drop when annex.adjustedbranchrefresh=1 -- Joey Hess Thu, 23 Mar 2023 15:04:41 -0400 diff --git a/doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_1_08b3eafdabe5f60ec2206584dff5d230._comment b/doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_1_08b3eafdabe5f60ec2206584dff5d230._comment index 3d43aeff32..1380567474 100644 --- a/doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_1_08b3eafdabe5f60ec2206584dff5d230._comment +++ b/doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_1_08b3eafdabe5f60ec2206584dff5d230._comment @@ -6,4 +6,6 @@ I assume this is a --hide-missing adjusted branch? Update: Oh, I see from a forum post that it's --unlock-present actually. + +What is the annex.adjustedbranchrefresh git config set to? """]] diff --git a/doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_2_a947f8afde3d7f63fd33b0b7e5998e43._comment b/doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_2_a947f8afde3d7f63fd33b0b7e5998e43._comment new file mode 100644 index 0000000000..f5ce8f9aea --- /dev/null +++ b/doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_2_a947f8afde3d7f63fd33b0b7e5998e43._comment @@ -0,0 +1,42 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 2""" + date="2023-03-23T19:35:33Z" + content=""" +I was able to reproduce something that looks similar to this without +needing to interrupt any command: + + joey@darkstar:~/tmp/bench>git clone a b + Cloning into 'b'... + done. + joey@darkstar:~/tmp/bench>cd b + joey@darkstar:~/tmp/bench/b>git config annex.adjustedbranchrefresh 1 + joey@darkstar:~/tmp/bench/b>git annex adjust --unlock-present + adjust + Switched to branch 'adjusted/master(unlockpresent)' + ok + joey@darkstar:~/tmp/bench/b#master(unlockpresent)>ls + foo@ + joey@darkstar:~/tmp/bench/b#master(unlockpresent)>git-annex get + get foo (from origin...) + ok + (recording state in git...) + joey@darkstar:~/tmp/bench/b#master(unlockpresent)>ls + foo + joey@darkstar:~/tmp/bench/b#master(unlockpresent)>git-annex drop + drop foo ok + error: Your local changes to the following files would be overwritten by checkout: + foo + Please commit your changes or stash them before you switch branches. + Aborting + + Updating adjusted branch failed. + (recording state in git...) + +And it was left in a similar detached head status: + + HEAD detached at 2aab85d + nothing to commit, working tree clean + +This seems be be a bug with the implementation of annex.adjustedbranchrefresh +"""]] diff --git a/doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_3_c8ce6c9fc35fa6ad5165ecf9a3592c9d._comment b/doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_3_c8ce6c9fc35fa6ad5165ecf9a3592c9d._comment new file mode 100644 index 0000000000..28215d4c79 --- /dev/null +++ b/doc/bugs/Failed_adjusted_branch_update_after_error_in_drop/comment_3_c8ce6c9fc35fa6ad5165ecf9a3592c9d._comment @@ -0,0 +1,23 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 3""" + date="2023-03-23T19:50:45Z" + content=""" +git-annex is what writes that detached HEAD, +in updateAdjustedBranch. And I've verified that when it fails like this, +git status shows the file is modified. But of course the modification is +only that the annex content has been replaced by an annex pointer. Running +`git add` on the file makes the modification status go away. + +And this only happens when annex.adjustedbranchrefresh=1. +At higher values, it calls Annex.Queue.flush, but at 1 it does not, and so +restagePointerFiles does not get called before adjustedBranchRefreshFull. +(Or at least may not, they're both running as cleanup actions and order is +not really defined.) + +I wonder if there are other situations where modifications can prevent +checkout of the updated adjusted branch? Eg, what if the user has made some +other modification to an annexed file? It seems wise for git-annex to +defend against it in depth, by making sure no crash can leave it in +detached head state. +"""]] diff --git a/doc/forum/How_to_recover_from_failed_branch_updates__63__/comment_1_f296d4870a6fdef5c57bc8bb1a1e0474._comment b/doc/forum/How_to_recover_from_failed_branch_updates__63__/comment_1_f296d4870a6fdef5c57bc8bb1a1e0474._comment new file mode 100644 index 0000000000..ed6f496d2d --- /dev/null +++ b/doc/forum/How_to_recover_from_failed_branch_updates__63__/comment_1_f296d4870a6fdef5c57bc8bb1a1e0474._comment @@ -0,0 +1,11 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 1""" + date="2023-03-23T19:30:12Z" + content=""" +You can just run "git checkout adjusted/master(unlockpresent)" +to switch back to that branch. + +It's fine to switch between adjusted and other branches, though the way git-annex +failed and left your head detached is certainly a bug. +"""]]