summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-09-22 12:59:56 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-09-22 13:00:18 -0400
commitf5c11a1acc4ded0ffcf0f9e6cf7c316750d61ee7 (patch)
treef03531a1db9953d8ea114f9d58e8961b0d893cd3
parent8bca37646e326a8409a2aa8d0c7e9001663f6050 (diff)
Improve robustness of direct mode merge, avoiding a crash if the index file is missing.
I couldn't find a good way to make an *empty* index file (zero byte file won't do), so I punted and just don't make index.lock when there's no index yet. This means some other git process could race and write an index file at the same time as the merge is ongoing, in theory. Only happens in new repos though.
-rw-r--r--Annex/Direct.hs8
-rw-r--r--debian/changelog3
-rw-r--r--doc/bugs/Assistant:_synchronisation_between_two_regular_repositories_hangs_.mdwn2
-rw-r--r--doc/bugs/Assistant:_synchronisation_between_two_regular_repositories_hangs_/comment_3_db50cbdc302480c4b1fe0f364aa769d9._comment19
4 files changed, 29 insertions, 3 deletions
diff --git a/Annex/Direct.hs b/Annex/Direct.hs
index d88dc43fb..35a5b5013 100644
--- a/Annex/Direct.hs
+++ b/Annex/Direct.hs
@@ -153,7 +153,7 @@ addDirect file cache = do
-
- A lock file is used to avoid races with any other caller of mergeDirect.
-
- - To avoid other git processes from making change to the index while our
+ - To avoid other git processes from making changes to the index while our
- merge is in progress, the index lock file is used as the temp index
- file. This is the same as what git does when updating the index
- normally.
@@ -162,7 +162,8 @@ mergeDirect :: Maybe Git.Ref -> Maybe Git.Ref -> Git.Branch -> Annex Bool -> Git
mergeDirect startbranch oldref branch resolvemerge commitmode = exclusively $ do
reali <- liftIO . absPath =<< fromRepo indexFile
tmpi <- liftIO . absPath =<< fromRepo indexFileLock
- liftIO $ copyFile reali tmpi
+ liftIO $ whenM (doesFileExist reali) $
+ copyFile reali tmpi
d <- fromRepo gitAnnexMergeDir
liftIO $ do
@@ -178,7 +179,8 @@ mergeDirect startbranch oldref branch resolvemerge commitmode = exclusively $ do
mergeDirectCleanup d (fromMaybe Git.Sha.emptyTree oldref)
mergeDirectCommit merged startbranch branch commitmode
- liftIO $ rename tmpi reali
+ liftIO $ whenM (doesFileExist tmpi) $
+ rename tmpi reali
return r
where
diff --git a/debian/changelog b/debian/changelog
index 17fd70a0f..5ebbfcd18 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -10,6 +10,9 @@ git-annex (5.20150917) UNRELEASED; urgency=medium
to use Google's NearLine storage.
* Improve ~/.ssh/config modification code to not add trailing spaces
to lines it cannot parse.
+ * Fix a crash at direct mode merge time when .git/index doesn't exist
+ yet. Triggered by eg, git-annex sync --no-commit in a fresh clone of
+ a repository.
-- Joey Hess <id@joeyh.name> Wed, 16 Sep 2015 12:23:33 -0400
diff --git a/doc/bugs/Assistant:_synchronisation_between_two_regular_repositories_hangs_.mdwn b/doc/bugs/Assistant:_synchronisation_between_two_regular_repositories_hangs_.mdwn
index 8e6c4f468..cc63ac138 100644
--- a/doc/bugs/Assistant:_synchronisation_between_two_regular_repositories_hangs_.mdwn
+++ b/doc/bugs/Assistant:_synchronisation_between_two_regular_repositories_hangs_.mdwn
@@ -26,3 +26,5 @@ Also note that the second repository is on a FAT32 usb stick
# End of transcript or log.
"""]]
+
+> [[fixed|done]] --[[Joey]]
diff --git a/doc/bugs/Assistant:_synchronisation_between_two_regular_repositories_hangs_/comment_3_db50cbdc302480c4b1fe0f364aa769d9._comment b/doc/bugs/Assistant:_synchronisation_between_two_regular_repositories_hangs_/comment_3_db50cbdc302480c4b1fe0f364aa769d9._comment
new file mode 100644
index 000000000..515ad0b7b
--- /dev/null
+++ b/doc/bugs/Assistant:_synchronisation_between_two_regular_repositories_hangs_/comment_3_db50cbdc302480c4b1fe0f364aa769d9._comment
@@ -0,0 +1,19 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 3"""
+ date="2015-09-22T16:25:15Z"
+ content="""
+Ok, that seems clear enough, and there's only 1 place where git-annex
+copies .git/index; in `mergeDirect`. Indeed, if .git/index doesn't exist
+yet when that is called, it'll crash. And, a freshly created git repo
+starts off without a .git/index until changes start to be staged.
+
+However, I can't reproduce the crash with a current version of git-annex,
+and this bug report is about a version nearly a year old now. AFAICS,
+the sync (or the assistant) will make a commit before merging, and that
+commit results in the index file being created, as a side effect.
+Also, I can't see anything that VFAT could have to do with this.
+
+Hmm, I did manage to reproduce the crash using the new --no-commit flag to
+git-annex sync. Will fix on that basis.
+"""]]