Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions ptc-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2976,12 +2976,16 @@ ptc-translate:
# > "Allow Git push requests to the repository" (GitLab 18.4+, off by
# default). Otherwise set PTC_GIT_PUSH_TOKEN to a project access token with
# the write_repository scope, as a masked CI/CD variable.
# \`git add -A\` comes BEFORE the check, and the check reads the index.
# On the first run the translations are new files, and a plain
# \`git diff\` only looks at tracked ones - it would report "nothing changed",
# skip the push, and leave a green job that produced no merge request.
- |
if ! git diff --quiet; then
git config user.email "ci@ptc"
git config user.name "PTC Translate"
git checkout -B ptc/translations
git add -A
git config user.email "ci@ptc"
git config user.name "PTC Translate"
git checkout -B ptc/translations
git add -A
if ! git diff --cached --quiet; then
git commit -m "chore(i18n): update translations via PTC [skip ci]"
git push -o merge_request.create \\
-o merge_request.target="\$CI_DEFAULT_BRANCH" \\
Expand Down
15 changes: 15 additions & 0 deletions tests/test-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,21 @@ test_ci_snippets_use_action() {
# by default), so the recipe must accept a write_repository token instead.
assert_contains "gitlab allows a push token override" "$gl" 'PTC_GIT_PUSH_TOKEN:-$CI_JOB_TOKEN'

# On the first run the translations are NEW files. `git diff`
# reads the worktree against the index and only sees tracked paths, so it
# reports "nothing changed", the push is skipped, and the job goes green
# having produced no merge request. Staging first and asking `--cached`
# is what makes run #1 push. Order is the defect, so assert the order,
# not merely the presence of both commands.
assert_contains "gitlab checks the index, where new files land" "$gl" "git diff --cached --quiet"
assert_not_contains "gitlab does not check the worktree, which misses new files" "$gl" "if ! git diff --quiet"
local add_at check_at
add_at=$(printf '%s\n' "$gl" | grep -n "git add -A" | head -1 | cut -d: -f1)
check_at=$(printf '%s\n' "$gl" | grep -n "git diff --cached --quiet" | head -1 | cut -d: -f1)
assert_eq "gitlab stages before it checks for changes" \
"$([ -n "$add_at" ] && [ -n "$check_at" ] && [ "$add_at" -lt "$check_at" ] && echo "add-then-check" || echo "check-then-add")" \
"add-then-check"

# The standalone path is still offered, so the CLI does not depend on the action.
assert_contains "standalone CLI usage is still shown" "$block" "./ptc-cli.sh --config-file .ptc-config.yml"
}
Expand Down