git-p4.py: add support for filetype change
After changing the type of a file in the git repository, it is not possible to "git p4 publish" the commit to perforce. This is due to the fact that the git "T" status is not handled in git-p4.py. This can typically occur when replacing an existing file with a symbolic link. The "T" modifier is now supported in git-p4.py. When a file type has changed, inform perforce with the "p4 edit -f auto" command. Signed-off-by: Romain Picard <romain.picard@oakbits.com> Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Romain Picard committed
Jan 12, 2016 at 13:43 UTC
a02b8bc4d7525896b5f20553dc10e7ada257046a
2 files changed
+73
-2
git-p4.py
+7
-2
@@ -253,8 +253,8 @@ def p4_add(f):
253
def p4_delete(f):
254
p4_system(["delete", wildcard_encode(f)])
255
256
-def p4_edit(f):
257
- p4_system(["edit", wildcard_encode(f)])
256
+def p4_edit(f, *options):
257
+ p4_system(["edit"] + list(options) + [wildcard_encode(f)])
258
259
def p4_revert(f):
260
p4_system(["revert", wildcard_encode(f)])
@@ -1554,6 +1554,7 @@ class P4Submit(Command, P4UserMap):
1554
1555
diff = read_pipe_lines("git diff-tree -r %s \"%s^\" \"%s\"" % (self.diffOpts, id, id))
1556
filesToAdd = set()
1557
+ filesToChangeType = set()
1558
filesToDelete = set()
1559
editedFiles = set()
1560
pureRenameCopy = set()
@@ -1614,6 +1615,8 @@ class P4Submit(Command, P4UserMap):
1615
os.unlink(dest)
1616
filesToDelete.add(src)
1617
editedFiles.add(dest)
1618
+ elif modifier == "T":
1619
+ filesToChangeType.add(path)
1620
else:
1621
die("unknown modifier %s for %s" % (modifier, path))
1622
@@ -1673,6 +1676,8 @@ class P4Submit(Command, P4UserMap):
1676
#
1677
system(applyPatchCmd)
1678
1679
+ for f in filesToChangeType:
1680
+ p4_edit(f, "-t", "auto")
1681
for f in filesToAdd:
1682
p4_add(f)
1683
for f in filesToDelete:
t/t9827-git-p4-change-filetype.sh
new
+66
@@ -0,0 +1,66 @@
1
+#!/bin/sh
2
+
3
+test_description='git p4 support for file type change'
4
+
5
+. ./lib-git-p4.sh
6
+
7
+test_expect_success 'start p4d' '
8
+ start_p4d
9
+'
10
+
11
+test_expect_success 'create files' '
12
+ (
13
+ cd "$cli" &&
14
+ p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
15
+ cat >file1 <<-EOF &&
16
+ text without any funny substitution business
17
+ EOF
18
+ cat >file2 <<-EOF &&
19
+ second file whose type will change
20
+ EOF
21
+ p4 add file1 file2 &&
22
+ p4 submit -d "add files"
23
+ )
24
+'
25
+
26
+test_expect_success SYMLINKS 'change file to symbolic link' '
27
+ git p4 clone --dest="$git" //depot@all &&
28
+ test_when_finished cleanup_git &&
29
+ (
30
+ cd "$git" &&
31
+ git config git-p4.skipSubmitEdit true &&
32
+
33
+ rm file2 &&
34
+ ln -s file1 file2 &&
35
+ git add file2 &&
36
+ git commit -m "symlink file1 to file2" &&
37
+ git p4 submit &&
38
+ p4 filelog -m 1 //depot/file2 >filelog &&
39
+ grep "(symlink)" filelog
40
+ )
41
+'
42
+
43
+test_expect_success SYMLINKS 'change symbolic link to file' '
44
+ git p4 clone --dest="$git" //depot@all &&
45
+ test_when_finished cleanup_git &&
46
+ (
47
+ cd "$git" &&
48
+ git config git-p4.skipSubmitEdit true &&
49
+
50
+ rm file2 &&
51
+ cat >file2 <<-EOF &&
52
+ This is another content for the second file.
53
+ EOF
54
+ git add file2 &&
55
+ git commit -m "re-write file2" &&
56
+ git p4 submit &&
57
+ p4 filelog -m 1 //depot/file2 >filelog &&
58
+ grep "(text)" filelog
59
+ )
60
+'
61
+
62
+test_expect_success 'kill p4d' '
63
+ kill_p4d
64
+'
65
+
66
+test_done