Bugfix: Make add ../ work.

The complication of check-attr returning absolute paths that have to be
converted back to relative paths..
This commit is contained in:
Joey Hess 2011-07-10 13:52:53 -04:00
parent 562fd41d6c
commit 7919de73af
4 changed files with 20 additions and 6 deletions

13
Git.hs
View file

@ -530,6 +530,7 @@ checkAttr repo attr files = do
-- directory. Convert to absolute, and then convert the filenames
-- in its output back to relative.
cwd <- getCurrentDirectory
let top = workTree repo
let absfiles = map (absPathFrom cwd) files
(_, fromh, toh) <- hPipeBoth "git" (toCommand params)
_ <- forkProcess $ do
@ -539,19 +540,21 @@ checkAttr repo attr files = do
exitSuccess
hClose toh
s <- hGetContents fromh
return $ map (topair $ cwd++"/") $ lines s
return $ map (topair cwd top) $ lines s
where
params = gitCommandLine repo [Param "check-attr", Param attr, Params "-z --stdin"]
topair cwd l = (relfile, value)
topair cwd top l = (relfile, value)
where
relfile
| startswith cwd file = drop (length cwd) file
| otherwise = file
relfile
| startswith cwd' file = drop (length cwd') file
| otherwise = relPathDirToFile top' file
file = decodeGitFile $ join sep $ take end bits
value = bits !! end
end = length bits - 1
bits = split sep l
sep = ": " ++ attr ++ ": "
cwd' = cwd ++ "/"
top' = top ++ "/"
{- Some git commands output encoded filenames. Decode that (annoyingly
- complex) encoding. -}

1
debian/changelog vendored
View file

@ -1,6 +1,7 @@
git-annex (3.20110708) UNRELEASED; urgency=low
* add: Be even more robust to avoid ever leaving the file seemingly deleted.
* Bugfix: Make add ../ work.
-- Joey Hess <joeyh@debian.org> Thu, 07 Jul 2011 21:28:49 -0400

View file

@ -11,3 +11,5 @@ error: Invalid path '.git/annex/objects/Jx/...
...
Then it seems it is enough to 'git add ../d/f' to complete the operation.
> Thanks for reporting, [[fixed|done]] --[[Joey]]

10
test.hs
View file

@ -108,7 +108,7 @@ test_init = "git-annex init" ~: TestCase $ innewrepo $ do
reponame = "test repo"
test_add :: Test
test_add = "git-annex add" ~: TestList [basic, sha1dup]
test_add = "git-annex add" ~: TestList [basic, sha1dup, subdirs]
where
-- this test case runs in the main repo, to set up a basic
-- annexed file that later tests will use
@ -129,6 +129,14 @@ test_add = "git-annex add" ~: TestList [basic, sha1dup]
git_annex "add" ["-q", sha1annexedfiledup, "--backend=SHA1"] @? "add of second file with same SHA1 failed"
annexed_present sha1annexedfiledup
annexed_present sha1annexedfile
subdirs = TestCase $ intmpclonerepo $ do
createDirectory "dir"
writeFile "dir/foo" $ content annexedfile
git_annex "add" ["-q", "dir"] @? "add of subdir failed"
createDirectory "dir2"
writeFile "dir2/foo" $ content annexedfile
changeWorkingDirectory "dir"
git_annex "add" ["-q", "../dir2"] @? "add of ../subdir failed"
test_setkey :: Test
test_setkey = "git-annex setkey/fromkey" ~: TestCase $ inmainrepo $ do