git-p4: map a P4 user to Git author name and email address
Map a P4 user to a specific name and email address in Git with the "git-p4.mapUser" config. The config value must be a string adhering to the format "p4user = First Lastname <email@address.com>". Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Reviewed-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Schneider committed
Mar 1, 2016 at 11:49 UTC
10d08a149d2295a239ac7710d32c0b77492f61c3
3 files changed
+81
Documentation/git-p4.txt
+11
@@ -553,6 +553,17 @@ git-p4.keepEmptyCommits::
553
A changelist that contains only excluded files will be imported
554
as an empty commit if this boolean option is set to true.
555
556
+git-p4.mapUser::
557
+ Map a P4 user to a name and email address in Git. Use a string
558
+ with the following format to create a mapping:
559
++
560
+-------------
561
+git config --add git-p4.mapUser "p4user = First Last <mail@address.com>"
562
+-------------
563
++
564
+A mapping will override any user information from P4. Mappings for
565
+multiple P4 user can be defined.
566
+
567
Submit variables
568
~~~~~~~~~~~~~~~~
569
git-p4.detectRenames::
git-p4.py
+9
@@ -1160,6 +1160,15 @@ class P4UserMap:
1160
self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
1161
self.emails[output["Email"]] = output["User"]
1162
1163
+ mapUserConfigRegex = re.compile(r"^\s*(\S+)\s*=\s*(.+)\s*<(\S+)>\s*$", re.VERBOSE)
1164
+ for mapUserConfig in gitConfigList("git-p4.mapUser"):
1165
+ mapUser = mapUserConfigRegex.findall(mapUserConfig)
1166
+ if mapUser and len(mapUser[0]) == 3:
1167
+ user = mapUser[0][0]
1168
+ fullname = mapUser[0][1]
1169
+ email = mapUser[0][2]
1170
+ self.users[user] = fullname + " <" + email + ">"
1171
+ self.emails[email] = user
1172
1173
s = ''
1174
for (key, val) in self.users.items():
t/t9828-git-p4-map-user.sh
new
+61
@@ -0,0 +1,61 @@
1
+#!/bin/sh
2
+
3
+test_description='Clone repositories and map users'
4
+
5
+. ./lib-git-p4.sh
6
+
7
+test_expect_success 'start p4d' '
8
+ start_p4d
9
+'
10
+
11
+test_expect_success 'Create a repo with different users' '
12
+ client_view "//depot/... //client/..." &&
13
+ (
14
+ cd "$cli" &&
15
+
16
+ >author.txt &&
17
+ p4 add author.txt &&
18
+ p4 submit -d "Add file author\\n" &&
19
+
20
+ P4USER=mmax &&
21
+ >max.txt &&
22
+ p4 add max.txt &&
23
+ p4 submit -d "Add file max" &&
24
+
25
+ P4USER=eri &&
26
+ >moritz.txt &&
27
+ p4 add moritz.txt &&
28
+ p4 submit -d "Add file moritz" &&
29
+
30
+ P4USER=no &&
31
+ >nobody.txt &&
32
+ p4 add nobody.txt &&
33
+ p4 submit -d "Add file nobody"
34
+ )
35
+'
36
+
37
+test_expect_success 'Clone repo root path with all history' '
38
+ client_view "//depot/... //client/..." &&
39
+ test_when_finished cleanup_git &&
40
+ (
41
+ cd "$git" &&
42
+ git init . &&
43
+ git config --add git-p4.mapUser "mmax = Max Musterman <max@example.com> " &&
44
+ git config --add git-p4.mapUser " eri=Erika Musterman <erika@example.com>" &&
45
+ git p4 clone --use-client-spec --destination="$git" //depot@all &&
46
+ cat >expect <<-\EOF &&
47
+ no <no@client>
48
+ Erika Musterman <erika@example.com>
49
+ Max Musterman <max@example.com>
50
+ Dr. author <author@example.com>
51
+ EOF
52
+ git log --format="%an <%ae>" >actual &&
53
+ test_cmp expect actual
54
+ )
55
+'
56
+
57
+test_expect_success 'kill p4d' '
58
+ kill_p4d
59
+'
60
+
61
+test_done