-
Notifications
You must be signed in to change notification settings - Fork 3
/
author
executable file
·66 lines (60 loc) · 1.72 KB
/
author
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
#!/bin/bash
# Automatically setup your Author Name and Email from your config
#
# In your config, add a per URL user section. Example:
#
# [user]
# name=Bowser
# email=author@example.com
#
# [user "https://repo.example.net"]
# name=Luigi Mario
# email=luigi@example.net
#
# [user "https://repo.example.org"]
# name=Mario Mario
# email=mario@example.org
#
# [user "ssh://git@gitlab.example.com"]
# name=Mario Luigi
# email=mariol@example.com
#
# ---
#
# Now we can use `git config --get-urlmatch` section.key URL to retrieve the value.
#
# git config --get-urlmatch user.name "https://repo.example.org"
# git config --get-urlmatch user.name "https://repo.example.net"
# git config user.name
#
# urlmatch will select the closest matching url
#
# NOTE: This is problematic for Gitlab's default location format:
# [user@]host.xz:path/to/repo.git/ so you will have to explicitly use the
# SSH form: ssh://user@host.xz/path/to/repo.git
# since --urlmatch depends on having the scheme (https://, ssh://, ftp:// etc.)
#
# ---
#
# To check the URL of our repo, we can use ls-remote
# `git ls-remote --get-url 'origin'`
#
# ---
#
# Finally, we should be able to
#
# originurl=$(git ls-remote --get-url 'origin')
# authorname=$(git config --get-urlmatch user.name $originurl)
# authoremail=$(git config --get-urlmatch user.email $originurl)
#
# Get user name and email from config -- user.<url>.name, user.<url>.email --
# and set it locally.
originurl=$(git ls-remote --get-url 'origin')
username=$(git config --get-urlmatch user.name $originurl)
useremail=$(git config --get-urlmatch user.email $originurl)
if [[ -n $username ]] ; then
git config --local user.name $username
fi
if [[ -n $useremail ]] ; then
git config --local user.email $useremail
fi