Skip to content

Commit c5ca094

Browse files
authored
Merge pull request #7 from 3scale-labs/test
ignore git-ignored optionally and colored diffs
2 parents 76b48a9 + efa06b3 commit c5ca094

3 files changed

Lines changed: 364 additions & 7 deletions

File tree

agent-dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# claude-code-isolated: Secure bubblewrap wrapper for running commands in isolation
33
#
44
# Provides isolated environment with:

merge-overlay

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# merge-overlay: Interactive tool to review and merge overlayfs changes back to host
33
#
44
# Usage:
@@ -43,6 +43,50 @@ should_ignore() {
4343
return 1
4444
}
4545

46+
is_git_ignored() {
47+
(cd "$REPO_DIR" && git check-ignore -q "$1") 2>/dev/null
48+
}
49+
50+
GIT_IGNORED_CHOICE=""
51+
52+
git_ignored_should_discard() {
53+
local rel_path="$1"
54+
55+
# If user already chose to keep, skip checking (optimization)
56+
[[ "$GIT_IGNORED_CHOICE" == "keep" ]] && return 1
57+
58+
# Check if file is git-ignored
59+
is_git_ignored "$rel_path" || return 1
60+
61+
# If already chose to discard, return true
62+
[[ "$GIT_IGNORED_CHOICE" == "discard" ]] && return 0
63+
64+
# First git-ignored file - ask user
65+
echo ""
66+
echo -e "${YELLOW}⚠ Git-ignored file detected:${NC} $rel_path"
67+
echo ""
68+
while true; do
69+
read -p "How should git-ignored files be handled? [a/A=ask (review), D=discard all]? " choice
70+
case "$choice" in
71+
a|A)
72+
echo "→ Git-ignored files will be treated like regular changes"
73+
echo ""
74+
GIT_IGNORED_CHOICE="keep"
75+
return 1
76+
;;
77+
D)
78+
echo "→ All git-ignored files will be discarded"
79+
echo ""
80+
GIT_IGNORED_CHOICE="discard"
81+
return 0
82+
;;
83+
*)
84+
echo "Invalid choice. Please enter a, A, or D"
85+
;;
86+
esac
87+
done
88+
}
89+
4690
# Validate directories
4791
if [[ ! -d "$REPO_DIR" ]]; then
4892
echo "Error: Repository directory does not exist: $REPO_DIR"
@@ -130,7 +174,7 @@ show_diff() {
130174
if [[ -f "$repo_file" ]]; then
131175
echo ""
132176
echo "====== Diff: $repo_file ======"
133-
diff -u "$repo_file" "$overlay_file" || true
177+
diff -u --color=always "$repo_file" "$overlay_file" || true
134178
echo "=============================="
135179
echo ""
136180
else
@@ -299,16 +343,22 @@ echo ""
299343
# We need to handle whiteout files (both .wh. prefix and char devices 0/0) and regular files
300344
FILES=()
301345
IGNORED=()
302-
while IFS= read -r -d '' file; do
346+
GIT_IGNORED_COUNT=0
347+
348+
# Read from fd 4 (connected to find output) so stdin remains available for user input
349+
while IFS= read -u 4 -r -d '' file; do
303350
rel_path="${file#$OVERLAY_UPPER/}"
304351
if should_ignore "$rel_path"; then
305352
IGNORED+=("$rel_path")
306353
# Auto-discard ignored files
307354
rm -f "$file"
355+
elif git_ignored_should_discard "$rel_path"; then
356+
rm -f "$file"
357+
((GIT_IGNORED_COUNT++))
308358
else
309359
FILES+=("$rel_path")
310360
fi
311-
done < <(find "$OVERLAY_UPPER" \( -type f -o -type c \) -print0 | sort -z)
361+
done 4< <(find "$OVERLAY_UPPER" \( -type f -o -type c \) -print0)
312362

313363
# Report ignored files
314364
if [[ ${#IGNORED[@]} -gt 0 ]]; then
@@ -319,6 +369,12 @@ if [[ ${#IGNORED[@]} -gt 0 ]]; then
319369
echo ""
320370
fi
321371

372+
# Report git-ignored files that were discarded
373+
if [[ $GIT_IGNORED_COUNT -gt 0 ]]; then
374+
echo "Discarded $GIT_IGNORED_COUNT git-ignored file(s)"
375+
echo ""
376+
fi
377+
322378
TOTAL=${#FILES[@]}
323379

324380
# Exit if no files remain after filtering

0 commit comments

Comments
 (0)