git-p4: support clone --bare
Just like git clone --bare, build a .git directory but no checked out files. Signed-off-by: Pete Wyckoff <pw@padd.com> Acked-By: Tor Arvid Lund <torarvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Feb 19, 2011 at 08:18 UTC
382000769477ed0666e99d01c21df64df9ba0911
2 files changed
+23
-4
contrib/fast-import/git-p4
+13
-4
@@ -1776,10 +1776,13 @@ class P4Clone(P4Sync):
1776
help="where to leave result of the clone"),
1777
optparse.make_option("-/", dest="cloneExclude",
1778
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),
1782
]
1783
self.cloneDestination = None
1784
self.needsGit = False
1785
+ self.cloneBare = False
1786
1787
# This is required for the "append" cloneExclude action
1788
def ensure_value(self, attr, value):
@@ -1819,11 +1822,16 @@ class P4Clone(P4Sync):
1822
self.cloneDestination = self.defaultDestination(args)
1823
1824
print "Importing from %s into %s" % (', '.join(depotPaths), self.cloneDestination)
1825
+
1826
if not os.path.exists(self.cloneDestination):
1827
os.makedirs(self.cloneDestination)
1828
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
+
1835
if not P4Sync.run(self, depotPaths):
1836
return False
1837
if self.branch != "master":
@@ -1833,7 +1841,8 @@ class P4Clone(P4Sync):
1841
masterbranch = "refs/heads/p4/master"
1842
if gitBranchExists(masterbranch):
1843
system("git branch master %s" % masterbranch)
1836
- system("git checkout -f")
1844
+ if not self.cloneBare:
1845
+ system("git checkout -f")
1846
else:
1847
print "Could not detect main branch. No checkout/master branch created."
1848
t/t9800-git-p4.sh
+10
@@ -80,6 +80,16 @@ test_expect_success 'wildcard files git-p4 clone' '
80
rm -rf "$git" && mkdir "$git"
81
'
82
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
+
93
test_expect_success 'shutdown' '
94
pid=`pgrep -f p4d` &&
95
test -n "$pid" &&