When adding files to an adjusted branch set up by --unlock-present, add them unlocked, not locked

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.
This commit is contained in:
Joey Hess 2021-01-25 13:55:01 -04:00
parent db1e6c0625
commit 6f78497572
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 28 additions and 9 deletions

View file

@ -329,18 +329,24 @@ gitAddParams (CheckGitIgnore False) = return [Param "-f"]
{- Whether a file should be added unlocked or not. Default is to not, {- Whether a file should be added unlocked or not. Default is to not,
- unless symlinks are not supported. annex.addunlocked can override that. - 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 :: AddUnlockedMatcher -> MatchInfo -> Bool -> Annex Bool
addUnlocked matcher mi = addUnlocked matcher mi contentpresent =
((not . coreSymlinks <$> Annex.getGitConfig) <||> ((not . coreSymlinks <$> Annex.getGitConfig) <||>
(checkAddUnlockedMatcher matcher mi) <||> (checkAddUnlockedMatcher matcher mi) <||>
(maybe False isadjustedunlocked . snd <$> getCurrentBranch) (maybe False go . snd <$> getCurrentBranch)
) )
where where
isadjustedunlocked (LinkAdjustment UnlockAdjustment) = True go (LinkAdjustment UnlockAdjustment) = True
isadjustedunlocked (PresenceAdjustment _ (Just UnlockAdjustment)) = True go (LinkAdjustment LockAdjustment) = False
isadjustedunlocked _ = 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. {- 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 - 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. - When the content of the key is not accepted into the annex, returns False.
-} -}
addAnnexedFile :: CheckGitIgnore -> AddUnlockedMatcher -> RawFilePath -> Key -> Maybe RawFilePath -> Annex Bool 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 ( do
mode <- maybe mode <- maybe
(pure Nothing) (pure Nothing)

View file

@ -3,6 +3,8 @@ git-annex (8.20210128) UNRELEASED; urgency=medium
* Fix a reversion that made import of a tree from a special remote * 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 result in a merge that deleted files that were not preferred content
of that special remote. 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 -- Joey Hess <id@joeyh.name> Thu, 28 Jan 2021 12:34:32 -0400

View file

@ -172,6 +172,7 @@ perform :: AddOptions -> RawFilePath -> AddUnlockedMatcher -> CommandPerform
perform o file addunlockedmatcher = withOtherTmp $ \tmpdir -> do perform o file addunlockedmatcher = withOtherTmp $ \tmpdir -> do
lockingfile <- not <$> addUnlocked addunlockedmatcher lockingfile <- not <$> addUnlocked addunlockedmatcher
(MatchingFile (FileInfo (Just file) file Nothing)) (MatchingFile (FileInfo (Just file) file Nothing))
True
let cfg = LockDownConfig let cfg = LockDownConfig
{ lockingFile = lockingfile { lockingFile = lockingfile
, hardlinkFileTmpDir = Just tmpdir , hardlinkFileTmpDir = Just tmpdir

View file

@ -243,7 +243,7 @@ startLocal o addunlockedmatcher largematcher mode (srcfile, destfile) =
, matchFile = destfile , matchFile = destfile
, matchKey = Nothing , matchKey = Nothing
} }
lockingfile <- not <$> addUnlocked addunlockedmatcher mi lockingfile <- not <$> addUnlocked addunlockedmatcher mi True
-- Minimal lock down with no hard linking so nothing -- Minimal lock down with no hard linking so nothing
-- has to be done to clean up from it. -- has to be done to clean up from it.
let cfg = LockDownConfig let cfg = LockDownConfig

View file

@ -50,3 +50,5 @@ echo "## after sync --content"
stat -c "%n: %F" a b c d # ibid stat -c "%n: %F" a b c d # ibid
' '
``` ```
> [[fixed|done]] --[[Joey]]

View file

@ -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.
"""]]