forked from logseq/git-auto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Start-GitAutoCommit.ps1
57 lines (51 loc) · 1.2 KB
/
Start-GitAutoCommit.ps1
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
# Usage:
# git-auto ;; use current script dir as git dir, and Start-GitAutoCommitAnoPpush.
# git-auto -d /path/to/your/note's/dir ;; set git dir
# git-auto -p ;; Start-GitAutoCommitAndPush
# git-auto -s origin -p ;; set remote server
# git-auto -b main -p ;; set git branch
# git-auto -i 30 -p ;; set interval seconds
# git-auto -o -p;; execute once
# parameters
param (
[Alias('d')]
[string] $Dir,
[Alias('i')]
[int] $Interval = 20,
[Alias('p')]
[switch] $PushToServer = $false,
[Alias('o')]
[switch] $Once = $false,
[Alias('s')]
[string] $Server,
[Alias('b')]
[string] $Branch
)
# if -Dir/-d specified
if ($Dir -ne "") {
Set-Location $Dir
}
# if -Branch/-b specified
if ($Branch -eq "") {
$Branch = (& git rev-parse --abbrev-ref HEAD)
}
function Start-GitAutoCommitAndPush {
[string] $status = (& git status)
if (!$status.Contains("working tree clean")) {
git add .
git commit -m "auto commit"
}
if ($PushToServer) {
git push $Server $Branch
}
}
Get-Date
if ($Once) {
Start-GitAutoCommitAndPush
}
else {
while ($true) {
Start-GitAutoCommitAndPush
Start-Sleep -Seconds $Interval
}
}