Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset remote if URL changed #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions libexec/decomposer/decomposer-install
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ install_library() {

cd "${library_target_dir}" || return 2

local revision revision_type revision_alt_type revision_reset
local revision revision_type revision_alt_type revision_reset default_remote

revision=$( jq -r '.revision' <<< "${object}" )
if [ "${revision}" = "null" ]; then
Expand All @@ -94,18 +94,26 @@ install_library() {
revision_alt_type=$( git cat-file -t "v${revision}" 2> /dev/null )
revision_reset=

if git branch -a | grep -q "/origin/${revision}"; then
revision_reset="origin/${revision}"
# use the origin for master as the default origin
# TODO: determine the default remote
default_remote="origin"
if git remote get-url "$default_remote" | grep -q "${url}"; then
SMillerDev marked this conversation as resolved.
Show resolved Hide resolved
printf -v "${status_text_variable}" 'remote URL has changed'
git remote set-url "$default_remote" "${url}"
fi
pprkut marked this conversation as resolved.
Show resolved Hide resolved

if git branch -a | grep -q "/${default_remote}/${revision}"; then
revision_reset="${default_remote}/${revision}"
elif [ "${revision_type}" = 'commit' ] || [ "${revision_type}" = 'tag' ]; then
revision_reset="${revision}"
elif [ "${revision_alt_type}" = 'commit' ] || [ "${revision_alt_type}" = 'tag' ]; then
revision_reset="v${revision}"
fi

if [ -z "${just_cloned}" ] && [ "${revision_reset}" = "origin/${revision}" ] || [ -z "${revision_reset}" ]; then
if [ -z "${just_cloned}" ] && [ "${revision_reset}" = "${default_remote}/${revision}" ] || [ -z "${revision_reset}" ]; then
# no need to fetch changes if we just cloned the repository
# or we can already resolve a commit or tag
if ! git fetch origin &> /dev/null; then
if ! git fetch ${default_remote} &> /dev/null; then
printf -v "${status_text_variable}" 'fetching changes failed'
return 1
fi
Expand All @@ -116,8 +124,8 @@ install_library() {
revision_alt_type=$( git cat-file -t "v${revision}" 2> /dev/null )
revision_reset=

if git branch -a | grep -q "/origin/${revision}"; then
revision_reset="origin/${revision}"
if git branch -a | grep -q "/${default_remote}/${revision}"; then
revision_reset="${default_remote}/${revision}"
elif [ "${revision_type}" = 'commit' ] || [ "${revision_type}" = 'tag' ]; then
revision_reset="${revision}"
elif [ "${revision_alt_type}" = 'commit' ] || [ "${revision_alt_type}" = 'tag' ]; then
Expand Down
18 changes: 18 additions & 0 deletions tests/install.bats
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ SUITE_NAME=$( test_suite_name )
assert_lib_installed Alpha-1.0 "${tag_alpha_lib_revision_hash}"
}

@test "${SUITE_NAME}: existing library resets upstream" {
create_decomposer_json alpha_tag_version

create_repository alpha-lib

# create usual clone of library
git clone "${TEST_REPOS_DIR}/alpha-lib" "${DECOMPOSER_TARGET_DIR}/Alpha-1.0"

# create new commit in repository and tag
git -C "${TEST_REPOS_DIR}/alpha-lib" remote set-url origin https://moveagency.com
Comment on lines +126 to +127
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That command references the original repo, not the clone. Also, the comment is wrong


run_decomposer install
[ "${status}" -eq 0 ]
[ "${lines[0]}" = "Installing Alpha...done" ]

assert_lib_installed Alpha-1.0 "${tag_alpha_lib_revision_hash}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just verifies the hash is as expected, but we only have the commits from the original clone. To properly test this decomposer install would have to fetch new commits, and we'd have to verify that the remote after running decomposer install matches what's in decomposer.json

}

@test "${SUITE_NAME}: existing library fetches new annotated tag" {
create_decomposer_json alpha_tag_version

Expand Down
Loading