Skip to content

Commit f639da3

Browse files
authored
Merge pull request #66 from apauley/include-path-fix
Fix incorrect paths in include files when given a relative base dir
2 parents 8bc61fb + 513089a commit f639da3

File tree

6 files changed

+51
-38
lines changed

6 files changed

+51
-38
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ install:
5353
- git clone --recurse-submodules https://github.com/apauley/hledger-flow-example.git $HOME/hledger-flow-example
5454

5555
script:
56-
- stack test --interleaved-output
5756
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then git checkout HEAD package.yaml; fi
5857
- hledger-flow --verbose --show-options import $HOME/hledger-flow-example
5958
- hledger-flow --verbose --show-options report $HOME/hledger-flow-example

ChangeLog.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Changelog for [hledger-flow](https://github.com/apauley/hledger-flow)
22

3+
## 0.12.3.1
4+
5+
Fixed a bug where:
6+
7+
Given:
8+
- A run of `hledger-flow import`
9+
10+
When:
11+
- specifying a relative import base directory
12+
- but specifically without any relative prefixes such as `./` or `../`
13+
14+
Then:
15+
- the account-level include files pointing to the real journal entries would have incorrect paths
16+
17+
https://github.com/apauley/hledger-flow/issues/65
18+
319
## 0.12.3
420

521
Add more reports:

package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: hledger-flow
2-
version: 0.12.3.0
2+
version: 0.12.3.1
33
synopsis: An hledger workflow focusing on automated statement import and classification.
44
category: Finance, Console
55
license: GPL-3

src/Hledger/Flow/Common.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,9 @@ determineBaseDir Nothing = pwd >>= determineBaseDir'
427427

428428
determineBaseDir' :: FilePath -> IO FilePath
429429
determineBaseDir' startDir = do
430-
ebd <- determineBaseDir'' startDir startDir
430+
currentDir <- pwd
431+
let absoluteStartDir = if relative startDir then collapse (currentDir </> startDir) else startDir
432+
ebd <- determineBaseDir'' absoluteStartDir absoluteStartDir
431433
case ebd of
432434
Right bd -> return bd
433435
Left t -> die t

stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# resolver: ./custom-snapshot.yaml
2020
# resolver: https://example.com/snapshots/2018-01-01.yaml
21-
resolver: nightly-2019-05-26
21+
resolver: nightly-2019-06-21
2222

2323
# User packages to be built.
2424
# Various formats can be used as shown in the example below.

test/Common/Integration.hs

+30-34
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Test.HUnit
77
import Turtle
88
import Prelude hiding (FilePath)
99
import qualified Data.List as List (sort)
10+
import qualified Data.Text as T
1011

1112
import TestHelpers
1213
import Hledger.Flow.Common
@@ -49,6 +50,23 @@ testDirOrPwd = TestCase (
4950
)
5051
)
5152

53+
assertSubDirsForDetermineBaseDir :: FilePath -> [FilePath] -> IO ()
54+
assertSubDirsForDetermineBaseDir expectedBaseDir importDirs = do
55+
_ <- sequence $ map (assertDetermineBaseDir expectedBaseDir) importDirs
56+
return ()
57+
58+
assertDetermineBaseDir :: FilePath -> FilePath -> IO ()
59+
assertDetermineBaseDir expectedBaseDir subDir = do
60+
initialPwd <- pwd
61+
bd1 <- determineBaseDir $ Just subDir
62+
cd subDir
63+
bd2 <- determineBaseDir Nothing
64+
bd3 <- determineBaseDir $ Just "."
65+
cd initialPwd
66+
let msg = format ("determineBaseDir searches from pwd upwards until it finds a dir containing 'import' - "%fp) subDir
67+
_ <- sequence $ map (assertEqual (T.unpack msg) expectedBaseDir) [bd1, bd2, bd3]
68+
return ()
69+
5270
testDetermineBaseDir :: Test
5371
testDetermineBaseDir = TestCase (
5472
sh (
@@ -63,51 +81,29 @@ testDetermineBaseDir = TestCase (
6381
bdUnrelated <- liftIO $ determineBaseDir'' unrelatedDir unrelatedDir
6482
liftIO $ assertEqual "determineBaseDir produces an error message when it cannot find a baseDir" (Left $ errorMessageBaseDir unrelatedDir) bdUnrelated
6583

66-
currentDir <- pwd
67-
let baseDir = forceTrailingSlash $ collapse $ currentDir </> tmpdir </> "bd1"
68-
84+
let baseDir = "bd1"
6985
let importDir = baseDir </> "import"
7086
let ownerDir = importDir </> "john"
7187
let bankDir = ownerDir </> "mybank"
7288
let accDir = bankDir </> "myacc"
7389
let inDir = accDir </> "1-in"
7490
let yearDir = inDir </> "2019"
75-
mktree yearDir
76-
77-
let reportDir = baseDir </> "report"
78-
mkdir reportDir
91+
let subDirs = [yearDir, inDir, accDir, bankDir, ownerDir, importDir, baseDir]
7992

80-
cd baseDir
81-
bd <- liftIO $ determineBaseDir Nothing
82-
liftIO $ assertEqual "determineBaseDir searches from pwd upwards until it finds a dir containing 'import' - in the base dir" baseDir bd
93+
mktree $ tmpdir </> yearDir
8394

84-
cd reportDir
85-
bdReport <- liftIO $ determineBaseDir Nothing
86-
liftIO $ assertEqual "determineBaseDir searches from pwd upwards until it finds a dir containing 'import' - report dir" baseDir bdReport
95+
let subDirsRelativeToTop = map (tmpdir </>) subDirs
8796

88-
cd yearDir
89-
bdYear <- liftIO $ determineBaseDir Nothing
90-
liftIO $ assertEqual "determineBaseDir searches from pwd upwards until it finds a dir containing 'import' - year dir" baseDir bdYear
91-
92-
cd inDir
93-
bdIn <- liftIO $ determineBaseDir Nothing
94-
liftIO $ assertEqual "determineBaseDir searches from pwd upwards until it finds a dir containing 'import' - input dir" baseDir bdIn
95-
96-
cd accDir
97-
bdAcc <- liftIO $ determineBaseDir Nothing
98-
liftIO $ assertEqual "determineBaseDir searches from pwd upwards until it finds a dir containing 'import' - account dir" baseDir bdAcc
99-
100-
cd bankDir
101-
bdBank <- liftIO $ determineBaseDir Nothing
102-
liftIO $ assertEqual "determineBaseDir searches from pwd upwards until it finds a dir containing 'import' - bank dir" baseDir bdBank
97+
currentDir <- pwd
98+
let absoluteTempDir = forceTrailingSlash $ collapse $ currentDir </> tmpdir
99+
let absoluteSubDirs = map (absoluteTempDir </>) subDirs
103100

104-
cd ownerDir
105-
bdOwner <- liftIO $ determineBaseDir Nothing
106-
liftIO $ assertEqual "determineBaseDir searches from pwd upwards until it finds a dir containing 'import' - owner dir" baseDir bdOwner
101+
let absoluteBaseDir = forceTrailingSlash $ absoluteTempDir </> baseDir
102+
liftIO $ assertSubDirsForDetermineBaseDir absoluteBaseDir absoluteSubDirs
103+
liftIO $ assertSubDirsForDetermineBaseDir absoluteBaseDir subDirsRelativeToTop
107104

108-
cd importDir
109-
bdImport <- liftIO $ determineBaseDir Nothing
110-
liftIO $ assertEqual "determineBaseDir searches from pwd upwards until it finds a dir containing 'import' - import dir" baseDir bdImport
105+
cd absoluteTempDir
106+
liftIO $ assertSubDirsForDetermineBaseDir absoluteBaseDir subDirs
111107
)
112108
)
113109

0 commit comments

Comments
 (0)