-
Notifications
You must be signed in to change notification settings - Fork 25
/
git-passport.py
executable file
·83 lines (69 loc) · 2.15 KB
/
git-passport.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" git-passport is a Git command and hook written in Python to manage multiple
Git users / user identities.
"""
if __name__ == "__main__":
import os.path
import sys
from passport import (
arg,
case,
configuration,
dialog,
git
)
args = arg.release()
config_file = os.path.expanduser("~/.gitpassport")
if (
not configuration.preset(config_file) or
not configuration.validate_scheme(config_file) or
not configuration.validate_values(config_file) or
not git.infected()
):
sys.exit(1)
else:
config = configuration.release(config_file)
if config["enable_hook"]:
local_email = git.config_get(config, "local", "email")
local_name = git.config_get(config, "local", "name")
local_url = git.config_get(config, "local", "url")
if args.select:
local_name = None
local_email = None
git.config_remove(verbose=False)
if args.delete:
git.config_remove()
sys.exit(0)
if args.active:
case.active_identity(
config,
local_email,
local_name,
local_url,
style="compact"
)
sys.exit(0)
if args.passports:
dialog.print_choice(config["git_passports"])
exit(0)
if local_email and local_name:
case.active_identity(
config,
local_email,
local_name,
local_url
)
sys.exit(0)
if local_url:
candidates = case.url_exists(config, local_url)
else:
candidates = case.no_url_exists(config)
selected_id = dialog.get_input(candidates.keys())
if selected_id is not None:
git.config_set(config, candidates[selected_id]["email"], "email")
git.config_set(config, candidates[selected_id]["name"], "name")
sys.exit(0)
else:
print("git-passport is currently disabled.")
sys.exit(0)