Skip to content

Commit 267f365

Browse files
mcepldmach
authored andcommitted
feat: add subpackage git-obs-hooks-script-convert-changes
Add subpackage with a working script, which causes `git commit` to generate default commit message based on the last record in the `*.changes` file.
1 parent 537c4f6 commit 267f365

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

git-obs-hooks.spec

+23-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ Group: Development/Tools/Other
77
URL: https://github.com/dmach/git-obs-hooks
88
Source: https://github.com/dmach/git-obs-hooks/archive/refs/tags/%{version}.tar.gz#/%{name}-%{version}.tar.gz
99

10+
BuildRequires: fdupes
1011
BuildArch: noarch
1112
BuildRoot: %{_tmppath}/%{name}-%{version}-build
1213

13-
%define hook_dir %{_datarootdir}/git-obs-hooks
14+
%define hook_dir %{_datadir}/git-obs-hooks
1415

1516
%description
1617
Framework for running git hooks in git-obs and osc.
@@ -22,9 +23,21 @@ To enable git-obs-hooks in the current git repo, run: install-git-obs-hooks
2223

2324
See githooks(5) man page for more help on the hooks.
2425

26+
%package script-convert-changes
27+
Summary: working script for %{name} converting last record of *.changes to git commit
28+
Requires: %{name} = %{version}
29+
30+
%description script-convert-changes
31+
Working script for %{name}, which causes `git commit` to generate
32+
default commit message based on the last last record in the
33+
`*.changes`.
34+
2535
%prep
2636
%autosetup -p1
2737

38+
%build
39+
:
40+
2841
%install
2942
install -D install-git-obs-hooks %{buildroot}%{_bindir}/install-git-obs-hooks
3043

@@ -70,6 +83,12 @@ install -D git-obs-hook-template %{buildroot}%{hook_dir}/sendemail-validate
7083
install -d %{buildroot}%{hook_dir}/update.d
7184
install -D git-obs-hook-template %{buildroot}%{hook_dir}/update
7285

86+
for scriptlet in scripts/*/*.sh ; do
87+
cp -p "${scriptlet}" "%{buildroot}%{hook_dir}/${scriptlet#*/}"
88+
done
89+
90+
%fdupes %{buildroot}%{hook_dir}
91+
7392
%files
7493
%defattr(-,root,root,-)
7594
%attr(0755, root, root) %{_bindir}/install-git-obs-hooks
@@ -92,4 +111,7 @@ install -D git-obs-hook-template %{buildroot}%{hook_dir}/update
92111
%license LICENSE
93112
%doc README.md
94113

114+
%files script-convert-changes
115+
%{hook_dir}/prepare-commit-msg.d
116+
95117
%changelog
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
set -e
3+
4+
COMMIT_MSG_FILE="$1"
5+
COMMIT_SOURCE="$2"
6+
SHA1="${3:-HEAD}"
7+
8+
# {
9+
# printf "COMMIT_MSG_FILE: %s\n" "$COMMIT_MSG_FILE" >>/tmp/prepare-commit-msg-log.txt
10+
# printf "COMMIT_SOURCE: %s\n" "$COMMIT_SOURCE" >>/tmp/prepare-commit-msg-log.txt
11+
# printf "SHA1: %s\n" "$SHA1" >>/tmp/prepare-commit-msg-log.txt
12+
# printf "\n"
13+
# } >>/tmp/prepare-commit-msg-log.txt
14+
15+
if test -z "$COMMIT_SOURCE"; then
16+
if ! git add -- *.changes; then
17+
echo "Error: Failed to add *.changes files." >&2
18+
exit 1
19+
fi
20+
21+
diff=$(git diff --no-color "$SHA1" -- *.changes \
22+
| sed -E -n -e '/^\+[^+]/s/^\+//p' \
23+
| sed -e '/^-\{4,\}/,+1d' \
24+
| sed -e 's/^- *//')
25+
26+
if test -n "$diff"
27+
then # Check if diff is not empty
28+
TEMP_COMMIT_MSG=$(mktemp /tmp/moddiff.XXXXXX.msg)
29+
trap 'rm -f $TEMP_COMMIT_MSG' EXIT
30+
printf "%s\n" "$diff" >"$TEMP_COMMIT_MSG"
31+
cat "$COMMIT_MSG_FILE" >>"$TEMP_COMMIT_MSG"
32+
mv "$TEMP_COMMIT_MSG" "$COMMIT_MSG_FILE"
33+
fi
34+
fi

0 commit comments

Comments
 (0)