Skip to content

Commit 4e51ba2

Browse files
peffgitster
authored andcommitted
git-remote-testgit: import non-HEAD refs
Upon receiving an "import" command, the testgit remote helper would ignore the ref asked for by git and generate a fast-export stream based on HEAD. Instead, we should actually give git the ref it asked for. This requires adding a new parameter to the export_repo method in the remote-helpers python library, which may be used by code outside of git.git. We use a default parameter so that callers without the new parameter will get the same behavior as before. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Sverre Rabbelier <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c00dd33 commit 4e51ba2

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

git-remote-testgit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def do_import(repo, args):
122122
die("Need gitdir to import")
123123

124124
repo = update_local_repo(repo)
125-
repo.exporter.export_repo(repo.gitdir)
125+
repo.exporter.export_repo(repo.gitdir, args)
126126

127127

128128
def do_export(repo, args):

git_remote_helpers/git/exporter.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ def __init__(self, repo):
1515

1616
self.repo = repo
1717

18-
def export_repo(self, base):
18+
def export_repo(self, base, refs=None):
1919
"""Exports a fast-export stream for the given directory.
2020
2121
Simply delegates to git fast-epxort and pipes it through sed
2222
to make the refs show up under the prefix rather than the
2323
default refs/heads. This is to demonstrate how the export
2424
data can be stored under it's own ref (using the refspec
2525
capability).
26+
27+
If None, refs defaults to ["HEAD"].
2628
"""
2729

30+
if not refs:
31+
refs = ["HEAD"]
32+
2833
dirname = self.repo.get_base_path(base)
2934
path = os.path.abspath(os.path.join(dirname, 'testgit.marks'))
3035

@@ -42,7 +47,7 @@ def export_repo(self, base):
4247
if os.path.exists(path):
4348
args.append("--import-marks=" + path)
4449

45-
args.append("HEAD")
50+
args.extend(refs)
4651

4752
p1 = subprocess.Popen(args, stdout=subprocess.PIPE)
4853

t/t5800-remote-helpers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test_expect_success 'pushing remote local repo' '
8585
compare_refs clone HEAD server HEAD
8686
'
8787

88-
test_expect_failure 'fetch new branch' '
88+
test_expect_success 'fetch new branch' '
8989
(cd public &&
9090
git checkout -b new &&
9191
echo content >>file &&

0 commit comments

Comments
 (0)