summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorLuke Diamand <luke@diamand.org>2011-05-13 20:46:00 +0100
committerJunio C Hamano <gitster@pobox.com>2011-05-13 12:59:13 -0700
commit848de9c3831f7e476ea58e3ee426aa63fb8f6870 (patch)
treec6d80ef1b5068833d20a1232a5e274d1578bfd34 /contrib
parentecdba36da6143bc00ade66b655bcff910f3e93b3 (diff)
downloadgit-848de9c3831f7e476ea58e3ee426aa63fb8f6870.tar.gz
git-p4: warn if git authorship won't be retained
If the git commits you are submitting contain changes made by other people, the authorship will not be retained. Change git-p4 to warn of this and to note that --preserve-user can be used to solve the problem (if you have suitable permissions). The warning can be disabled. Add a test case and update documentation. Signed-off-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/fast-import/git-p433
-rw-r--r--contrib/fast-import/git-p4.txt7
2 files changed, 38 insertions, 2 deletions
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index e66a7df908..98d2aee67f 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -614,6 +614,7 @@ class P4Submit(Command, P4UserMap):
self.verbose = False
self.preserveUser = gitConfig("git-p4.preserveUser").lower() == "true"
self.isWindows = (platform.system() == "Windows")
+ self.myP4UserId = None
def check(self):
if len(p4CmdList("opened ...")) > 0:
@@ -721,6 +722,25 @@ class P4Submit(Command, P4UserMap):
return 1
return 0
+ def p4UserId(self):
+ if self.myP4UserId:
+ return self.myP4UserId
+
+ results = p4CmdList("user -o")
+ for r in results:
+ if r.has_key('User'):
+ self.myP4UserId = r['User']
+ return r['User']
+ die("Could not find your p4 user id")
+
+ def p4UserIsMe(self, p4User):
+ # return True if the given p4 user is actually me
+ me = self.p4UserId()
+ if not p4User or p4User != me:
+ return False
+ else:
+ return True
+
def prepareSubmitTemplate(self):
# remove lines in the Files section that show changes to files outside the depot path we're committing into
template = ""
@@ -750,8 +770,7 @@ class P4Submit(Command, P4UserMap):
def applyCommit(self, id):
print "Applying %s" % (read_pipe("git log --max-count=1 --pretty=oneline %s" % id))
- if self.preserveUser:
- (p4User, gitEmail) = self.p4UserForCommit(id)
+ (p4User, gitEmail) = self.p4UserForCommit(id)
if not self.detectRenames:
# If not explicitly set check the config variable
@@ -890,6 +909,11 @@ class P4Submit(Command, P4UserMap):
newdiff += "+" + line
f.close()
+ if self.checkAuthorship and not self.p4UserIsMe(p4User):
+ submitTemplate += "######## git author %s does not match your p4 account.\n" % gitEmail
+ submitTemplate += "######## Use git-p4 option --preserve-user to modify authorship\n"
+ submitTemplate += "######## Use git-p4 config git-p4.skipUserNameCheck hides this message.\n"
+
separatorLine = "######## everything below this line is just the diff #######\n"
[handle, fileName] = tempfile.mkstemp()
@@ -1001,6 +1025,11 @@ class P4Submit(Command, P4UserMap):
commits.append(line.strip())
commits.reverse()
+ if self.preserveUser or (gitConfig("git-p4.skipUserNameCheck") == "true"):
+ self.checkAuthorship = False
+ else:
+ self.checkAuthorship = True
+
if self.preserveUser:
self.checkValidP4Users(commits)
diff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt
index b6986f0ebd..caa4bb3e30 100644
--- a/contrib/fast-import/git-p4.txt
+++ b/contrib/fast-import/git-p4.txt
@@ -225,6 +225,13 @@ stop. With allowMissingPerforceUsers set to true, git-p4 will use the
current user (i.e. the behavior without --preserve-user) and carry on with
the perforce commit.
+git-p4.skipUserNameCheck
+
+ git config [--global] git-p4.skipUserNameCheck false
+
+When submitting, git-p4 checks that the git commits are authored by the current
+p4 user, and warns if they are not. This disables the check.
+
Implementation Details...
=========================