From 94029995fa2754ed8c22f23cf7bf0157edeeef7a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 19 Aug 2022 12:49:17 -0400 Subject: [PATCH] fix git-annex add regression on deleted file Fix a regression in 10.20220624 that caused git-annex add to crash when there was an unstaged deletion. Sponsored-by: Dartmouth College's Datalad project --- CHANGELOG | 2 ++ Command/Add.hs | 35 ++++++++++--------- Test.hs | 2 ++ ...__39__add_.__39___if_file_was_renamed.mdwn | 2 ++ ..._bceb84ed261a160c4041c146372fc551._comment | 11 ++++++ 5 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 doc/bugs/regression__58___fails_to___39__add_.__39___if_file_was_renamed/comment_2_bceb84ed261a160c4041c146372fc551._comment diff --git a/CHANGELOG b/CHANGELOG index e826f3db72..b3d274a8cc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,8 @@ git-annex (10.20220725) UNRELEASED; urgency=medium * Use curl when annex.security.allowed-url-schemes includes an url scheme not supported by git-annex internally, as long as annex.security.allowed-ip-addresses is configured to allow using curl. + * Fix a regression in 10.20220624 that caused git-annex add to crash + when there was an unstaged deletion. -- Joey Hess Mon, 25 Jul 2022 15:35:45 -0400 diff --git a/Command/Add.hs b/Command/Add.hs index cf3e5f5534..5010fef0e7 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -88,19 +88,17 @@ seek o = startConcurrency commandStages $ do addunlockedmatcher <- addUnlockedMatcher annexdotfiles <- getGitConfigVal annexDotFiles let gofile includingsmall (si, file) = case largeFilesOverride o of - Nothing -> do - s <- liftIO $ R.getSymbolicLinkStatus file - ifM (pure (annexdotfiles || not (dotfile file)) - <&&> (checkFileMatcher largematcher file - <||> Annex.getRead Annex.force)) - ( start dr si file addunlockedmatcher - , if includingsmall - then ifM (annexAddSmallFiles <$> Annex.getGitConfig) - ( startSmall dr si file s - , stop - ) - else stop - ) + Nothing -> ifM (pure (annexdotfiles || not (dotfile file)) + <&&> (checkFileMatcher largematcher file + <||> Annex.getRead Annex.force)) + ( start dr si file addunlockedmatcher + , if includingsmall + then ifM (annexAddSmallFiles <$> Annex.getGitConfig) + ( startSmall dr si file + , stop + ) + else stop + ) Just True -> start dr si file addunlockedmatcher Just False -> startSmallOverridden dr si file case batchOption o of @@ -132,10 +130,13 @@ seek o = startConcurrency commandStages $ do dr = dryRunOption o {- Pass file off to git-add. -} -startSmall :: DryRun -> SeekInput -> RawFilePath -> FileStatus -> CommandStart -startSmall dr si file s = - starting "add" (ActionItemTreeFile file) si $ - addSmall dr file s +startSmall :: DryRun -> SeekInput -> RawFilePath -> CommandStart +startSmall dr si file = + liftIO (catchMaybeIO $ R.getSymbolicLinkStatus file) >>= \case + Just s -> + starting "add" (ActionItemTreeFile file) si $ + addSmall dr file s + Nothing -> stop addSmall :: DryRun -> RawFilePath -> FileStatus -> CommandPerform addSmall dr file s = do diff --git a/Test.hs b/Test.hs index 2d32f34d55..5ec5d8d1de 100644 --- a/Test.hs +++ b/Test.hs @@ -399,6 +399,8 @@ test_add_moved = intmpclonerepo $ do createDirectory subdir Utility.MoveFile.moveFile (toRawFilePath annexedfile) (toRawFilePath subfile) git_annex "add" [subdir] "add of moved annexed file" + git "mv" [sha1annexedfile, sha1annexedfile ++ ".renamed"] "git mv" + git_annex "add" [] "add does not fail on deleted file after move" where subdir = "subdir" subfile = subdir "file" diff --git a/doc/bugs/regression__58___fails_to___39__add_.__39___if_file_was_renamed.mdwn b/doc/bugs/regression__58___fails_to___39__add_.__39___if_file_was_renamed.mdwn index facdb2014d..985e4a958e 100644 --- a/doc/bugs/regression__58___fails_to___39__add_.__39___if_file_was_renamed.mdwn +++ b/doc/bugs/regression__58___fails_to___39__add_.__39___if_file_was_renamed.mdwn @@ -47,3 +47,5 @@ I am a little surprised that it is only datalad-crawler, not datalad or git-anne [[!meta author=yoh]] [[!tag projects/datalad]] + +> [[fixed|done]] --[[Joey]] diff --git a/doc/bugs/regression__58___fails_to___39__add_.__39___if_file_was_renamed/comment_2_bceb84ed261a160c4041c146372fc551._comment b/doc/bugs/regression__58___fails_to___39__add_.__39___if_file_was_renamed/comment_2_bceb84ed261a160c4041c146372fc551._comment new file mode 100644 index 0000000000..e2ca79d78b --- /dev/null +++ b/doc/bugs/regression__58___fails_to___39__add_.__39___if_file_was_renamed/comment_2_bceb84ed261a160c4041c146372fc551._comment @@ -0,0 +1,11 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 2""" + date="2022-08-19T16:39:11Z" + content=""" +Fixed this. + +The test suite does test add of renamed files, but just barely missed it +since it ran git-annex add of the destination file only. +Added a test case for this. +"""]] -- 2.30.2