From 876d5b6c6fed7d540767783eb3d14469f41bd1c2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 13 Nov 2024 13:42:52 -0400 Subject: [PATCH] add: Consistently treat files in a dotdir as dotfiles, even when ran inside that dotdir Assistant and smudge also updated. This does add a small amount of extra work, getting the TopFilePath. Not enough to be concerned by. Also improve documentation to make clear that files inside dotdirs are treated as dotfiles. Sponsored-by: Eve on Patreon --- Assistant/Threads/Committer.hs | 19 +++++++++------ CHANGELOG | 2 ++ Command/Add.hs | 24 ++++++++++--------- Command/Smudge.hs | 14 ++++++----- ...y_treats_files_in_dotdirs_as_dotfiles.mdwn | 4 ++++ ..._c9206d1a0c74149df970d44025160d89._comment | 21 ++++++++++++++++ ..._eb82a22ffe512bf0d6f2e7841ce022f0._comment | 9 +++++++ doc/git-annex-add.mdwn | 8 +++---- doc/git-annex-config.mdwn | 15 ++++++------ doc/git-annex.mdwn | 13 +++++----- 10 files changed, 88 insertions(+), 41 deletions(-) create mode 100644 doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles/comment_5_c9206d1a0c74149df970d44025160d89._comment create mode 100644 doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles/comment_6_eb82a22ffe512bf0d6f2e7841ce022f0._comment diff --git a/Assistant/Threads/Committer.hs b/Assistant/Threads/Committer.hs index 2f7e03c43c..85692767e7 100644 --- a/Assistant/Threads/Committer.hs +++ b/Assistant/Threads/Committer.hs @@ -45,6 +45,7 @@ import qualified Git.Branch import Utility.Tuple import Utility.Metered import qualified Utility.RawFilePath as R +import Git.FilePath import Data.Time.Clock import qualified Data.Set as S @@ -319,15 +320,19 @@ handleAdds lockdowndir havelsof largefilematcher annexdotfiles delayadd cs = ret (LinkChange (Just key)) checksmall change - | not annexdotfiles && dotfile f = - return (Right change) - | otherwise = - ifM (liftAnnex $ checkFileMatcher NoLiveUpdate largefilematcher f) - ( return (Left change) - , return (Right change) - ) + | not annexdotfiles = do + topfile <- liftAnnex $ + getTopFilePath <$> inRepo (toTopFilePath f) + if dotfile topfile + then return (Right change) + else checkmatcher + | otherwise = checkmatcher where f = toRawFilePath (changeFile change) + checkmatcher = ifM (liftAnnex $ checkFileMatcher NoLiveUpdate largefilematcher f) + ( return (Left change) + , return (Right change) + ) addsmall [] = noop addsmall toadd = liftAnnex $ void $ tryIO $ diff --git a/CHANGELOG b/CHANGELOG index 1fda614aa9..91d3ca294d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,8 @@ git-annex (10.20241032) UNRELEASED; urgency=medium * git-remote-annex: Fix a reversion introduced in version 10.20241031 that broke cloning from a special remote. * vpop: Only update state after successful checkout. + * add: Consistently treat files in a dotdir as dotfiles, even + when ran inside that dotdir. -- Joey Hess Mon, 11 Nov 2024 12:26:00 -0400 diff --git a/Command/Add.hs b/Command/Add.hs index f42008f18b..ff60cd4370 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -94,17 +94,19 @@ seek' o = do addunlockedmatcher <- addUnlockedMatcher annexdotfiles <- getGitConfigVal annexDotFiles let gofile includingsmall (si, file) = case largeFilesOverride o of - Nothing -> ifM (pure (annexdotfiles || not (dotfile file)) - <&&> (checkFileMatcher NoLiveUpdate 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 - ) + Nothing -> do + topfile <- getTopFilePath <$> inRepo (toTopFilePath file) + ifM (pure (annexdotfiles || not (dotfile topfile)) + <&&> (checkFileMatcher NoLiveUpdate 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 diff --git a/Command/Smudge.hs b/Command/Smudge.hs index 57ab8ff8dd..89f637dd52 100644 --- a/Command/Smudge.hs +++ b/Command/Smudge.hs @@ -239,12 +239,14 @@ shouldAnnex file indexmeta moldkey = do , checkunchanged checkwasannexed ) where - checkmatcher d - | dotfile file = ifM (getGitConfigVal annexDotFiles) - ( go - , d - ) - | otherwise = go + checkmatcher d = do + topfile <- getTopFilePath <$> inRepo (toTopFilePath file) + if dotfile topfile + then ifM (getGitConfigVal annexDotFiles) + ( go + , d + ) + else go where go = do matcher <- largeFilesMatcher diff --git a/doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles.mdwn b/doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles.mdwn index 353fbdd1dd..ff54c26e7f 100644 --- a/doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles.mdwn +++ b/doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles.mdwn @@ -101,3 +101,7 @@ go-to solution for “want something versioned, but can't store the contents themselves (too big, too sensitive, etc.)?”. Furthermore, git-annex documentation in general is excellent. But that is also why I'm stumped that the manual is so silent on this point. + +> [[fixed|done]] by resolving inconsistent behavior. Also improved +> documentation to be clear that dot directories are treated same as +> dotfiles. diff --git a/doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles/comment_5_c9206d1a0c74149df970d44025160d89._comment b/doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles/comment_5_c9206d1a0c74149df970d44025160d89._comment new file mode 100644 index 0000000000..b52a2b54e1 --- /dev/null +++ b/doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles/comment_5_c9206d1a0c74149df970d44025160d89._comment @@ -0,0 +1,21 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 5""" + date="2024-11-13T17:04:59Z" + content=""" +> Why can't git-annex just handle the .git folder differently and for all others just annex or not as set in the largefile rules? + +Because creating a .gitignore followed by `git-annex add` would then blow the +user's foot off. And this would be a very common foot-shooting opportunity, +and .gitignore is only the perhaps most common trigger for it. + +Files in dot directories are generally less common, outside of course of +.git and $HOME. Which is the only reason I'm willing to consider changing +the dotfiles handling to not include those. + +But, .config/ seems to me to perfectly match what dotfiles *are*, which is +files that are configuration that are named with a name starting with a +dot in order to keep them from cluttering up `ls`. Just because in your use +case you don't want to check those into git as dotfiles does not seem like +a good argument for git-annex to not treat them as dotfiles by default. +"""]] diff --git a/doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles/comment_6_eb82a22ffe512bf0d6f2e7841ce022f0._comment b/doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles/comment_6_eb82a22ffe512bf0d6f2e7841ce022f0._comment new file mode 100644 index 0000000000..985237c16d --- /dev/null +++ b/doc/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles/comment_6_eb82a22ffe512bf0d6f2e7841ce022f0._comment @@ -0,0 +1,9 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 6""" + date="2024-11-13T17:14:47Z" + content=""" +Revisiting this, it seems best to fix the inconsistent behavior by +having git-annex get the path to the file relative to the top of the git +repository, and check if there's a dot directory in the path. +"""]] diff --git a/doc/git-annex-add.mdwn b/doc/git-annex-add.mdwn index a4b6d95208..6313008e06 100644 --- a/doc/git-annex-add.mdwn +++ b/doc/git-annex-add.mdwn @@ -18,10 +18,10 @@ git has been configured to ignore will be silently skipped. If annex.largefiles is configured (in git config, gitattributes, or git-annex config), and does not match a file, `git annex add` will behave the same as `git add` and add the non-large file directly to the git -repository, instead of to the annex. (By default dotfiles are assumed to -not be large, and are added directly to git, but annex.dotfiles can be -configured to annex those too.) See the git-annex manpage for documentation -of these and other configuration settings. +repository, instead of to the annex. (By default dotfiles and the contents +of dotdirs) are assumed to not be large, and are added directly to git, but +annex.dotfiles can be configured to annex those too.) See the git-annex +manpage for documentation of these and other configuration settings. By default, large files are added to the annex in locked form, which prevents further modification of their content until diff --git a/doc/git-annex-config.mdwn b/doc/git-annex-config.mdwn index f52f4a2a4a..a4a1b4ddac 100644 --- a/doc/git-annex-config.mdwn +++ b/doc/git-annex-config.mdwn @@ -81,8 +81,8 @@ looks for these. This configures the behavior of both git-annex and git when adding files to the repository. By default, `git-annex add` adds all files - to the annex (except dotfiles), and `git add` adds files to git - (unless they were added to the annex previously). + to the annex (except dotfiles and files in dotdirs), and + `git add` adds files to git (unless they were added to the annex previously). When annex.largefiles is configured, both `git annex add` and `git add` will add matching large files to the annex, and the other files to git. @@ -95,11 +95,12 @@ looks for these. attributes in `.gitattributes` files, or by `git config`. * `annex.dotfiles` - - Normally, dotfiles are assumed to be files like .gitignore, - whose content should always be part of the git repository, so - they will not be added to the annex. Setting annex.dotfiles to true - makes dotfiles be added to the annex the same as any other file. + + Normally, dotfiles and files inside dotdirs are assumed to be + configuration files like .gitignore, whose content should always + be part of the git repository, so they will not be added to the annex. + Setting annex.dotfiles to true makes these files be added to the + annex the same as any other file. This sets a default, which can be overridden by annex.dotfiles in `git config`. diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index 73ddb2ac97..e0cae8c02b 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -974,8 +974,8 @@ repository, using [[git-annex-config]]. See its man page for a list.) This configures the behavior of both git-annex and git when adding files to the repository. By default, `git-annex add` adds all files - to the annex (except dotfiles), and `git add` adds files to git - (unless they were added to the annex previously). + to the annex (except dotfiles and files in dotdirs), and `git add` + adds files to git (unless they were added to the annex previously). When annex.largefiles is configured, both `git annex add` and `git add` will add matching large files to the annex, and the other files to git. @@ -986,10 +986,11 @@ repository, using [[git-annex-config]]. See its man page for a list.) * `annex.dotfiles` - Normally, dotfiles are assumed to be files like .gitignore, - whose content should always be part of the git repository, so - they will not be added to the annex. Setting annex.dotfiles to true - makes dotfiles be added to the annex the same as any other file. + Normally, dotfiles and files inside dotdirs are assumed to be + configuration files like .gitignore, whose content should always + be part of the git repository, so they will not be added to the annex. + Setting annex.dotfiles to true makes these files be added to the + annex the same as any other file. To annex only some dotfiles, set this and configure annex.largefiles to match the ones you want. For example, to match only dotfiles ending -- 2.30.2