This repository was archived by the owner on Feb 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_submodule.fish
More file actions
executable file
·76 lines (63 loc) · 2.25 KB
/
remove_submodule.fish
File metadata and controls
executable file
·76 lines (63 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env fish
function remove_git_submodule
# Check if we got an argument
if test (count $argv) -eq 0
echo "Usage: remove_git_submodule <submodule-directory>"
echo "Example: remove_git_submodule libs/some-library"
return 1
end
set submodule_path $argv[1]
# Remove trailing slash if present
set submodule_path (string trim --right --chars=/ $submodule_path)
# Check if we're in a git repository
if not git rev-parse --git-dir >/dev/null 2>&1
echo "Error: Not in a git repository"
return 1
end
# Check if the submodule exists
if not test -d $submodule_path
echo "Error: Directory '$submodule_path' does not exist"
return 1
end
# Check if it's actually a submodule
if not git submodule status $submodule_path >/dev/null 2>&1
echo "Error: '$submodule_path' is not a git submodule"
return 1
end
echo "Removing git submodule: $submodule_path"
# Step 1: Deinitialize the submodule
echo "→ Deinitializing submodule..."
git submodule deinit -f $submodule_path
if test $status -ne 0
echo "Error: Failed to deinitialize submodule"
return 1
end
# Step 2: Remove the submodule from .git/modules
echo "→ Removing from .git/modules..."
rm -rf .git/modules/$submodule_path
if test $status -ne 0
echo "Error: Failed to remove .git/modules/$submodule_path"
return 1
end
# Step 3: Remove the submodule from the working tree
echo "→ Removing from git index..."
git rm -f $submodule_path
if test $status -ne 0
echo "Error: Failed to remove submodule from git"
return 1
end
# Step 4: Check if .gitmodules is now empty and remove if so
if test -f .gitmodules
set gitmodules_content (string trim (cat .gitmodules))
if test -z "$gitmodules_content"
echo "→ Removing empty .gitmodules file..."
git rm .gitmodules
end
end
echo "✓ Submodule '$submodule_path' successfully removed"
echo ""
echo "Don't forget to commit these changes:"
echo " git commit -m \"Remove submodule $submodule_path\""
end
# Run the function with arguments passed to the script
remove_git_submodule $argv