-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgit_bare_config_allow_rewrite.sh
More file actions
104 lines (84 loc) · 2.38 KB
/
git_bare_config_allow_rewrite.sh
File metadata and controls
104 lines (84 loc) · 2.38 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
#!/usr/bin/env bash
# USAGE:
# git_bare_config_allow_rewrite.sh <dir> [<dir-name-pattern>]
# Description:
# Script to allow rewrite in a bare git repository or in a list of git bare
# repositories searched by the `find` pattern.
# Examples:
# >
# git_bare_config_allow_rewrite.sh /home/git "*.git"
# Script both for execution and inclusion.
[[ -n "$BASH" ]] || return 0 || exit 0 # exit to avoid continue if the return can not be called
function call()
{
local IFS=$' \t'
echo ">$*"
"$@"
}
# Based on:
# https://stackoverflow.com/questions/71928010/makefile-on-windows-is-there-a-way-to-force-make-to-use-the-mingw-find-exe/76393735#76393735
#
function detect_find()
{
SHELL_FIND=find
local IFS
# NOTE:
# The `${path,,}` or `${path^^}` form has issues:
# 1. Does not handle a unicode string case conversion correctly (unicode characters translation in words).
# 2. Supported in Bash 4+.
# detect `find.exe` in Windows behind `$SYSTEMROOT\System32\find.exe`
if which where >/dev/null 2>&1; then
local old_shopt="$(shopt -p nocasematch)" # read state before change
if [[ "$old_shopt" != 'shopt -s nocasematch' ]]; then
shopt -s nocasematch
else
old_shopt=''
fi
IFS=$'\r\n'; for path in `where find 2>/dev/null`; do # IFS - with trim trailing line feeds
case "$path" in # with case insensitive comparison
"$SYSTEMROOT"\\*) ;;
"$WINDIR"\\*) ;;
*)
SHELL_FIND="$path"
break
;;
esac
done
if [[ -n "$old_shopt" ]]; then
eval $old_shopt
fi
fi
}
function git_bare_config_allow_rewrite()
{
local dir="$1"
local name_pttn="$2"
local git_path
local IFS
if [[ -n "$name_pttn" ]]; then
detect_find
# cygwin workaround
SHELL_FIND="${SHELL_FIND//\\//}"
IFS=$'\r\n'; for git_path in `"$SHELL_FIND" "$dir" -name "$name_pttn" -type d`; do # IFS - with trim trailing line feeds
call pushd "$git_path" && {
call git config receive.denynonfastforwards false
call popd
}
done
else
call pushd "$dir" && {
call git config receive.denynonfastforwards false
call popd
}
fi
return 0
}
# shortcut
function git_bc_al_rw()
{
git_bare_config_allow_rewrite "$@"
}
if [[ -z "$BASH_LINENO" || BASH_LINENO[0] -eq 0 ]]; then
# Script was not included, then execute it.
git_bare_config_allow_rewrite "$@"
fi