Skip to content

Commit 51334bb

Browse files
luked99gitster
authored andcommitted
git-p4: support excluding paths on sync
The clone subcommand has long had support for excluding subdirectories, but sync has not. This is a nuisance, since as soon as you do a sync, any changed files that were initially excluded start showing up. Move the "exclude" command-line option into the parent class; the actual behavior was already present there so it simply had to be exposed. Signed-off-by: Luke Diamand <[email protected]> Reviewed-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fdf96a2 commit 51334bb

File tree

3 files changed

+84
-13
lines changed

3 files changed

+84
-13
lines changed

Documentation/git-p4.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ Git repository:
241241
Use a client spec to find the list of interesting files in p4.
242242
See the "CLIENT SPEC" section below.
243243

244+
-/ <path>::
245+
Exclude selected depot paths when cloning or syncing.
246+
244247
Clone options
245248
~~~~~~~~~~~~~
246249
These options can be used in an initial 'clone', along with the 'sync'
@@ -254,9 +257,6 @@ options described above.
254257
--bare::
255258
Perform a bare clone. See linkgit:git-clone[1].
256259

257-
-/ <path>::
258-
Exclude selected depot paths when cloning.
259-
260260
Submit options
261261
~~~~~~~~~~~~~~
262262
These options can be used to modify 'git p4 submit' behavior.

git-p4.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,10 @@ def __init__(self):
19151915
optparse.make_option("--keep-path", dest="keepRepoPath", action='store_true',
19161916
help="Keep entire BRANCH/DIR/SUBDIR prefix during import"),
19171917
optparse.make_option("--use-client-spec", dest="useClientSpec", action='store_true',
1918-
help="Only sync files that are included in the Perforce Client Spec")
1918+
help="Only sync files that are included in the Perforce Client Spec"),
1919+
optparse.make_option("-/", dest="cloneExclude",
1920+
action="append", type="string",
1921+
help="exclude depot path"),
19191922
]
19201923
self.description = """Imports from Perforce into a git repository.\n
19211924
example:
@@ -1950,6 +1953,12 @@ def __init__(self):
19501953
if gitConfig("git-p4.syncFromOrigin") == "false":
19511954
self.syncWithOrigin = False
19521955

1956+
# This is required for the "append" cloneExclude action
1957+
def ensure_value(self, attr, value):
1958+
if not hasattr(self, attr) or getattr(self, attr) is None:
1959+
setattr(self, attr, value)
1960+
return getattr(self, attr)
1961+
19531962
# Force a checkpoint in fast-import and wait for it to finish
19541963
def checkpoint(self):
19551964
self.gitStream.write("checkpoint\n\n")
@@ -3101,22 +3110,13 @@ def __init__(self):
31013110
optparse.make_option("--destination", dest="cloneDestination",
31023111
action='store', default=None,
31033112
help="where to leave result of the clone"),
3104-
optparse.make_option("-/", dest="cloneExclude",
3105-
action="append", type="string",
3106-
help="exclude depot path"),
31073113
optparse.make_option("--bare", dest="cloneBare",
31083114
action="store_true", default=False),
31093115
]
31103116
self.cloneDestination = None
31113117
self.needsGit = False
31123118
self.cloneBare = False
31133119

3114-
# This is required for the "append" cloneExclude action
3115-
def ensure_value(self, attr, value):
3116-
if not hasattr(self, attr) or getattr(self, attr) is None:
3117-
setattr(self, attr, value)
3118-
return getattr(self, attr)
3119-
31203120
def defaultDestination(self, args):
31213121
## TODO: use common prefix of args?
31223122
depotPath = args[0]

t/t9817-git-p4-exclude.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh
2+
3+
test_description='git p4 tests for excluded paths during clone and sync'
4+
5+
. ./lib-git-p4.sh
6+
7+
test_expect_success 'start p4d' '
8+
start_p4d
9+
'
10+
11+
# Create a repo with the structure:
12+
#
13+
# //depot/wanted/foo
14+
# //depot/discard/foo
15+
#
16+
# Check that we can exclude a subdirectory with both
17+
# clone and sync operations.
18+
19+
test_expect_success 'create exclude repo' '
20+
(
21+
cd "$cli" &&
22+
mkdir -p wanted discard &&
23+
echo wanted >wanted/foo &&
24+
echo discard >discard/foo &&
25+
p4 add wanted/foo discard/foo &&
26+
p4 submit -d "initial revision"
27+
)
28+
'
29+
30+
test_expect_success 'check the repo was created correctly' '
31+
test_when_finished cleanup_git &&
32+
git p4 clone --dest="$git" //depot/...@all &&
33+
(
34+
cd "$git" &&
35+
test_path_is_file wanted/foo &&
36+
test_path_is_file discard/foo
37+
)
38+
'
39+
40+
test_expect_success 'clone, excluding part of repo' '
41+
test_when_finished cleanup_git &&
42+
git p4 clone -//depot/discard/... --dest="$git" //depot/...@all &&
43+
(
44+
cd "$git" &&
45+
test_path_is_file wanted/foo &&
46+
test_path_is_missing discard/foo
47+
)
48+
'
49+
50+
test_expect_success 'clone, then sync with exclude' '
51+
test_when_finished cleanup_git &&
52+
git p4 clone -//depot/discard/... --dest="$git" //depot/...@all &&
53+
(
54+
cd "$cli" &&
55+
p4 edit wanted/foo discard/foo &&
56+
date >>wanted/foo &&
57+
date >>discard/foo &&
58+
p4 submit -d "updating" &&
59+
60+
cd "$git" &&
61+
git p4 sync -//depot/discard/... &&
62+
test_path_is_file wanted/foo &&
63+
test_path_is_missing discard/foo
64+
)
65+
'
66+
67+
test_expect_success 'kill p4d' '
68+
kill_p4d
69+
'
70+
71+
test_done

0 commit comments

Comments
 (0)