From ac8045f3e2b4859983295328186cde0990aeb24c Mon Sep 17 00:00:00 2001 From: Sergey Bogdanov Date: Thu, 8 Aug 2019 15:17:38 -0400 Subject: [PATCH 1/9] The 'subrepo pull' failed to update the parent recrod after the pull. As a result at the followup pull 1. it resamples all the commits from the beginning of times in 'subrepo branch' 2. the above causes merging issue. The fix: remove an extra checking in the update-gitrepo-file while creating the parent currentl failing the tsts: test/branch-rev-list-one-path.t (Wstat: 0 Tests: 7 Failed: 1) Failed test: 7 test/error.t (Wstat: 0 Tests: 17 Failed: 1) Failed test: 17 Parse errors: No plan found in TAP output test/pull-merge.t (Wstat: 0 Tests: 13 Failed: 1) Failed test: 8 test/push-after-init.t (Wstat: 0 Tests: 0 Failed: 0) Parse errors: No plan found in TAP output test/push-new-branch.t (Wstat: 0 Tests: 0 Failed: 0) Parse errors: No plan found in TAP output test/push.t (Wstat: 0 Tests: 17 Failed: 2) Failed tests: 3-4 --- lib/git-subrepo | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/git-subrepo b/lib/git-subrepo index 68918cbe..b4bbfb5b 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -704,7 +704,7 @@ subrepo:branch() { local prev_commit= local ancestor= o "Create new commits with parents into the subrepo fetch" - OUT=true RUN git rev-list --reverse --ancestry-path "$subrepo_parent..HEAD" + OUT=true RUN git rev-list --reverse --ancestry-path "$subrepo_parent..HEAD" local commit_list="$output" for commit in $commit_list; do o "Working on $commit" @@ -1374,13 +1374,20 @@ update-gitrepo-file() { fi RUN git config --file="$gitrepo" subrepo.commit "$upstream_head_commit" + o " upstream_head_commit:'$upstream_head_commit', subrepo_commit_ref='$subrepo_commit_ref'" + # Only write new parent when we are at the head of upstream - if [[ -n $upstream_head_commit && -n $subrepo_commit_ref ]]; then - OUT=true RUN git rev-parse "$subrepo_commit_ref" - o "$upstream_head_commit == $output" - if [[ $upstream_head_commit == $output ]]; then - RUN git config --file="$gitrepo" subrepo.parent "$original_head_commit" - fi + if [[ -n $upstream_head_commit && -n $subrepo_commit_ref && -n $original_head_commit ]]; then + # + # srg: this check prevents from updating the parent after pull + # + # OUT=true RUN git rev-parse "$subrepo_commit_ref" + # o "$upstream_head_commit == $output" + # if [[ $upstream_head_commit == $output ]]; then + + RUN git config --file="$gitrepo" subrepo.parent "$original_head_commit" + + #fi fi [[ -z $join_method ]] && join_method="merge" From 1dd3c7d7fc914593b048c01d2bff88ad61f25065 Mon Sep 17 00:00:00 2001 From: Sergey Bogdanov Date: Thu, 8 Aug 2019 15:21:23 -0400 Subject: [PATCH 2/9] few branch... tests have been failing sporadically due to the undefined rev order in rev-list (at least in git 2.22). the fix: add --topo-order qualifier to the rev-list to make the order to be stable across different test. still failing tests: test/error.t (Wstat: 0 Tests: 17 Failed: 1) Failed test: 17 Parse errors: No plan found in TAP output test/pull-merge.t (Wstat: 0 Tests: 13 Failed: 1) Failed test: 8 test/push-after-init.t (Wstat: 0 Tests: 0 Failed: 0) Parse errors: No plan found in TAP output test/push-new-branch.t (Wstat: 0 Tests: 0 Failed: 0) Parse errors: No plan found in TAP output test/push.t (Wstat: 0 Tests: 17 Failed: 2) Failed tests: 3-4 --- lib/git-subrepo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git-subrepo b/lib/git-subrepo index b4bbfb5b..2dfdacc6 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -704,7 +704,7 @@ subrepo:branch() { local prev_commit= local ancestor= o "Create new commits with parents into the subrepo fetch" - OUT=true RUN git rev-list --reverse --ancestry-path "$subrepo_parent..HEAD" + OUT=true RUN git rev-list --reverse --ancestry-path --topo-order "$subrepo_parent..HEAD" local commit_list="$output" for commit in $commit_list; do o "Working on $commit" From e8737fdcd69a09ba62c0fd7d71fc249642c909f5 Mon Sep 17 00:00:00 2001 From: Sergey Bogdanov Date: Thu, 8 Aug 2019 15:34:04 -0400 Subject: [PATCH 3/9] error.t test was failing inside a submodule. The reason: there is no '.git' directory, just a .git ref. fix: replace 'cd .dir' with 'cd $(git rev-parse --git-dir)' --- test/error.t | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/error.t b/test/error.t index 0e3100d3..f6879e90 100644 --- a/test/error.t +++ b/test/error.t @@ -117,8 +117,10 @@ clone-foo-and-bar { is "$( - cd .git - catch git subrepo status + # the test was failing inside a submodule. there is no .git directory, just a ref + # cd .git + cd $(git rev-parse --git-dir) + catch git subrepo status )" \ "git-subrepo: Can't 'subrepo status' outside a working tree." \ "Error OK: check inside working tree" From eb282b5d1f78cc8f393dbb621c7d5da511f4bf4a Mon Sep 17 00:00:00 2001 From: Sergey Bogdanov Date: Thu, 8 Aug 2019 15:43:25 -0400 Subject: [PATCH 4/9] The pull-merge.t test expects that parent to be establishes 'before' the subrepo pull. I'd like this behavior to change. The parent should *change* after the pull. --- test/pull-merge.t | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/pull-merge.t b/test/pull-merge.t index 285a798b..e542e965 100644 --- a/test/pull-merge.t +++ b/test/pull-merge.t @@ -27,7 +27,8 @@ gitrepo=$OWNER/foo/bar/.gitrepo test-gitrepo-field "parent" "$foo_pull_commit" } -foo_pull_commit="$(cd $OWNER/foo; git rev-parse HEAD)" +## i think this wrong and the parent should be moved after the pull +#foo_pull_commit="$(cd $OWNER/foo; git rev-parse HEAD)" ( cd $OWNER/foo @@ -36,6 +37,9 @@ foo_pull_commit="$(cd $OWNER/foo; git rev-parse HEAD)" git push ) &> /dev/null || die +#this is the right place +foo_pull_commit="$(cd $OWNER/foo; git rev-parse HEAD)" + ( cd $OWNER/bar modify-files-ex Bar2 From 8e4e7f8370b1d746f9dbaeb14dbfe97db1eb65a6 Mon Sep 17 00:00:00 2001 From: Sergey Bogdanov Date: Thu, 8 Aug 2019 16:01:50 -0400 Subject: [PATCH 5/9] failed tests: test/push-after-init.t test/push-new-branch.t the reason: git 2.21 changed the message from Couldn't to couldn't fix: fixed regex to catch both cases. --- lib/git-subrepo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git-subrepo b/lib/git-subrepo index 2dfdacc6..e4b5d5d0 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -581,7 +581,7 @@ subrepo:push() { if ! OK; then # Check if we are pushing to a new upstream repo (or branch) and just # push the commit directly. This is common after a `git subrepo init`: - local re="(^|"$'\n'")fatal: Couldn't find remote ref " + local re="(^|"$'\n'")fatal: [Cc]ouldn't find remote ref " if [[ $output =~ $re ]]; then o "Pushing to new upstream: $subrepo_remote ($subrepo_branch)." new_upstream=true From fc0a944f0255ada354c3f8daca25377c282f53f3 Mon Sep 17 00:00:00 2001 From: Sergey Bogdanov Date: Thu, 8 Aug 2019 17:46:19 -0400 Subject: [PATCH 6/9] the push.t test has an intersting scenario: it has pull before push. With the new scheme the pull will set up a new parent for the subrepo. This causes all history before the parent to be truncated for the consequent push. The way around it is to introduce yet another 'push-parent' in the .gitrepo file. The push-parent is set up by the 'clone' and 'push' commands. The push uses it as subrepo_parent. This way all tests passed. --- lib/git-subrepo | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/git-subrepo b/lib/git-subrepo index e4b5d5d0..c8a391d4 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -114,6 +114,7 @@ main() { local subrepo_branch= # Upstream branch to clone/push/pull local subrepo_commit= # Upstream HEAD from previous clone/pull local subrepo_parent= # Local commit from before previous clone/pull + local subrepo_push_parent= # Local commit from before previous push local subrepo_former= # A retired gitrepo key that might still exist local refs_subrepo_branch= # A subrepo ref -> commit of branch/pull command @@ -494,7 +495,7 @@ subrepo:clone() { o "Commit the new '$subdir/' content." subrepo_commit_ref="$upstream_head_commit" - CALL subrepo:commit + CALL subrepo:commit clone } # Init a new subrepo from current repo: @@ -604,10 +605,12 @@ subrepo:push() { if $squash_wanted; then o "Squash commits" subrepo_parent="HEAD^" + elif [ -n "$subrepo_push_parent" ]; then + subrepo_parent=$subrepo_push_parent fi o "Create subrepo branch '$branch_name'." - CALL subrepo:branch "$branch_name" + CALL subrepo:branch "$branch_name" cd "$worktree"; if [[ "$join_method" == "rebase" ]]; then @@ -669,6 +672,8 @@ subrepo:push() { upstream_head_commit="$new_upstream_head_commit" subrepo_commit_ref="$upstream_head_commit" update-gitrepo-file + RUN git config --file="$gitrepo" subrepo.push-parent "$original_head_commit" + RUN git add -f -- "$gitrepo" RUN git commit -m "$(get-commit-message)" } @@ -693,6 +698,7 @@ subrepo:fetch() { # Create a subrepo branch containing all changes subrepo:branch() { local branch="${1:-"subrepo/$subref"}" + o "Check if the '$branch' branch already exists." git:branch-exists "$branch" && return @@ -807,6 +813,7 @@ subrepo:branch() { # Commit a merged subrepo branch: subrepo:commit() { + local is_clone=$1 o "Check that '$subrepo_commit_ref' exists." git:rev-exists "$subrepo_commit_ref" || error "Commit ref '$subrepo_commit_ref' does not exist." @@ -830,6 +837,9 @@ subrepo:commit() { o "Put info into '$subdir/.gitrepo' file." update-gitrepo-file + if [ "$is_clone" == "clone" ]; then + RUN git config --file="$gitrepo" subrepo.push-parent "$original_head_commit" + fi RUN git add -f -- "$gitrepo" local commit_message @@ -1322,6 +1332,10 @@ read-gitrepo-file() { SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.parent subrepo_parent="$output" + FAIL=false \ + SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.push-parent + subrepo_push_parent="$output" + FAIL=false \ SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.method if [[ $output == "rebase" ]]; then From 329832f2ba10e1782b9735119dac4f0330a26dad Mon Sep 17 00:00:00 2001 From: Sergey Bogdanov Date: Thu, 8 Aug 2019 18:18:14 -0400 Subject: [PATCH 7/9] added push-parent reporting to the 'subrepo status' --- lib/git-subrepo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/git-subrepo b/lib/git-subrepo index c8a391d4..88036817 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -941,6 +941,10 @@ subrepo:status() { printf " Former Commit: $(git rev-parse --short $subrepo_former)" echo " *** DEPRECATED ***" fi + [[ -n $subrepo_push_parent ]] && + echo " Push Parent: $(git rev-parse --short $subrepo_push_parent)" + + # Grep for directory, branch can be in detached state due to conflicts local _worktree=$(git worktree list | grep "$GIT_TMP/subrepo/$subdir") From 464b2a17ed2aa8afba6ff052bdd452a1b2b210fa Mon Sep 17 00:00:00 2001 From: Sergey Bogdanov Date: Tue, 13 Aug 2019 09:20:06 -0400 Subject: [PATCH 8/9] moved push-parent config into update-gitrepo-file with header checking --- lib/git-subrepo | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/git-subrepo b/lib/git-subrepo index 88036817..9f082f55 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -671,9 +671,9 @@ subrepo:push() { o "Put updates into '$subdir/.gitrepo' file." upstream_head_commit="$new_upstream_head_commit" subrepo_commit_ref="$upstream_head_commit" - update-gitrepo-file - RUN git config --file="$gitrepo" subrepo.push-parent "$original_head_commit" - RUN git add -f -- "$gitrepo" + update-gitrepo-file "push" + # RUN git config --file="$gitrepo" subrepo.push-parent "$original_head_commit" + # RUN git add -f -- "$gitrepo" RUN git commit -m "$(get-commit-message)" } @@ -836,11 +836,14 @@ subrepo:commit() { RUN git read-tree --prefix="$subdir" -u "$subrepo_commit_ref" o "Put info into '$subdir/.gitrepo' file." - update-gitrepo-file - if [ "$is_clone" == "clone" ]; then - RUN git config --file="$gitrepo" subrepo.push-parent "$original_head_commit" - fi - RUN git add -f -- "$gitrepo" + local push_update= + [ "$is_clone" == "clone" ] && push_update="push" + update-gitrepo-file "$push_update" + + # if [ "$is_clone" == "clone" ]; then + # RUN git config --file="$gitrepo" subrepo.push-parent "$original_head_commit" + # fi + # RUN git add -f -- "$gitrepo" local commit_message if [[ -n "$wanted_commit_message" ]]; then @@ -1360,7 +1363,8 @@ read-gitrepo-file() { # Update the subdir/.gitrepo state file: update-gitrepo-file() { local short_commit= - + local is_push=$1 + local newfile=false if [[ ! -e $gitrepo ]]; then @@ -1404,7 +1408,9 @@ update-gitrepo-file() { # if [[ $upstream_head_commit == $output ]]; then RUN git config --file="$gitrepo" subrepo.parent "$original_head_commit" - + if [ "$is_push" == "push" ]; then + RUN git config --file="$gitrepo" subrepo.push-parent "$original_head_commit" + fi #fi fi From aa9f5e8f30fb42ea61efce16a12b404abecb8768 Mon Sep 17 00:00:00 2001 From: Sergey Bogdanov Date: Tue, 13 Aug 2019 16:23:32 -0400 Subject: [PATCH 9/9] attempt to fix test scripts which fail at the github site only --- test/error.t | 8 ++++++-- test/status.t | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/error.t b/test/error.t index f6879e90..d166ab24 100644 --- a/test/error.t +++ b/test/error.t @@ -118,8 +118,12 @@ clone-foo-and-bar { is "$( # the test was failing inside a submodule. there is no .git directory, just a ref - # cd .git - cd $(git rev-parse --git-dir) + if [ -d .git ]; then + cd .git + else + cd $(git rev-parse --git-dir) + fi + catch git subrepo status )" \ "git-subrepo: Can't 'subrepo status' outside a working tree." \ diff --git a/test/status.t b/test/status.t index b6a7fe61..c296616f 100644 --- a/test/status.t +++ b/test/status.t @@ -5,6 +5,7 @@ set -e source test/setup use Test::More + echo "===> $0: $PWD <===" > /dev/tty { output="$(git subrepo status)"