From b7fad46f1bd6b2882a63f909310237b69e7e3bda Mon Sep 17 00:00:00 2001 From: Matej Urbas Date: Mon, 21 May 2018 16:50:00 +0100 Subject: [PATCH 1/2] Travis CI not checking out a branch. The command in `.travis.yml` that is supposed to checkout the branch did not actually check out the branch. --- .travis.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index a590c5a3..9f369043 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,18 +4,9 @@ sudo: false # Want 'bash' but 'c' works: language: c -branches: - only: - - master - - /^release\// - script: -- git checkout $( - git branch --contains HEAD - | cut -c3- - | grep -E '^(master$|release)' - | head -1 - ) +# NOTE: we have to make sure we're on a branch (rather than on a detached HEAD) because tests rely on it. +- git checkout -b travis-ci-dummy-branch-name - GIT_COMMITTER_NAME=Bob GIT_COMMITTER_EMAIL=bob@blob.net GIT_AUTHOR_NAME='Bob Blob' From 7f3c47789ab8d2b8e6be8f185d88b748fc0fde66 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 4 Dec 2019 18:24:20 +0100 Subject: [PATCH 2/2] Make reclone with implicit branch update branch in .gitrepo correctly If the subrepo is tracking a branch and you reclone using git subrepo clone --force $URL without specifying -b/--branch then the branch setting in .gitrepo is not updated. --- lib/git-subrepo | 7 +++++++ test/reclone.t | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/git-subrepo b/lib/git-subrepo index 68918cbe..6ed6b5f8 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -478,6 +478,13 @@ subrepo:clone() { fi o "Remove the old subdir." RUN git rm -r -- "$subdir" + + if [[ -z $override_branch ]]; then + o "Determine the upstream head branch." + get-upstream-head-branch + subrepo_branch="$output" + override_branch="$output" # Force update of the branch in .gitrepo + fi else assert-subdir-empty if [[ -z $subrepo_branch ]]; then diff --git a/test/reclone.t b/test/reclone.t index ff6f451f..6ff7ed7f 100644 --- a/test/reclone.t +++ b/test/reclone.t @@ -16,6 +16,7 @@ clone-foo-and-bar test-exists \ "$OWNER/foo/bar/bard/" +# Test that reclone is not done if not needed. export XYZ=1 is "$( cd $OWNER/foo @@ -24,19 +25,25 @@ is "$( "Subrepo 'bar' is up to date." \ "No reclone if same commit" +# Test that reclone of a different ref works. ( cd $OWNER/foo git subrepo --quiet clone --force ../../../$UPSTREAM/bar --branch=refs/tags/A ) +is "$(git -C $OWNER/foo subrepo config bar branch)" \ + "Subrepo 'bar' option 'branch' has value 'refs/tags/A'." test-exists \ "!$OWNER/foo/bar/bard/" +# Test that reclone back to (implicit) master works. ( cd $OWNER/foo - git subrepo --quiet clone -f ../../../$UPSTREAM/bar --branch=master + git subrepo --quiet clone -f ../../../$UPSTREAM/bar ) +is "$(git -C $OWNER/foo subrepo config bar branch)" \ + "Subrepo 'bar' option 'branch' has value 'master'." test-exists \ "$OWNER/foo/bar/bard/"