-
Notifications
You must be signed in to change notification settings - Fork 9
/
gitpatch.bat
62 lines (48 loc) · 2.01 KB
/
gitpatch.bat
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
@setlocal EnableDelayedExpansion
@echo off
:init
set "D=%DATE%"
set "T=%TIME%"
if "%T:~0,1%"==" " set "T=0%T:~1%"
set "filepart="
:parse
if "%~1"=="" goto :main
if /i "%1"=="--cached" set "fileset=--cached" && shift && goto :parse
if /i "%1"=="-cached" set "fileset=--cached" && shift && goto :parse
if /i "%1"=="cached" set "fileset=--cached" && shift && goto :parse
if /i "%1"=="--staged" set "fileset=--cached" && shift && goto :parse
if /i "%1"=="-staged" set "fileset=--cached" && shift && goto :parse
if /i "%1"=="staged" set "fileset=--cached" && shift && goto :parse
if /i "%1"=="--head" set "fileset=HEAD" && shift && goto :parse
if /i "%1"=="-head" set "fileset=HEAD" && shift && goto :parse
if /i "%1"=="head" set "fileset=HEAD" && shift && goto :parse
if /i "%1"=="--all" set "fileset=HEAD" && shift && goto :parse
if /i "%1"=="-all" set "fileset=HEAD" && shift && goto :parse
if /i "%1"=="all" set "fileset=HEAD" && shift && goto :parse
if /i "%1"=="--unstaged" set "fileset=" && shift && goto :parse
if /i "%1"=="-unstaged" set "fileset=" && shift && goto :parse
if /i "%1"=="unstaged" set "fileset=" && shift && goto :parse
:: Use any other argument as part of the file name..
if "%filepart%"=="" set filepart=%~1
shift
goto :parse
:main
if "%fileset%"=="" (
set filesetname=unstaged
) else (
set filesetname=!fileset!
rem if "%filesetname:~0,2%"=="--" set filesetname=%filesetname:~2%
if "!filesetname:~0,2!"=="--" (
set filesetname=!filesetname:~2!
)
)
if "!filepart!"=="" set "filepart=Current Work"
if not "!filesetname!"=="" set "filesetname= (!filesetname!)"
set filename=%UserProfile%\Desktop\%D:~-4%-%D:~4,2%-%D:~7,2% %T:~0,2%-%T:~3,2%-%T:~6,2% !filepart!!filesetname!.patch
:: Different ways to create a patch..
rem git format-patch -1 --stdout > "%filename%"
rem git diff %fileset% >"%filename%"
echo git diff %fileset% ^>"%filename%"
git diff %fileset% >"%filename%"
:end
endlocal && exit /B 0