Skip to content

Commit b47d383

Browse files
committed
Implement issue #62: search for ADR dir in parents of current
directory.
1 parent db4185e commit b47d383

File tree

7 files changed

+84
-12
lines changed

7 files changed

+84
-12
lines changed

Makefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
TESTS:=$(wildcard tests/*.sh)
33
SRC:=$(wildcard src/*)
44

5-
check: $(TESTS:tests/%.sh=build/tests/%.diff)
5+
# Run tests outside the project directory so that they cannot interfere with the project's
6+
# own ADR directory
7+
BUILDDIR:=/tmp/adr-tools-build
8+
9+
check: $(TESTS:tests/%.sh=$(BUILDDIR)/tests/%.diff)
610
@echo SUCCESS
711

8-
build/tests/%.diff: build/tests/%.output tests/%.expected
12+
$(BUILDDIR)/tests/%.diff: $(BUILDDIR)/tests/%.output tests/%.expected
913
@diff --side-by-side $^ > $@ || ! cat $@
1014

11-
build/tests/%.output: tests/%.sh tests/%.expected $(SRC)
15+
$(BUILDDIR)/tests/%.output: tests/%.sh tests/%.expected $(SRC)
1216
@echo TEST: $*
1317
@rm -rf $(dir $@)/$*
1418
@mkdir -p $(dir $@)/$*
@@ -21,8 +25,11 @@ build/tests/%.output: tests/%.sh tests/%.expected $(SRC)
2125
/bin/sh -v $(abspath $<) > $(abspath $@) 2>&1) || ! cat $@
2226

2327
clean:
24-
rm -rf build/
28+
rm -rf /tmp/adr-tools-build
29+
30+
show-%:
31+
@echo "$* ($(flavor $*)) = $($*)"
2532

2633
.PHONY: all clean
27-
.PRECIOUS: build/tests/%.output
34+
.PRECIOUS: $(BUILDDIR)/tests/%.output
2835
.DELETE_ON_ERROR:

approve

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ test="${1:?test}"
55

66
test_name=$(basename $test | sed 's/\..*//')
77

8-
cp -v build/tests/$test_name.output tests/$test_name.expected
8+
cp -v /tmp/adr-tools-build/tests/$test_name.output tests/$test_name.expected

src/_adr_dir

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,29 @@
22
set -e
33
eval "$($(dirname $0)/adr-config)"
44

5-
if [ -f .adr-dir ]
6-
then
7-
cat .adr-dir
8-
else
9-
echo doc/adr
10-
fi
5+
reldir=.
6+
7+
function mkrel() {
8+
local d=$reldir/$1
9+
echo ${d#./}
10+
}
11+
12+
function absdir() {
13+
(cd $(dirname $1) && pwd -P)
14+
}
15+
16+
while [ $(absdir $reldir) != / ]
17+
do
18+
if [ -f $(mkrel .adr-dir) ]
19+
then
20+
mkrel $(cat $(mkrel .adr-dir))
21+
exit
22+
elif [ -d $(mkrel doc/adr) ]
23+
then
24+
mkrel doc/adr
25+
exit
26+
else
27+
reldir=$reldir/..
28+
fi
29+
done
30+
echo doc/adr

tests/search-for-adr-dir.expected

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
adr new First Record
2+
doc/adr/0001-first-record.md
3+
mkdir subdir
4+
cd subdir
5+
adr new Second Record
6+
../doc/adr/0002-second-record.md
7+
adr list
8+
../doc/adr/0001-first-record.md
9+
../doc/adr/0002-second-record.md
10+
cd ..
11+
adr list
12+
doc/adr/0001-first-record.md
13+
doc/adr/0002-second-record.md

tests/search-for-adr-dir.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
adr new First Record
2+
mkdir subdir
3+
cd subdir
4+
adr new Second Record
5+
adr list
6+
cd ..
7+
adr list
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
adr init architecture-log
2+
architecture-log/0001-record-architecture-decisions.md
3+
adr new First Record
4+
architecture-log/0002-first-record.md
5+
mkdir subdir
6+
cd subdir
7+
adr new Second Record
8+
../architecture-log/0003-second-record.md
9+
adr list
10+
../architecture-log/0001-record-architecture-decisions.md
11+
../architecture-log/0002-first-record.md
12+
../architecture-log/0003-second-record.md
13+
cd ..
14+
adr list
15+
architecture-log/0001-record-architecture-decisions.md
16+
architecture-log/0002-first-record.md
17+
architecture-log/0003-second-record.md

tests/search-for-custom-adr-dir.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
adr init architecture-log
2+
adr new First Record
3+
mkdir subdir
4+
cd subdir
5+
adr new Second Record
6+
adr list
7+
cd ..
8+
adr list

0 commit comments

Comments
 (0)