When adding files to an adjusted branch set up by --unlock-present, add them unlocked...
authorJoey Hess <joeyh@joeyh.name>
Mon, 25 Jan 2021 17:55:01 +0000 (13:55 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 28 Jan 2021 16:47:46 +0000 (12:47 -0400)
Missed this when implementing it because of the default case catching
the new constructor. So, removed that default case to make sure
future types of adjusted branches don't make the same mistake.

Complicated by git-annex addurl --fast which adds the file whose content
is not present, so it needs to stay unlocked when on such a branch.

This commit was sponsored by Brock Spratlen on Patreon.

Annex/Ingest.hs
CHANGELOG
Command/Add.hs
Command/Import.hs
doc/bugs/adjustedbranchrefresh_ignored_by_git_annex_add.mdwn
doc/bugs/adjustedbranchrefresh_ignored_by_git_annex_add/comment_2_da0e37920a879bdb9df3fef87d52a10c._comment [new file with mode: 0644]

index a23c193769913637fba48347f9d1900f1f75c1be..66e1d71c6908312ceb2b2191eb9cd842434fc65d 100644 (file)
@@ -329,18 +329,24 @@ gitAddParams (CheckGitIgnore False) = return [Param "-f"]
 
 {- Whether a file should be added unlocked or not. Default is to not,
  - unless symlinks are not supported. annex.addunlocked can override that.
- - Also, when in an adjusted unlocked branch, always add files unlocked.
+ - Also, when in an adjusted branch that unlocked files, always add files
+ - unlocked.
  -}
-addUnlocked :: AddUnlockedMatcher -> MatchInfo -> Annex Bool
-addUnlocked matcher mi =
+addUnlocked :: AddUnlockedMatcher -> MatchInfo -> Bool -> Annex Bool
+addUnlocked matcher mi contentpresent =
        ((not . coreSymlinks <$> Annex.getGitConfig) <||>
         (checkAddUnlockedMatcher matcher mi) <||>
-        (maybe False isadjustedunlocked . snd <$> getCurrentBranch)
+        (maybe False go . snd <$> getCurrentBranch)
        )
   where
-       isadjustedunlocked (LinkAdjustment UnlockAdjustment) = True
-       isadjustedunlocked (PresenceAdjustment _ (Just UnlockAdjustment)) = True
-       isadjustedunlocked _ = False
+       go (LinkAdjustment UnlockAdjustment) = True
+       go (LinkAdjustment LockAdjustment) = False
+       go (LinkAdjustment FixAdjustment) = False
+       go (LinkAdjustment UnFixAdjustment) = False
+       go (PresenceAdjustment _ (Just la)) = go (LinkAdjustment la)
+       go (PresenceAdjustment _ Nothing) = False
+       go (LinkPresentAdjustment UnlockPresentAdjustment) = contentpresent
+       go (LinkPresentAdjustment LockPresentAdjustment) = False
 
 {- Adds a file to the work tree for the key, and stages it in the index.
  - The content of the key may be provided in a temp file, which will be
@@ -350,7 +356,7 @@ addUnlocked matcher mi =
  - When the content of the key is not accepted into the annex, returns False.
  -}
 addAnnexedFile :: CheckGitIgnore -> AddUnlockedMatcher -> RawFilePath -> Key -> Maybe RawFilePath -> Annex Bool
-addAnnexedFile ci matcher file key mtmp = ifM (addUnlocked matcher mi)
+addAnnexedFile ci matcher file key mtmp = ifM (addUnlocked matcher mi (isJust mtmp))
        ( do
                mode <- maybe
                        (pure Nothing)
index b5f92b2c3a5c686f239c508b59b01ee8204da7bd..a325d9067134aaa47c09b38f99f5b5a16e163645 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,8 @@ git-annex (8.20210128) UNRELEASED; urgency=medium
   * Fix a reversion that made import of a tree from a special remote
     result in a merge that deleted files that were not preferred content
     of that special remote.
+  * When adding files to an adjusted branch set up by --unlock-present,
+    add them unlocked, not locked.
 
  -- Joey Hess <id@joeyh.name>  Thu, 28 Jan 2021 12:34:32 -0400
 
index 0835f0946ebd7014f5f379d5057ee2a39858058a..73e355b4212635249c65d6c0f5f8085c706d844d 100644 (file)
@@ -172,6 +172,7 @@ perform :: AddOptions -> RawFilePath -> AddUnlockedMatcher -> CommandPerform
 perform o file addunlockedmatcher = withOtherTmp $ \tmpdir -> do
        lockingfile <- not <$> addUnlocked addunlockedmatcher
                (MatchingFile (FileInfo (Just file) file Nothing))
+               True
        let cfg = LockDownConfig
                { lockingFile = lockingfile
                , hardlinkFileTmpDir = Just tmpdir
index cbd344f0d9359850ed908127299c22e4b5b18ca6..d1957e05821278ed7f089643f43c97019f192d58 100644 (file)
@@ -243,7 +243,7 @@ startLocal o addunlockedmatcher largematcher mode (srcfile, destfile) =
                        , matchFile = destfile
                        , matchKey = Nothing
                        }
-               lockingfile <- not <$> addUnlocked addunlockedmatcher mi
+               lockingfile <- not <$> addUnlocked addunlockedmatcher mi True
                -- Minimal lock down with no hard linking so nothing
                -- has to be done to clean up from it.
                let cfg = LockDownConfig
index 025cf887b60e2c438a2a837046264957117f06c1..756fd0291d399e0886363f40ce8755f8a264f4d6 100644 (file)
@@ -50,3 +50,5 @@ echo "## after sync --content"
 stat -c "%n: %F" a b c d # ibid
 '
 ```
+
+> [[fixed|done]] --[[Joey]]
diff --git a/doc/bugs/adjustedbranchrefresh_ignored_by_git_annex_add/comment_2_da0e37920a879bdb9df3fef87d52a10c._comment b/doc/bugs/adjustedbranchrefresh_ignored_by_git_annex_add/comment_2_da0e37920a879bdb9df3fef87d52a10c._comment
new file mode 100644 (file)
index 0000000..3437e9c
--- /dev/null
@@ -0,0 +1,8 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 2"""
+ date="2021-01-25T17:46:03Z"
+ content="""
+Oh, git-annex add already adds it unlocked in an adjusted unlocked branch,
+so that just needs to be done for this new type of branch too.
+"""]]