git-p4: honor --changesfile option and test

When an explicit list of changes is given, it makes no sense to use @all or @3,5 or any of the other p4 revision specifiers. Make the code notice when this happens, instead of just ignoring --changesfile. Test it. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Dec 24, 2011 at 21:07 UTC 58c8bc7c1aa0c7cf71c524cc4531a19ef72ea706
2 files changed +38 -1
contrib/fast-import/git-p4
+15 -1
@@ -2024,6 +2024,17 @@ class P4Sync(Command, P4UserMap):
2024 revision = ""
2025 self.users = {}
2026
2027 + # Make sure no revision specifiers are used when --changesfile
2028 + # is specified.
2029 + bad_changesfile = False
2030 + if len(self.changesFile) > 0:
2031 + for p in self.depotPaths:
2032 + if p.find("@") >= 0 or p.find("#") >= 0:
2033 + bad_changesfile = True
2034 + break
2035 + if bad_changesfile:
2036 + die("Option --changesfile is incompatible with revision specifiers")
2037 +
2038 newPaths = []
2039 for p in self.depotPaths:
2040 if p.find("@") != -1:
@@ -2040,7 +2051,10 @@ class P4Sync(Command, P4UserMap):
2051 revision = p[hashIdx:]
2052 p = p[:hashIdx]
2053 elif self.previousDepotPaths == []:
2043 - revision = "#head"
2054 + # pay attention to changesfile, if given, else import
2055 + # the entire p4 tree at the head revision
2056 + if len(self.changesFile) == 0:
2057 + revision = "#head"
2058
2059 p = re.sub ("\.\.\.$", "", p)
2060 if not p.endswith("/"):
t/t9806-git-p4-options.sh
+23
@@ -38,6 +38,29 @@ test_expect_success 'clone --branch' '
38 )
39 '
40
41 +test_expect_success 'clone --changesfile' '
42 + cf="$TRASH_DIRECTORY/cf" &&
43 + test_when_finished "rm \"$cf\"" &&
44 + printf "1\n3\n" >"$cf" &&
45 + "$GITP4" clone --changesfile="$cf" --dest="$git" //depot &&
46 + test_when_finished cleanup_git &&
47 + (
48 + cd "$git" &&
49 + git log --oneline p4/master >lines &&
50 + test_line_count = 2 lines
51 + test_path_is_file file1 &&
52 + test_path_is_missing file2 &&
53 + test_path_is_file file3
54 + )
55 +'
56 +
57 +test_expect_success 'clone --changesfile, @all' '
58 + cf="$TRASH_DIRECTORY/cf" &&
59 + test_when_finished "rm \"$cf\"" &&
60 + printf "1\n3\n" >"$cf" &&
61 + test_must_fail "$GITP4" clone --changesfile="$cf" --dest="$git" //depot@all
62 +'
63 +
64 test_expect_success 'kill p4d' '
65 kill_p4d
66 '