fix: don't write an empty changelog when the clone has one tag

- git2debcl writes one entry per tag, listing the commits since the
  next older tag. With only one tag in the clone, or none, there was
  nothing to compare against and the changelog came out empty.
- In that case list the whole history under the newest version. Output
  for clones with more than one tag is unchanged.
This commit is contained in:
Antonio SJ Musumeci 2026-11-21 14:53:45 -05:00
parent 8555c56418
commit 0f9d52d9d8

View file

@ -152,6 +152,23 @@ else
echo "$TAGS" >> "$TMPFILE"
fi
# Print one changelog entry: header, log lines, then author and time
print_entry() {
local tag="$1"
local ref="$2"
local entries="$3"
printf "%s (%s%s) %s; urgency=%s\n\n" "$NAME" "$tag" "$VERSUFFIX" "$CODENAME" "$URGENCY"
echo "$entries" | while IFS= read -r entry; do
if [ -n "$entry" ]; then
printf " * %s\n" "$entry"
fi
done
printf "\n %s\n\n" "$(git_author_and_time "$ref")"
}
# Process tags and generate changelog
PREV_TAG=""
PREV_REF=""
@ -182,21 +199,17 @@ while IFS= read -r line; do
continue
fi
# Print package header
printf "%s (%s%s) %s; urgency=%s\n\n" "$NAME" "$PREV_TAG" "$VERSUFFIX" "$CODENAME" "$URGENCY"
# Print each log entry
echo "$LOG_ENTRIES" | while IFS= read -r entry; do
if [ -n "$entry" ]; then
printf " * %s\n" "$entry"
fi
done
# Print author and time
AUTHOR_TIME=$(git_author_and_time "$PREV_REF")
printf "\n %s\n\n" "$AUTHOR_TIME"
print_entry "$PREV_TAG" "$PREV_REF" "$LOG_ENTRIES"
FIRST=0
fi
PREV_TAG="$TAG"
PREV_REF="$REF"
done < "$TMPFILE"
# Each entry needs an older tag to compare against. A clone with only
# one tag, or none, would get an empty changelog, so list the whole
# history under the newest version instead.
if [ "$FIRST" = 1 ] && [ -n "$PREV_TAG" ]; then
print_entry "$PREV_TAG" "$PREV_REF" "$(git log --no-merges --oneline "$PREV_REF" 2>/dev/null)"
fi