Skip to content

Commit 54b3364

Browse files
authored
Merge pull request #4 from justcoded/develop
lk-hotfix fixed, delete submodule added
2 parents 87114a3 + 700b903 commit 54b3364

File tree

4 files changed

+73
-11
lines changed

4 files changed

+73
-11
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
---
1010
<!--- END HEADER -->
1111

12+
## [1.2.0](https://github.com/justcoded/git-extras/compare/v1.1.0...v1.2.0) (2022-05-16)
13+
### Features
14+
15+
* Added delete-submodule extra
16+
17+
### Bug Fixes
18+
19+
* Lk-hotfix command doesn't work
20+
21+
22+
---
23+
1224
## [1.1.0](https://github.com/justcoded/git-extras/compare/v1.0.0...v1.1.0) (2022-05-13)
1325
### Features
1426

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ make install
1616

1717
## Commands reference
1818

19-
| Command | Description |
20-
|-------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
21-
| `git browse` | Opens remote repository URL in browser. Taken from [git-extras](https://github.com/tj/git-extras). |
22-
| `git set-config` | Configures repository with default global filemode (or 'false' by default) and push strategy. |
23-
| `git set-gitflow` | Creates if not exists `develop`/`release` branches or sync them. |
19+
| Command | Description |
20+
|-------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
21+
| `git browse` | Opens remote repository URL in browser. Taken from [git-extras](https://github.com/tj/git-extras). |
22+
| `git set-config` | Configures repository with default global filemode (or 'false' by default) and push strategy. |
23+
| `git set-gitflow` | Creates if not exists `develop`/`release` branches or sync them. |
2424
| `git jc-feature <shortDescription>` | Defines git branching flow ("gitflow" or "feature branch") and creates Feature branch from the right branch (develop or main/master) |
25-
| `git jc-hotfix <shortDescription>` | Creates Hotfix branch from `main`/`master` branch. |
26-
| `git lk-feature <shortDescription>` | Creates Feature branch from `release`. |
27-
| `git lk-epic <shortDescription>` | Creates Epic branch from `release`. |
28-
| `git lk-hotfix <shortDescription>` | Creates Hotfix branch from `main`/`master` branch. |
29-
25+
| `git jc-hotfix <shortDescription>` | Creates Hotfix branch from `main`/`master` branch. |
26+
| `git lk-feature <shortDescription>` | Creates Feature branch from `release`. |
27+
| `git lk-epic <shortDescription>` | Creates Epic branch from `release`. |
28+
| `git lk-hotfix <shortDescription>` | Creates Hotfix branch from `main`/`master` branch. |
29+
| `git delete-submodule` | Deletes specified submodule. Taken from [git-extras](https://github.com/tj/git-extras). |

bin/git-delete-submodule

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
abort() {
4+
error="$1" && shift
5+
echo "ERROR: $*" 1>&2
6+
test -z "$FORCE" && exit "$error"
7+
}
8+
9+
# Don't abort on failures. This allows to cleanup after a previous failure.
10+
[ "$1" = '--force' ] && FORCE=1 && shift
11+
12+
test -z "$1" && abort 1 'Submodule required'
13+
cd "$(git root)" || abort 5 'Cannot change to repository root'
14+
test ! -f '.gitmodules' && abort 2 '.gitmodules file not found'
15+
16+
NAME="${1%/}"
17+
test -z "$(git config --file='.gitmodules' "submodule.$NAME.url")" \
18+
&& abort 3 'Submodule not found'
19+
20+
# 1. Handle the .git directory
21+
# 1.a. Delete the relevant section from .git/config
22+
git submodule deinit -f "$NAME" || abort 4 "Failed to deinitialize $NAME"
23+
# 1.b. Delete empty submodule directory
24+
git rm -f "$NAME"
25+
26+
# 2. Handle .gitmodules file
27+
# 2.a. Delete the relevant line from .gitmodules
28+
git config --file='.gitmodules' --remove-section "submodule.$NAME" 2>/dev/null || :
29+
# 2.b and stage changes
30+
git add '.gitmodules'
31+
# 2.c. Delete empty .gitmodules
32+
[ "$(wc -l '.gitmodules' | cut -d' ' -f1)" = '0' ] && git rm -f '.gitmodules'
33+
34+
# 3. Need to confirm and commit the changes for yourself
35+
git_status_text="$(git submodule status 2>&1)"
36+
git_status_exit=$?
37+
if [ "$git_status_exit" -eq 0 ] \
38+
&& printf '%s' "DUMMY$git_status_text" | grep -v "$NAME" > /dev/null; then
39+
# grep fails when piping in an empty string, so we add a DUMMY prefix
40+
41+
echo "Successfully deleted $NAME."
42+
else
43+
abort 6 "Failed to delete $NAME with error:\n$git_status_text"
44+
fi
45+
printf '\n%s\n' '== git submodule status =='
46+
printf '%s\n' "$git_status_text"
47+
printf '%s\n' '=========================='
48+
# shellcheck disable=SC2016
49+
echo 'Confirm the output of `git submodule status` above (if any)' \
50+
'and then commit the changes.'

bin/git-lk-hotfix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
git jc-hotfix "$@"
3+
git jc-branch -p hotfix/ -s master "$@"

0 commit comments

Comments
 (0)