Skip to content

Commit daa1d75

Browse files
committed
fix(git): fix boolean expression syntax and shell expansion issues
Fixed two issues in git workflows: 1. git-analyze-changes: Split boolean expression into separate variable references to enable proper variable resolution and evaluation 2. git-commit: Replace echo with printf to prevent shell expansion of special characters in commit messages
1 parent fdfb0d8 commit daa1d75

2 files changed

Lines changed: 82 additions & 51 deletions

File tree

src/workflows_mcp/templates/git/git-analyze-changes.yaml

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,102 @@ inputs:
1010
default: "."
1111
required: false
1212

13+
staged_only:
14+
type: bool
15+
description: If true, only analyze staged changes (default). Set false to include unstaged/untracked.
16+
default: true
17+
required: false
18+
1319
blocks:
14-
- id: changes
20+
- id: get_staged_summary
1521
type: Shell
22+
description: "Get diff statistics for staged changes"
1623
inputs:
17-
command: |
18-
# Check for any changes: staged, unstaged, or untracked
19-
if [ -z "$(git status --porcelain)" ]; then
20-
printf "false" > $SCRATCH/changes.txt
21-
else
22-
printf "true" > $SCRATCH/changes.txt
23-
fi
24+
command: git diff --cached --stat --compact-summary > $SCRATCH/summary.txt
2425
working_dir: "${inputs.working_dir}"
25-
outputs:
26-
detected:
27-
type: bool
28-
description: "Indicates if there are any changes (staged, unstaged, or untracked)"
29-
path: "$SCRATCH/changes.txt"
26+
condition: "${inputs.staged_only}"
3027

31-
- id: get_file_status
28+
- id: get_staged_diff
3229
type: Shell
30+
description: "Generate compact diff of staged changes"
3331
inputs:
34-
command: git status --short --porcelain
32+
command: git diff --cached -U0 --inter-hunk-context=0 --no-color --no-prefix > $SCRATCH/raw_diff.txt
3533
working_dir: "${inputs.working_dir}"
36-
condition: ${blocks.changes.outputs.detected}
37-
depends_on:
38-
- changes
34+
condition: "${inputs.staged_only}"
3935

40-
- id: get_staged_diff
36+
- id: get_all_summary
4137
type: Shell
38+
description: "Get diff statistics for all changes (staged + unstaged)"
4239
inputs:
43-
command: git diff --cached
40+
command: git diff HEAD --stat --compact-summary > $SCRATCH/summary.txt
4441
working_dir: "${inputs.working_dir}"
45-
condition: ${blocks.changes.outputs.detected}
46-
depends_on:
47-
- changes
42+
condition: "not ${inputs.staged_only}"
4843

49-
- id: get_unstaged_diff
44+
- id: get_all_diff
5045
type: Shell
46+
description: "Generate compact diff of all changes (staged + unstaged)"
5147
inputs:
52-
command: git diff
48+
command: |
49+
git diff HEAD -U0 --inter-hunk-context=0 --no-color --no-prefix > $SCRATCH/raw_diff.txt
5350
working_dir: "${inputs.working_dir}"
54-
condition: ${blocks.changes.outputs.detected}
55-
depends_on:
56-
- changes
51+
condition: "not ${inputs.staged_only}"
5752

58-
- id: get_diff_stat
53+
- id: processing
5954
type: Shell
55+
description: "Process and consolidate analysis results"
6056
inputs:
6157
command: |
62-
echo "=== Staged Changes ==="
63-
git diff --cached --stat || echo "No staged changes"
64-
echo ""
65-
echo "=== Unstaged Changes ==="
66-
git diff --stat || echo "No unstaged changes"
58+
MAX_LINES=40
59+
60+
# Process raw diff with line limiting
61+
if [ -f "$SCRATCH/raw_diff.txt" ]; then
62+
awk -v max="$MAX_LINES" '
63+
BEGIN { lines = 0; truncated = 0 }
64+
/^diff --git/ {
65+
if (truncated) {
66+
print " ... (truncated " truncated " lines)\n"
67+
}
68+
lines = 0
69+
truncated = 0
70+
print
71+
next
72+
}
73+
{
74+
if (lines < max) {
75+
print
76+
lines++
77+
} else {
78+
truncated++
79+
}
80+
}
81+
END {
82+
if (truncated) {
83+
print " ... (truncated " truncated " lines)"
84+
}
85+
}
86+
' "$SCRATCH/raw_diff.txt" > "$SCRATCH/processed_diff.txt"
87+
else
88+
touch "$SCRATCH/processed_diff.txt"
89+
fi
6790
working_dir: "${inputs.working_dir}"
68-
condition: ${blocks.changes.outputs.detected}
6991
depends_on:
70-
- changes
92+
- block: get_staged_summary
93+
required: false
94+
- block: get_staged_diff
95+
required: false
96+
- block: get_all_summary
97+
required: false
98+
- block: get_all_diff
99+
required: false
100+
outputs:
101+
summary:
102+
type: str
103+
path: "$SCRATCH/summary.txt"
104+
diff:
105+
type: str
106+
path: "$SCRATCH/processed_diff.txt"
71107

72108
outputs:
73-
has_changes: "${blocks.changes.outputs.detected}"
74-
file_status: "${blocks.get_file_status.outputs.stdout}"
75-
staged_diff: "${blocks.get_staged_diff.outputs.stdout}"
76-
unstaged_diff: "${blocks.get_unstaged_diff.outputs.stdout}"
77-
diff_stat: "${blocks.get_diff_stat.outputs.stdout}"
109+
has_changes: "${blocks.get_staged_diff.succeeded} or ${blocks.get_all_diff.succeeded}"
110+
summary: "${blocks.processing.outputs.summary}"
111+
diff: "${blocks.processing.outputs.diff}"

src/workflows_mcp/templates/git/git-commit.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,11 @@ blocks:
9595
- Body: explain what and why (optional)
9696
- Scope: component/module affected (optional)
9797
98-
## File Status
99-
${blocks.analyze_changes.outputs.file_status}
100-
101-
## Diff Statistics
102-
${blocks.analyze_changes.outputs.diff_stat}
98+
## Summary
99+
${blocks.analyze_changes.outputs.summary}
103100
104101
## Detailed Changes
105-
${blocks.analyze_changes.outputs.staged_diff}
102+
${blocks.analyze_changes.outputs.diff}
106103
107104
Generate ONLY the commit message (no quotes, no explanations):
108105
condition: "${blocks.analyze_changes.outputs.has_changes} and ${inputs.commit_message} == ''"
@@ -116,10 +113,10 @@ blocks:
116113
command: |
117114
if [ -n "${inputs.commit_message}" ]; then
118115
# Use manual message if provided
119-
echo "${inputs.commit_message}"
116+
printf '%s\n' "${inputs.commit_message}"
120117
else
121-
# Use LLM-generated message
122-
echo "${blocks.llm_generate_message.outputs.response}"
118+
# Use LLM-generated message (printf prevents shell expansion of special chars)
119+
printf '%s\n' "${blocks.llm_generate_message.outputs.response}"
123120
fi
124121
condition: "${blocks.analyze_changes.outputs.has_changes}"
125122
depends_on:
@@ -147,7 +144,7 @@ blocks:
147144
command: |
148145
set -e # Exit immediately if any command fails
149146
# Create commit and get hash (using -F - to handle multi-line messages)
150-
echo "${blocks.select_message.outputs.stdout}" | git commit -F -
147+
printf '%s' "${blocks.select_message.outputs.stdout}" | git commit -F -
151148
git rev-parse HEAD
152149
working_dir: "${inputs.working_dir}"
153150
condition: "${blocks.analyze_changes.outputs.has_changes} and (${inputs.auto_commit} or ${blocks.confirm_commit.outputs.response} == 'yes')"

0 commit comments

Comments
 (0)