Skip to contentSkip to conversation

scripts: Refine git-checkout.sh change for different branches

PATCH In review Andrew Cooper 4 participants 9 messages Oct 31, 2024 – Nov 1, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: Refine git-checkout.sh change for different branches

The change works for divergent branches, but doesn't work for explicit SHAs.

Instead of passing -b $TAG to clone, explicitly fetch the $TAG we want after cloning.

Fixes c554ec124b12 ("scripts: Fix git-checkout.sh to work with branches other than master")

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

Speculative fix, pending CI:
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1521847529

---
 scripts/git-checkout.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/git-checkout.sh +2 -1
index 3796cbfe39a7..9f8f2bd04fca 100755
@@ -14,9 +14,10 @@ set -e
 if test \! -d $DIR-remote; then
 	rm -rf $DIR-remote $DIR-remote.tmp
 	mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp
-	$GIT clone -b $TAG $TREE $DIR-remote.tmp
+	$GIT clone $TREE $DIR-remote.tmp
 	if test "$TAG" ; then
 		cd $DIR-remote.tmp
+                $GIT fetch origin $TAG
 		$GIT branch -D dummy >/dev/null 2>&1 ||:
 		$GIT checkout -b dummy $TAG
 		cd -

base-commit: 9a2a50d5de7647bfb529867fdce47ec64b07f06a
prerequisite-patch-id: ef7a8f78a2a3bfb35a2835ce8c2ec97d95f1267e
prerequisite-patch-id: 8c25962203bdb283a9c95328fb0867ffa3da8b95

Signature · 1 line
2.39.5
#1 lore raw
Quoted 23 lines · Andrew Cooper

The change works for divergent branches, but doesn't work for explicit SHAs.

Instead of passing -b $TAG to clone, explicitly fetch the $TAG we want after cloning.

Fixes c554ec124b12 ("scripts: Fix git-checkout.sh to work with branches other than master")

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

Speculative fix, pending CI:
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1521847529

---
 scripts/git-checkout.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/git-checkout.sh +0 -0
index 3796cbfe39a7..9f8f2bd04fca 100755

scripts/git-checkout.sh set -e · line 17

Quoted 5 lines
scripts/git-checkout.sh +1 -1
@@ -14,9 +14,10 @@ set -e
 if test \! -d $DIR-remote; then
 	rm -rf $DIR-remote $DIR-remote.tmp
 	mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp
-	$GIT clone -b $TAG $TREE $DIR-remote.tmp
+	$GIT clone $TREE $DIR-remote.tmp

Can this be shallow (--depth 1) clone instead to avoid pulling for whole history in CI? There's probably some ENV variable that could be recovered from.

Quoted 10 lines
scripts/git-checkout.sh +1 -0
 	if test "$TAG" ; then
 		cd $DIR-remote.tmp
+                $GIT fetch origin $TAG
 		$GIT branch -D dummy >/dev/null 2>&1 ||:
 		$GIT checkout -b dummy $TAG
 		cd -

base-commit: 9a2a50d5de7647bfb529867fdce47ec64b07f06a
prerequisite-patch-id: ef7a8f78a2a3bfb35a2835ce8c2ec97d95f1267e
prerequisite-patch-id: 8c25962203bdb283a9c95328fb0867ffa3da8b95

#2 lore raw
Quoted 19 lines · Alejandro Vallejo
Quoted 18 lines · Andrew Cooper

The change works for divergent branches, but doesn't work for explicit SHAs.

Instead of passing -b $TAG to clone, explicitly fetch the $TAG we want after cloning.

Fixes c554ec124b12 ("scripts: Fix git-checkout.sh to work with branches other than master")

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

Speculative fix, pending CI:
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1521847529

---
 scripts/git-checkout.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 13 lines

scripts/git-checkout.sh set -e · line 17

Quoted 10 lines
scripts/git-checkout.sh +1 -1
index 3796cbfe39a7..9f8f2bd04fca 100755
@@ -14,9 +14,10 @@ set -e
 if test \! -d $DIR-remote; then
 	rm -rf $DIR-remote $DIR-remote.tmp
 	mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp
-	$GIT clone -b $TAG $TREE $DIR-remote.tmp
+	$GIT clone $TREE $DIR-remote.tmp

Can this be shallow (--depth 1) clone instead to avoid pulling for whole history in CI? There's probably some ENV variable that could be recovered from.

Maybe, but not here.  One swamp at a time.

More specifically, my first iteration of this fix did use --depth 1, but it broke QEMU's submodules.  I'm not debugging that as a prerequisite of fixing other CI breakages.

~Andrew

Reviewed-by
#3 lore raw
Quoted 34 lines · Andrew Cooper
Quoted 19 lines · Alejandro Vallejo
Quoted 18 lines · Andrew Cooper

The change works for divergent branches, but doesn't work for explicit SHAs.

Instead of passing -b $TAG to clone, explicitly fetch the $TAG we want after cloning.

Fixes c554ec124b12 ("scripts: Fix git-checkout.sh to work with branches other than master")

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

Speculative fix, pending CI:
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1521847529

---
 scripts/git-checkout.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 13 lines

scripts/git-checkout.sh set -e · line 17

Quoted 10 lines
scripts/git-checkout.sh +1 -1
index 3796cbfe39a7..9f8f2bd04fca 100755
@@ -14,9 +14,10 @@ set -e
 if test \! -d $DIR-remote; then
 	rm -rf $DIR-remote $DIR-remote.tmp
 	mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp
-	$GIT clone -b $TAG $TREE $DIR-remote.tmp
+	$GIT clone $TREE $DIR-remote.tmp

Can this be shallow (--depth 1) clone instead to avoid pulling for whole history in CI? There's probably some ENV variable that could be recovered from.

Quoted 7 lines

Maybe, but not here.  One swamp at a time.

More specifically, my first iteration of this fix did use --depth 1, but it broke QEMU's submodules.  I'm not debugging that as a prerequisite of fixing other CI breakages.

~Andrew

Fair. From inspection, pending an ok from some pipelines:

Cheers,
Alejandro

#4 lore raw
In reply to Andrew Cooper
Quoted 7 lines · Andrew Cooper

The change works for divergent branches, but doesn't work for explicit SHAs.

Instead of passing -b $TAG to clone, explicitly fetch the $TAG we want after cloning.

Fixes c554ec124b12 ("scripts: Fix git-checkout.sh to work with branches other than master")
Quoted 7 lines

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

Speculative fix, pending CI:
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1521847529

Nope.  While this works on staging, it breaks on 4.17

Back to the drawing board.

~Andrew

#5 lore raw
Quoted 13 lines · Andrew Cooper
Quoted 12 lines · Andrew Cooper

The change works for divergent branches, but doesn't work for explicit SHAs.

Instead of passing -b $TAG to clone, explicitly fetch the $TAG we want after cloning.

Fixes c554ec124b12 ("scripts: Fix git-checkout.sh to work with branches other than master")

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

Quoted 6 lines
Quoted 2 lines

Speculative fix, pending CI:
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1521847529

Nope.  While this works on staging, it breaks on 4.17

Back to the drawing board.

I am not certain about this but maybe we need:

$GIT fetch origin

without the $TAG

#6 lore raw
Quoted 20 lines · Stefano Stabellini
Quoted 17 lines · Andrew Cooper
Quoted 7 lines · Andrew Cooper

The change works for divergent branches, but doesn't work for explicit SHAs.

Instead of passing -b $TAG to clone, explicitly fetch the $TAG we want after cloning.

Fixes c554ec124b12 ("scripts: Fix git-checkout.sh to work with branches other than master")
Quoted 7 lines

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

Speculative fix, pending CI:
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1521847529

Nope.  While this works on staging, it breaks on 4.17

Quoted 7 lines
Quoted 1 line

Back to the drawing board.

I am not certain about this but maybe we need:

$GIT fetch origin

without the $TAG

You need the $TAG to guide what to pull when it's not a parent of master.

For real tags (which live in a global namespace), and real SHAs (don't need any further reference), creating a branch called dummy from them works fine.

The problem for branches is that $GIT fetch origin $TAG only updates FETCH_HEAD and doesn't create a remote branch of the same name.  You can do that with $GIT fetch origin $TAG:$TAG but only if you know that $TAG is really a branch in the first place.

Which circles back around to the original problem of not being able to disambiguate what $TAG is until you've got the whole repository.

I'm not aware of any way to ask the remote "do you know what type of object $TAG actually is?" and that's probably because it would be a reverse lookup through refs/ to figure out if it was a branch or not.

I'm sure there must be a way of doing this...

~Andrew

#7 lore raw
Quoted 40 lines · Andrew Cooper
Quoted 20 lines · Stefano Stabellini
Quoted 17 lines · Andrew Cooper
Quoted 7 lines · Andrew Cooper

The change works for divergent branches, but doesn't work for explicit SHAs.

Instead of passing -b $TAG to clone, explicitly fetch the $TAG we want after cloning.

Fixes c554ec124b12 ("scripts: Fix git-checkout.sh to work with branches other than master")
Quoted 7 lines

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

Speculative fix, pending CI:

   https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1521847529

Nope.  While this works on staging, it breaks on 4.17

Quoted 7 lines
Quoted 1 line

Back to the drawing board.

I am not certain about this but maybe we need:

$GIT fetch origin

without the $TAG

You need the $TAG to guide what to pull when it's not a parent of master.

For real tags (which live in a global namespace), and real SHAs (don't need any further reference), creating a branch called dummy from them works fine.

The problem for branches is that $GIT fetch origin $TAG only updates FETCH_HEAD and doesn't create a remote branch of the same name.  You can do that with $GIT fetch origin $TAG:$TAG but only if you know that $TAG is really a branch in the first place.

Quoted 8 lines

Which circles back around to the original problem of not being able to disambiguate what $TAG is until you've got the whole repository.

I'm not aware of any way to ask the remote "do you know what type of object $TAG actually is?" and that's probably because it would be a reverse lookup through refs/ to figure out if it was a branch or not.

I'm sure there must be a way of doing this...

I'm not clear on the exact problem, but can you just checkout the FETCH_HEAD:

$GIT fetch origin $TAG
$GIT branch -D dummy >/dev/null 2>&1 ||:
$GIT checkout -b dummy FETCH_HEAD

?

Regards,
Jason

#8 lore raw
Quoted 49 lines · Jason Andryuk
Quoted 48 lines · Andrew Cooper
Quoted 23 lines · Stefano Stabellini
Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Andrew Cooper

The change works for divergent branches, but doesn't work for explicit SHAs.

Instead of passing -b $TAG to clone, explicitly fetch the $TAG we want after
cloning.

Fixes c554ec124b12 ("scripts: Fix git-checkout.sh to work with

branches other than master")

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

Speculative fix, pending CI:

https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1521847529

Quoted 8 lines
Quoted 3 lines

Nope.  While this works on staging, it breaks on 4.17

Back to the drawing board.

  I am not certain about this but maybe we need:

   $GIT fetch origin

without the $TAG

You need the $TAG to guide what to pull when it's not a parent of master.

For real tags (which live in a global namespace), and real SHAs (don't need any further reference), creating a branch called dummy from them works fine.

The problem for branches is that $GIT fetch origin $TAG only updates FETCH_HEAD and doesn't create a remote branch of the same name.  You can do that with $GIT fetch origin $TAG:$TAG but only if you know that $TAG is really a branch in the first place.

Which circles back around to the original problem of not being able to disambiguate what $TAG is until you've got the whole repository.

Quoted 7 lines
Quoted 5 lines

I'm not aware of any way to ask the remote "do you know what type of object $TAG actually is?" and that's probably because it would be a reverse lookup through refs/ to figure out if it was a branch or not.

I'm sure there must be a way of doing this...

I'm not clear on the exact problem

These were the failure following the original patch, which lead to this patch.

https://gitlab.com/xen-project/hardware/xen/-/pipelines/1521590040

and https://gitlab.com/xen-project/hardware/xen/-/jobs/8237236030#L267
is one specific instance

Quoted 5 lines

, but can you just checkout the FETCH_HEAD:

$GIT fetch origin $TAG
$GIT branch -D dummy >/dev/null 2>&1 ||:
$GIT checkout -b dummy FETCH_HEAD

Hmm yeah, that looks like it might work.  Thanks.  I'll have a play.

~Andrew