generated from dycw/template-generic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.fish
More file actions
1434 lines (1300 loc) · 37.4 KB
/
git.fish
File metadata and controls
1434 lines (1300 loc) · 37.4 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env fish
if ! status is-interactive
exit
end
#### config ###################################################################
function fish-git
$EDITOR $HOME/dotfiles/fish/git.fish
end
function git-ignore
$EDITOR $(git repo-root)/pyproject.toml
end
#### git ######################################################################
# add
function ga
__git_add $argv
end
function gaf
__git_add $argv --force
end
function gap
git add --all --patch $argv
end
function __git_add
argparse force -- $argv; or return $status
set -l args
if test (count $argv) -eq 0
set args $args --all
else
set args $args $argv
end
if test -n "$_flag_force"
set args $args --force
end
git add $args
end
# branch
function gb
git branch-default
end
function gbd
if test (count $argv) -eq 0
__git_branch_fzf_local --multi | while read branch
git branch-delete $branch
end
else
for branch in $argv
git branch-delete $branch
end
end
end
function gbdr
git fetch-default; or return $status
if test (count $argv) -eq 0
__git_branch_fzf_remote --multi | xargs -r -I{} git push --delete origin "{}"
else
git push --delete origin $argv
end
end
function gbm
if test (count $argv) -eq 0
echo "'gbm' expected [1..) arguments BRANCH; got $(count $argv)" >&2; and return 1
end
git branch -m $argv
end
function __git_branch_fzf_local
argparse multi -- $argv; or return $status
set -l args
if test -n "$_flag_multi"
set args $args --multi
end
git branch --format='%(refname:short)' | fzf $args
end
function __git_branch_fzf_remote
argparse multi -- $argv; or return $status
set -l args
if test -n "$_flag_multi"
set args $args --multi
end
git branch --color=never --remotes | awk '!/- >/' | fzf $args \
| sed -E 's|^[[:space:]]*origin/||'
end
function __git_branch_purge_local
git branch -vv | awk '/: gone]/{print $1}' | xargs -r git branch -D
end
# checkout
function gcb
set -l args
if test (count $argv) -eq 0
else if test (count $argv) -eq 1
set args $args --title $argv[1]
else if test (count $argv) -eq 2
set args $args --title $argv[1] --num $argv[2]
else if test (count $argv) -eq 3
set args $args --title $argv[1] --num $argv[2] --part
else
echo "'gcb' expected [0..3] arguments TITLE NUM PART; got $(count $argv)" >&2; and return 1
end
__git_checkout_open $args
end
function gcbr
set -l branch
if test (count $argv) -eq 0
set branch (__git_branch_fzf_remote)
else if test (count $argv) -eq 1
set branch $argv[1]
else
echo "'gcbr' expected [0..1] arguments BRANCH; got "(count $argv) >&2; and return 1
end
git checkout -b $branch -t origin/$branch
end
function gco
set -l branch
if test (count $argv) -eq 0
set branch (__git_branch_fzf_local)
else
set branch $argv[1]
end
git checkout $branch
end
function gcof
if test (count $argv) -eq 0
git checkout -- .
else
if git is-valid-ref $argv[1]
git fetch-default; or return $status
git checkout $argv[1] -- $argv[2..]
else
git checkout -- $argv
end
end
end
function gcfm
git fetch-default; or return $status
set -l branch (git default-remote-branch); or return $status
git checkout $branch -- $argv
end
function gm
set -l branch (git default-local-branch); or return $status
__git_checkout_close $branch
end
function gmd
set -l branch (git default-local-branch); or return $status
__git_checkout_close $branch --delete
end
function gmx
set -l branch (git default-local-branch); or return $status
__git_checkout_close $branch --delete --exit
end
function __git_checkout_open
argparse title= num= part -- $argv; or return $status
git fetch-default; or return $status
set -l branch
if test -z "$_flag_title"; and test -z "$_flag_num"
set branch dev
else if test -n "$_flag_title"; and test -z "$_flag_num"
set branch (__clean_branch_name $_flag_title); or return $status
else if test -z "$_flag_title"; and test -n "$_flag_num"
set branch $_flag_num
else
set branch "$_flag_num-$(__clean_branch_name $_flag_title)"; or return $status
end
git checkout -b $branch $(git default-remote-branch); or return $status
git commit --allow-empty --message="$(__auto_msg)" --no-verify; or return $status
__git_push --no-verify; or return $status
set -l title
if test -n "$_flag_title"
set title $_flag_title
else
set title (__auto_msg); or return $status
end
set -l args
if test -n "$_flag_num"
if test -n "$_flag_part"
set args $args "Part of $_flag_num"
else
set args $args "Closes $_flag_num"
end
end
__git_create --title $title $args
end
function __git_checkout_close
if test (count $argv) -eq 0
echo "'__git_checkout_close' expected [1..) arguments TARGET; got $(count $argv)" >&2; and return 1
end
argparse delete delete-remote exit -- $argv; or return $status
set -l target $argv[1]
set -l original (git current-branch); or return $status
git checkout $target; or return $status
git pull-default; or return $status
if test -n "$_flag_delete"
git branch-delete $original
end
if test -n "$_flag_delete_remote"
git branch-delete-remote $original
end
if test -n "$_flag_exit"
exit
end
end
# cherry-pick
function gcp
git cherry-pick $argv
end
# clone
function gcl
if test (count $argv) -eq 0
echo "'gcl' expected [1..2) arguments REPO DIR; got $(count $argv)" >&2; and return 1
end
set -l args
if test (count $argv) -ge 2
set args $args --dir $argv[2]
end
__git_clone --repo $argv[1] $args
end
function __git_clone
argparse repo= dir= -- $argv; or return $status
set -l dir
if test -n "$_flag_dir"
set dir $_flag_dir
else
set dir (basename (string replace -r '\.git$' '' -- $_flag_repo))
end
git clone --recurse-submodules $_flag_repo $dir; or return $status
set -l current (pwd)
cd $dir
if type -q prek
prek install; or return $status
end
if type -q direnv
if test -f .env; or test -f .envrc
direnv allow .
end
end
cd $current
end
# commit + push
function gc
__git_commit_push
end
function gcn
__git_commit_push --no-verify
end
function gcf
__git_commit_push --force
end
function gcnf
__git_commit_push --no-verify --force
end
function gcw
__git_commit_push --web
end
function gcnw
__git_commit_push --no-verify --web
end
function gcfw
__git_commit_push --force --web
end
function gcnfw
__git_commit_push --no-verify --force --web
end
function gce
__git_commit_push --exit
end
function gcne
__git_commit_push --no-verify --exit
end
function gcfe
__git_commit_push --force --exit
end
function gcnfe
__git_commit_push --no-verify --force --exit
end
function gcx
__git_commit_push --web --exit
end
function gcnx
__git_commit_push --no-verify --web --exit
end
function gcfx
__git_commit_push --force --web --exit
end
function gcnfx
__git_commit_push --no-verify --force --web --exit
end
function __git_commit_push
if git is-clean
return 0
end
argparse no-verify force web exit -- $argv; or return $status
set -l commit_args
if test $_flag_no_verify
set commit_args $commit_args --no-verify
end
git commit --message=$(__auto_msg) $commit_args; or return $status
set -l push_args
if test $_flag_force
set push_args $push_args --force
end
if test $_flag_no_verify
set push_args $push_args --no-verify
end
if test $_flag_web
set push_args $push_args --web
end
if test $_flag_exit
set push_args $push_args --exit
end
__git_push $push_args
end
function __git_commit_until_push
argparse no-verify force web exit -- $argv; or return $status
set -l commit_args
if test -n "$_flag_no_verify"
set commit_args $commit_args --no-verify
end
set -l proceed 0
for i in (seq 1 3)
if test $proceed -eq 0
ga $argv; or return $status
__git_commit_push $commit_args
if test $status -eq 0; and git is-clean
set proceed 1
end
end
end
if test $proceed -eq 0
echo "'__git_commit_until_push' failed after $i attempts" >&2; and return 1
end
set -l push_args
if test $_flag_force
set push_args $push_args --force
end
if test $_flag_no_verify
set push_args $push_args --no-verify
end
if test $_flag_web
set push_args $push_args --web
end
if test $_flag_exit
set push_args $push_args --exit
end
__git_push $push_args
end
# diff
function gd
git diff $argv
end
function gdc
git diff --cached $argv
end
function gdm
if test (count $argv) -ge 1
git diff (git default-remote-branch) -- $argv
else
git diff (git default-remote-branch)
end
end
# fetch
function gf
git fetch-default
end
# log
function gl
set -l args
if test (count $argv) -eq 0
set args $args -n 20
else if string match -qr '^[0-9]+$' -- $argv[1]; and test $argv[1] -ge 1
set args $args -n $argv[1]
end
git log-default $args
end
# mv
function gmv
git mv $argv
end
# pull
function gpl
git pull-default $argv
end
# push
function gp
__git_push
end
function gpn
__git_push --no-verify
end
function gpf
__git_push --force
end
function gpfn
__git_push --force --no-verify
end
function gpw
__git_push --web
end
function gpnw
__git_push --no-verify --web
end
function gpfw
__git_push --force --web
end
function gpfnw
__git_push --force --no-verify --web
end
function gpe
__git_push --exit
end
function gpne
__git_push --no-verify --exit
end
function gpfe
__git_push --force --exit
end
function gpfne
__git_push --force --no-verify --exit
end
function gpx
__git_push --web --exit
end
function gpnx
__git_push --no-verify --web --exit
end
function gpfx
__git_push --force --web --exit
end
function gpfnx
__git_push --force --no-verify --web --exit
end
function __git_push
argparse force no-verify web exit -- $argv; or return $status
set -l args
if test -n "$_flag_force"
set args $args --force
end
set args $args --set-upstream origin (git current-branch); or return $status
if test -n "$_flag_no_verify"
set args $args --no-verify
end
git push $args; or return $status
if test -n "$_flag_web"
__git_view; or return $status
end
if test -n "$_flag_exit"
exit
end
end
# rebase
function grb
__git_rebase
end
function grbp
__git_rebase --push
end
function grbw
__git_rebase --push --web
end
function __git_rebase
argparse push web -- $argv; or return $status
git fetch-default; or return $status
set -l branch (git default-remote-branch); or return $status
git rebase --strategy=recursive --strategy-option=theirs $branch; or return $status
if test -n "$_flag_push"
prek run --all-files
set -l args
if test -n "$_flag_web"
set args $args --web
end
__git_all --no-verify --force $args
end
end
function grba
git rebase --abort $argv
end
function grbc
git rebase --continue $argv
end
function grbs
git rebase --skip $argv
end
# remote
function add-remote
if test (count $argv) -le 1
echo "'add-remote' expected [2..) arguments NAME URL; got $(count $argv)" >&2; and return 1
end
git remote add $argv
git remote set-url --push $argv
end
function remove-remote
if test (count $argv) -eq 0
echo "'remove-remote' expected [1..) arguments NAME; got $(count $argv)" >&2; and return 1
end
git remote remove $argv
end
function set-remote
if test (count $argv) -le 1
echo "'set-remote' expected [2..) arguments NAME URL; got $(count $argv)" >&2; and return 1
end
git remote set-url $argv; or return $status
git remote set-url --push $argv
end
function grem
git remote -v
end
function __remote_is
if test (count $argv) -eq 0
echo "'__remote_is' expected [1..) arguments REMOTE; got $(count $argv)" >&2; and return 1
end
if git remote-name | grep -q $argv[1]
return 0
else
return 1
end
end
function __remote_is_github
__remote_is github
end
function __remote_is_gitlab
__remote_is gitlab
end
function __remote_is_gitea
__remote_is gitea or __remote_is ts.net
end
# reset
function gr
git reset $argv
end
function grhom
set -l branch (git default-remote-branch); or return $status
git reset --hard $branch $argv
end
function grp
git reset --patch $argv
end
function gsq
git fetch-default; or return $status
set -l branch (git default-remote-branch); or return $status
git reset --soft $(git merge-base $branch HEAD)
end
# restore
function gres
git restore $argv
end
function gun
git restore --staged $argv
end
# rev-parse
function cdr
cd (git repo-root)
end
# rm
function grm
__git_rm $argv
end
function grmc
__git_rm $argv --cached
end
function __git_rm
argparse cached -- $argv; or return $status
set -l args
if test -n "$_flag_cached"
set args $args --cached
end
git rm -rf $argv
end
# switch
function gsw
__git_switch $argv
end
function gswc
if test (count $argv) -eq 0
echo "'gswc' expected [1..) arguments BRANCH; got $(count $argv)" >&2; and return 1
end
__git_switch --create=$argv[1] $argv[2..]
end
function __git_switch
argparse create= -- $argv; or return $status
set -l args
if test -n "$_flag_create"
set args $args --create="$_flag_create"
end
git switch $args $argv
end
# stash
function gst
git stash $argv
end
function gstd
git stash drop $argv
end
function gstp
git stash pop $argv
end
# status
function gs
git status $argv
end
function wg
watch --color --interval 2 --no-title --no-wrap -- '
echo "==== status ==================================================================="
git -c color.ui=always status --short
if ! git diff --quiet; then
printf "\n==== diff =====================================================================\n"
git -c color.ui=always diff --stat
fi
branch=$(printf "%-6s" "$(git default-local-branch)")
if ! git diff-remote --quiet; then
printf "\n==== diff origin/$branch =======================================================\n"
git -c color.ui=always diff-remote --stat
fi
if (git remote-name | grep -q github) && (command -v gh >/dev/null 2>&1); then
printf "\n==== github ==================================================================="
gh pr status
fi
'
end
# submodule
function gsa
git submodule add $argv
end
function gsu
git submodule-update
end
# tag
function gta
if test (count $argv) -eq 0
if type -q bump-my-version
git tag-add (bump-my-version show current_version) HEAD
else
echo "'gta' expected 'bump-my-version' to be available" >&2; and return 1
end
else if test (count $argv) -eq 1
git tag-add $argv[1] HEAD
else if test (math (count $argv) % 2) -eq 0
while test (count $argv) -ge 2
git tag-add $argv[1..2]
set argv $argv[3..-1]
end
else
echo "'gta' expected 0, 1 or an even number of arguments; got $(count $argv)" >&2; and return 1
end
end
function gtd
git tag-delete $argv
end
function __git_tag_push
if test (count $argv) -le 1
echo "'__git_tag_push' expected [2..) arguments TAG SHA; got $(count $argv)" >&2; and return 1
end
set -l tag $argv[1]
set -l sha $argv[2]
git tag -a "$tag" "$sha" -m "$tag"; or return $status
git push --tags --force --set-upstream origin; or return $status
end
#### github ###################################################################
function __github_create
argparse title= body= -- $argv; or return $status
set -l title
if test -n "$_flag_title"
set title $_flag_title
else
set title (__auto_msg); or return $status
end
set -l body
if test -n "$_flag_body"
set body $_flag_body
else
set body .
end
gh pr create --title $title --body $body
end
function __github_edit
argparse title= body= -- $argv; or return $status
set -l args
if test -n "$_flag_title"
set args $args --title $_flag_title
end
if test -n "$_flag_body"
set args $args --body $_flag_body
end
gh pr edit $args
end
function __github_exists
set -l branch (git current-branch); or return $status
set -l num (gh pr list --head=$branch --json number --jq '. | length'); or return $status
if test $num -eq 0
return 1
else if test $num -eq 1
return 0
else
echo "'__github_exists' expected a unique PR for '$branch'; got $num" >&2; and return 1
end
end
function __github_merge
argparse exit -- $argv; or return $status
set -l curr_branch (git current-branch); or return $status
if not __github_exists
echo "'__github_merge' could not find an open PR for '$curr_branch'" >&2; and return 1
end
set -l repo (git repo-name); or return $status
set -l start (date +%s); or return $status
set -l elapsed
gh pr merge --auto --delete-branch --squash; or return $status
while __github_merging
set elapsed (math (date +%s) - $start)
echo "$repo/$curr_branch is still merging... ($elapsed s)"
sleep 1
end
set -l args
if test -n "$_flag_exit"
set args $args --exit
end
set -l def_branch (git default-local-branch); or return $status
__git_checkout_close $def_branch --delete $args
end
function __github_merging
set -l branch (git current-branch); or return $status
set -l state (gh pr view --json state | jq -r .state); or return $status
if test -z "$state" -o "$state" != OPEN
return 1
end
set -l repo (gh repo view --json nameWithOwner -q .nameWithOwner)
if gh api repos/$repo/branches/$branch >/dev/null
return 0
else
return 1
end
end
function __github_view
if gh pr ready >/dev/null 2>&1
gh pr view -w
else if type -q gitweb
gitweb
else
set -l branch (git current-branch); or return $status
echo "'__github_view' could not find an open PR for '$branch', nor could it find 'gitweb'" >&2; and return 1
end
end
#### gitlab ###################################################################
function __gitlab_create
argparse title= description= -- $argv; or return $status
set -l args
if test -n "$_flag_title"
set title $_flag_title
else
set title (__auto_msg); or return $status
end
if test -n "$_flag_description"
set description $_flag_description
else
set description .
end
glab mr create --push --remove-source-branch --squash-before-merge $args --title $title --description $description
end
function __gitlab_merge
argparse exit -- $argv; or return $status
set -l repo (git repo-name); or return $status
set -l curr_branch (git current-branch); or return $status
set -l start (date +%s); or return $status
set -l i 0
while true
set -l json (__gitlab_mr_json 2>&1)
set -l json_status $status
if test $i -eq 0; and test $json_status -eq 100
echo "'__gitlab_merge' expected an MR for '$curr_branch'; got none" >&2; and return 1
else if test $i -ge 1; and test $json_status -eq 100
break
else if test $json_status -eq 101
echo "'__gitlab_merge' expected a unique MR for '$curr_branch'" >&2; and return 1
else if test $json_status -ne 0
echo "'__gitlab_merge' expected an exit status of 0, 100 or 101; got $json_status" >&2; and return 1
end
set -l state (echo $json | jq -r .state); or return $status
if test $state != opened
echo "'__gitlab_merge' expected the MR for '$curr_branch' to be opened; got '$state'" >&2; and return 1
end
set -l merge_status (__gitlab_mr_merge_status $json); or return $status
if test "$merge_status" = conflict; or test "$merge_status" = need_rebase; or test "$merge_status" = 'not open'
echo "'__gitlab_merge' cannot merge the MR for '$curr_branch' because of merge status '$merge_status'" >&2; and return 1
end
glab mr merge --remove-source-branch --squash --yes &>/dev/null
set i (math $i+1)
set -l json (__gitlab_mr_json 2>&1)
if test $status -eq 100
break
end
set -l merge_status (__gitlab_mr_merge_status $json); or return $status
set -l elapsed (math (date +%s) - $start)
echo "'$repo/$curr_branch' is still merging... ($i, $merge_status, $elapsed s)"
sleep 1
end
set -l def_branch (git default-local-branch); or return $status
set -l args
if test -n "$_flag_exit"
set args $args --exit
end
__git_checkout_close $def_branch --delete $args
end
function __gitlab_update
argparse title= description= -- $argv; or return $status
set -l args
if test -n "$_flag_title"
set args $args --title $_flag_title
end
if test -n "$_flag_body"
set args $args --description $_flag_description
end
set -l num (__gitlab_mr_num); or return $status
glab mr update $num $args
end
function __gitlab_mr_json
set -l branch (git current-branch); or return $status
set -l json (glab mr list --output=json --source-branch=$branch); or return $status
set -l num (printf %s $json | jq length); or return $status
if test $num -eq 0
echo "'__gitlab_mr_json' expected an MR for '$branch'; got none" >&2; and return 100
else if test $num -eq 1
printf "%s\n" "$json" | jq .[0]
else
echo "'__gitlab_mr_json' expected a unique MR for '$branch'; got $num" >&2; and return 101
end
end
function __gitlab_mr_merge_status
if test (count $argv) -eq 0
echo "'__gitlab_mr_merge_status' expected [1..) arguments JSON; got $(count $argv)" >&2; and return 1
end
echo (string collect $argv) | jq -r .detailed_merge_status
end
function __gitlab_mr_num
if test (count $argv) -eq 0
echo "'__gitlab_mr_num' expected [1..) arguments JSON; got $(count $argv)" >&2; and return 1
end
echo (string collect $argv) | jq -r .iid
end
function __gitlab_view
set -l json (__gitlab_mr_json 2>&1)
if test $status = 0
set -l num (__gitlab_mr_num $json)
glab mr view $num --web
else if type -q gitweb
gitweb
else
set -l branch $(git current-branch); or return $status
echo "'__gitlab_view' could not find an open MR for '$branch', nor could it find 'gitweb'" >&2; and return 1
end
end
#### gitea ####################################################################
function __gitea_create
argparse title= description= -- $argv; or return $status
set -l title
if test -n "$_flag_title"
set title $_flag_title
else
set title (__auto_msg); or return $status
end
set -l args
if test -n "$_flag_description"
set args $args --description $_flag_description
end
tea pulls create --title $title $aGS
end
function __gitea_exists
set -l branch (git current-branch); or return $status
__gitea_pulls_json >/dev/null 2>&1
set -l json_status $status
if test $json_status -eq 0
return 0
else if test $json_status -eq 100
return 1
else if test $json_status -eq 101
echo "'__gitea_exists' expected a unique MR for '$branch'" >&2; and return 1
else
echo "'__gitea_exists' expected an exit status of 0, 100 or 101; got $json_status" >&2; and return 1
end
end
function __gitea_merge
argparse exit -- $argv; or return $status
set -l curr_branch (git current-branch); or return $status
if not __gitea_exists
echo "'__gitea_merge' could not find an open PR for '$curr_branch'" >&2; and return 1
end
set -l index (__gitea_pulls_index); or return $status
set -l repo (git repo-name); or return $status
set -l start (date +%s); or return $status
set -l i 0
set -l elapsed
while __gitea_exists
if tea pull merge --style squash $index >/dev/null 2>&1; and not __gitea_exists
break
end
set i (math $i+1)
set elapsed (math (date +%s) - $start)
echo "'$repo/$curr_branch' is still merging... ($i, $elapsed s)"