From 70b71bf6607226e55a9e97af1a5c3f58f154749d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Aug 2019 14:12:46 -0400 Subject: [PATCH] have init --version fail when repo is already initialized with other version init: When the repo is already initialized, and --version requests a different version, error out rather than silently not changing the version. --- CHANGELOG | 3 +++ Command/Init.hs | 6 ++++++ .../windows_test_suite_fails_to_init_direct_mode_repo.mdwn | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index c26e0eca4d..40a36e7e66 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,9 @@ git-annex (7.20190731) UNRELEASED; urgency=medium since it needs 64 bit git now. * Build with silently-1.2.5.1 on Windows; the old one used "NUL" which is not supported with recent versions of ghc. + * init: When the repo is already initialized, and --version requests a + different version, error out rather than silently not changing the + version. -- Joey Hess Thu, 01 Aug 2019 00:11:56 -0400 diff --git a/Command/Init.hs b/Command/Init.hs index e8d80a3533..db6cb14fb9 100644 --- a/Command/Init.hs +++ b/Command/Init.hs @@ -51,6 +51,12 @@ start os = starting "init" (ActionItemOther (Just $ initDesc os)) $ perform :: InitOptions -> CommandPerform perform os = do + case initVersion os of + Nothing -> noop + Just wantversion -> getVersion >>= \case + Just v | v /= wantversion -> + giveup $ "This repository is already a initialized with version " ++ show (fromRepoVersion v) ++ ", not changing to requested version." + _ -> noop initialize (if null (initDesc os) then Nothing else Just (initDesc os)) (initVersion os) diff --git a/doc/bugs/windows_test_suite_fails_to_init_direct_mode_repo.mdwn b/doc/bugs/windows_test_suite_fails_to_init_direct_mode_repo.mdwn index d5c1231052..452d645fba 100644 --- a/doc/bugs/windows_test_suite_fails_to_init_direct_mode_repo.mdwn +++ b/doc/bugs/windows_test_suite_fails_to_init_direct_mode_repo.mdwn @@ -9,3 +9,9 @@ I have not managed to reproduce this outside of the test suite. I wonder if perhaps the environment variable that the test suite sets to communicate with itself is not working on Windows, which sometimes has gotchas around environment variables. --[[Joey]] + +Hmm, I reordered the direct mode tests to come first, and the failure went +away. Think that .t/repo gets reused, and being already a v7 repo, git annex +init --version=7 silently did not change it. (Made that error out.) +So the test suite should use different paths for the base repo in each test +pass.