-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.bat
More file actions
72 lines (63 loc) · 1.29 KB
/
commit.bat
File metadata and controls
72 lines (63 loc) · 1.29 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
@echo off
setlocal
rem commit.bat
rem Abort if anything is staged
set "git_diff=git diff --cached --quiet"
%git_diff%
set "rc=%errorlevel%"
if "%rc%"=="1" (
>&2 echo -- ERROR: staged changes exist; aborting.
exit /b 1
)
if not "%rc%"=="0" (
>&2 echo -- ERROR: "%git_diff%" failed; aborting.
exit /b %rc%
)
rem git status
set "git_status=git status --short"
%git_status%
set "rc=%errorlevel%"
if errorlevel 1 (
>&2 echo -- ERROR: "%git_status%" failed; aborting.
exit /b %rc%
)
rem git add
set "git_add=git add -A"
%git_add%
set "rc=%errorlevel%"
if errorlevel 1 (
>&2 echo -- ERROR: "%git_add%" failed; aborting.
exit /b %rc%
)
rem Exit if nothing has changed
%git_diff%
set "rc=%errorlevel%"
if "%rc%"=="0" (
>&2 echo -- nothing to commit; exiting.
goto reset
)
if not "%rc%"=="1" (
>&2 echo -- ERROR: "%git_diff%" failed; aborting.
goto reset
)
rem confirmation
set "confirm="
set /p "confirm=Commit all changes? [y/N]: "
if /i not "%confirm:~0,1%"=="y" (
>&2 echo -- commit canceled; exiting.
set "rc=0"
goto reset
)
rem git commit
git commit
set "rc=%errorlevel%"
rem git reset
:reset
set "git_reset=git reset ."
%git_reset% >nul 2>nul
if errorlevel 1 (
>&2 echo -- ERROR: "%git_reset%" failed; aborting.
exit /b 1
)
rem the end
exit /b %rc%