Skip to content

Commit 3820007

Browse files
Pete Wyckoffgitster
authored andcommitted
git-p4: support clone --bare
Just like git clone --bare, build a .git directory but no checked out files. Signed-off-by: Pete Wyckoff <[email protected]> Acked-By: Tor Arvid Lund <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 084f630 commit 3820007

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

contrib/fast-import/git-p4

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,10 +1776,13 @@ class P4Clone(P4Sync):
17761776
help="where to leave result of the clone"),
17771777
optparse.make_option("-/", dest="cloneExclude",
17781778
action="append", type="string",
1779-
help="exclude depot path")
1779+
help="exclude depot path"),
1780+
optparse.make_option("--bare", dest="cloneBare",
1781+
action="store_true", default=False),
17801782
]
17811783
self.cloneDestination = None
17821784
self.needsGit = False
1785+
self.cloneBare = False
17831786

17841787
# This is required for the "append" cloneExclude action
17851788
def ensure_value(self, attr, value):
@@ -1819,11 +1822,16 @@ class P4Clone(P4Sync):
18191822
self.cloneDestination = self.defaultDestination(args)
18201823

18211824
print "Importing from %s into %s" % (', '.join(depotPaths), self.cloneDestination)
1825+
18221826
if not os.path.exists(self.cloneDestination):
18231827
os.makedirs(self.cloneDestination)
18241828
chdir(self.cloneDestination)
1825-
system("git init")
1826-
self.gitdir = os.getcwd() + "/.git"
1829+
1830+
init_cmd = [ "git", "init" ]
1831+
if self.cloneBare:
1832+
init_cmd.append("--bare")
1833+
subprocess.check_call(init_cmd)
1834+
18271835
if not P4Sync.run(self, depotPaths):
18281836
return False
18291837
if self.branch != "master":
@@ -1833,7 +1841,8 @@ class P4Clone(P4Sync):
18331841
masterbranch = "refs/heads/p4/master"
18341842
if gitBranchExists(masterbranch):
18351843
system("git branch master %s" % masterbranch)
1836-
system("git checkout -f")
1844+
if not self.cloneBare:
1845+
system("git checkout -f")
18371846
else:
18381847
print "Could not detect main branch. No checkout/master branch created."
18391848

t/t9800-git-p4.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ test_expect_success 'wildcard files git-p4 clone' '
8080
rm -rf "$git" && mkdir "$git"
8181
'
8282

83+
test_expect_success 'clone bare' '
84+
"$GITP4" clone --dest="$git" --bare //depot &&
85+
cd "$git" &&
86+
test ! -d .git &&
87+
bare=`git config --get core.bare` &&
88+
test "$bare" = true &&
89+
cd "$TRASH_DIRECTORY" &&
90+
rm -rf "$git" && mkdir "$git"
91+
'
92+
8393
test_expect_success 'shutdown' '
8494
pid=`pgrep -f p4d` &&
8595
test -n "$pid" &&

0 commit comments

Comments
 (0)