From f1e698e225e738595092bb6dc75b36fbaac76370 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 11 Mar 2022 08:32:26 -0800 Subject: [PATCH 1/3] Support repo change between invocations main logic from PR 499 (v3) from sed-i --- cmd/git-sync/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/git-sync/main.go b/cmd/git-sync/main.go index 81c789c..66f610f 100644 --- a/cmd/git-sync/main.go +++ b/cmd/git-sync/main.go @@ -928,7 +928,7 @@ func (git *repoSync) AddWorktreeAndSwap(ctx context.Context, hash string) error if git.branch != "" { fetch = git.branch } - args = append(args, "origin", fetch) + args = append(args, git.repo, fetch) // Update from the remote. if _, err := git.run.Run(ctx, git.root, nil, git.cmd, args...); err != nil { @@ -1200,7 +1200,7 @@ func (git *repoSync) LocalHashForRev(ctx context.Context, rev string) (string, e // RemoteHashForRef returns the upstream hash for a given ref. func (git *repoSync) RemoteHashForRef(ctx context.Context, ref string) (string, error) { - output, err := git.run.Run(ctx, git.root, nil, git.cmd, "ls-remote", "-q", "origin", ref) + output, err := git.run.Run(ctx, git.root, nil, git.cmd, "ls-remote", "-q", git.repo, ref) if err != nil { return "", err } From ff3d11c92526ab7acef83ca02932ccec09e22014 Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Fri, 25 Feb 2022 03:46:37 -0500 Subject: [PATCH 2/3] Add repo-sync test --- test_e2e.sh | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/test_e2e.sh b/test_e2e.sh index 650f3c3..3850c7e 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -110,8 +110,9 @@ function clean_work() { mkdir -p "$WORK" } -# REPO is the source repo under test. +# REPO and REPO2 are the source repos under test. REPO="$DIR/repo" +REPO2="${REPO}2" MAIN_BRANCH="e2e-branch" function init_repo() { rm -rf "$REPO" @@ -120,6 +121,9 @@ function init_repo() { touch "$REPO"/file git -C "$REPO" add file git -C "$REPO" commit -aqm "init file" + + rm -rf "$REPO2" + cp -r "$REPO" "$REPO2" } # ROOT is the volume (usually) used as --root. @@ -156,6 +160,7 @@ function GIT_SYNC() { -u $(id -u):$(id -g) \ -v "$ROOT":"$ROOT":rw \ -v "$REPO":"$REPO":ro \ + -v "$REPO2":"$REPO2":ro \ -v "$WORK":"$WORK":ro \ -v "$(pwd)/slow_git_clone.sh":"$SLOW_GIT_CLONE":ro \ -v "$(pwd)/slow_git_fetch.sh":"$SLOW_GIT_FETCH":ro \ @@ -544,6 +549,43 @@ function e2e::readlink() { assert_link_eq "$ROOT"/link $(git -C "$REPO" rev-parse HEAD) } +############################################## +# Test repo syncing +############################################## +function e2e::repo_sync() { + # Prepare first repo + echo "$FUNCNAME 1" > "$REPO"/file + git -C "$REPO" commit -qam "$FUNCNAME 1" + + # First sync + GIT_SYNC \ + --repo="file://$REPO" \ + --branch="$MAIN_BRANCH" \ + --root="$ROOT" \ + --dest="link" \ + --one-time \ + >> "$1" 2>&1 + assert_link_exists "$ROOT"/link + assert_file_exists "$ROOT"/link/file + assert_file_eq "$ROOT"/link/file "$FUNCNAME 1" + + # Prepare other repo + echo "$FUNCNAME 2" > "$REPO2"/file + git -C "$REPO2" commit -qam "$FUNCNAME 2" + + # Now sync the other repo + GIT_SYNC \ + --repo="file://$REPO2" \ + --branch="$MAIN_BRANCH" \ + --root="$ROOT" \ + --dest="link" \ + --one-time \ + >> "$1" 2>&1 + assert_link_exists "$ROOT"/link + assert_file_exists "$ROOT"/link/file + assert_file_eq "$ROOT"/link/file "$FUNCNAME 2" +} + ############################################## # Test branch syncing ############################################## From 535735607f7d4ee17b0b5bd97622744ea56db98a Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 11 Mar 2022 08:36:40 -0800 Subject: [PATCH 3/3] Adapt testcases for v4 --- test_e2e.sh | 74 ++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/test_e2e.sh b/test_e2e.sh index 3850c7e..797594c 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -549,43 +549,6 @@ function e2e::readlink() { assert_link_eq "$ROOT"/link $(git -C "$REPO" rev-parse HEAD) } -############################################## -# Test repo syncing -############################################## -function e2e::repo_sync() { - # Prepare first repo - echo "$FUNCNAME 1" > "$REPO"/file - git -C "$REPO" commit -qam "$FUNCNAME 1" - - # First sync - GIT_SYNC \ - --repo="file://$REPO" \ - --branch="$MAIN_BRANCH" \ - --root="$ROOT" \ - --dest="link" \ - --one-time \ - >> "$1" 2>&1 - assert_link_exists "$ROOT"/link - assert_file_exists "$ROOT"/link/file - assert_file_eq "$ROOT"/link/file "$FUNCNAME 1" - - # Prepare other repo - echo "$FUNCNAME 2" > "$REPO2"/file - git -C "$REPO2" commit -qam "$FUNCNAME 2" - - # Now sync the other repo - GIT_SYNC \ - --repo="file://$REPO2" \ - --branch="$MAIN_BRANCH" \ - --root="$ROOT" \ - --dest="link" \ - --one-time \ - >> "$1" 2>&1 - assert_link_exists "$ROOT"/link - assert_file_exists "$ROOT"/link/file - assert_file_eq "$ROOT"/link/file "$FUNCNAME 2" -} - ############################################## # Test branch syncing ############################################## @@ -863,6 +826,43 @@ function e2e::crash_cleanup_retry() { assert_file_eq "$ROOT"/link/file "$FUNCNAME 1" } +############################################## +# Test changing repos with storage intact +############################################## +function e2e::change_repos_after_sync() { + # Prepare first repo + echo "$FUNCNAME 1" > "$REPO"/file + git -C "$REPO" commit -qam "$FUNCNAME 1" + + # First sync + GIT_SYNC \ + --repo="file://$REPO" \ + --branch="$MAIN_BRANCH" \ + --root="$ROOT" \ + --link="link" \ + --one-time \ + >> "$1" 2>&1 + assert_link_exists "$ROOT"/link + assert_file_exists "$ROOT"/link/file + assert_file_eq "$ROOT"/link/file "$FUNCNAME 1" + + # Prepare other repo + echo "$FUNCNAME 2" > "$REPO2"/file + git -C "$REPO2" commit -qam "$FUNCNAME 2" + + # Now sync the other repo + GIT_SYNC \ + --repo="file://$REPO2" \ + --branch="$MAIN_BRANCH" \ + --root="$ROOT" \ + --link="link" \ + --one-time \ + >> "$1" 2>&1 + assert_link_exists "$ROOT"/link + assert_file_exists "$ROOT"/link/file + assert_file_eq "$ROOT"/link/file "$FUNCNAME 2" +} + ############################################## # Test sync loop timeout ##############################################