Skip to content

Commit 22a9bc3

Browse files
committed
feat(gitutils): ✨ add script to fix file mode changes
1 parent 8df18f5 commit 22a9bc3

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/gitutils/_git-fix-mode.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# Fix file mode changes from diff
4+
# Handle the case where no deleted files exist
5+
6+
set -e
7+
8+
# Get the list of deleted files
9+
deleted_files=$(git ls-files --deleted)
10+
11+
# Generate the diff with mode information
12+
diff_output=$(git diff -p -R --no-color | grep -E "^(diff|(old|new) mode)" --color=never)
13+
14+
# If we have diff output
15+
if [ -n "$diff_output" ]; then
16+
if [ -n "$deleted_files" ]; then
17+
# Filter out deleted files
18+
echo "$diff_output" | grep -vF "$deleted_files" | git apply --allow-empty --no-index
19+
else
20+
# No deleted files, apply all mode changes
21+
echo "$diff_output" | git apply --allow-empty --no-index
22+
fi
23+
fi
24+
25+
exit 0

src/gitutils/alias.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"help": "Set user.name and user.email to specified commit's author."
4949
},
5050
"fixMode": {
51-
"cmd": "git diff -p -R --no-color | grep -E \"^(diff|(old|new) mode)\" --color=never | grep -vF \"$(git ls-files --deleted)\" | git apply --allow-empty --no-index; exit 0",
51+
"cmd": "git fix mode",
5252
"help": "Restore file mode changes from diff."
5353
},
5454
"forceable": {

src/gitutils/devcontainer-feature.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "gitutils",
33
"name": "Git Aliases",
44
"description": "A feature to add useful Git aliases to your shell.",
5-
"version": "5.24.0",
5+
"version": "5.24.1",
66
"dependsOn": {
77
"ghcr.io/devcontainers/features/node:1": "lts",
88
"ghcr.io/tomgrv/devcontainer-features/common-utils:3": {
@@ -39,6 +39,6 @@
3939
"config": "configure-feature gitutils"
4040
},
4141
"postStartCommand": {
42-
"files": "git fixMode"
42+
"files": "git fix mode"
4343
}
4444
}

0 commit comments

Comments
 (0)