Skip to content

Commit

Permalink
Issue #2: use git pull/fetch based on the current branch
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas committed Nov 6, 2023
1 parent 44b66bb commit fd92a47
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 15 deletions.
31 changes: 26 additions & 5 deletions hooks/common/pre-flow-feature-finish
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ VERSION=$1
ORIGIN=$2
BRANCH=$3
ORIGIN_URL=$(git config remote.${ORIGIN}.url)
CURRENT_BRANCH=$(git branch --show-current)

# Find the folder location through potential symlinks
if [[ -z $HOOKS_DIR ]]; then
Expand All @@ -40,7 +41,11 @@ if [[ $ORIGIN_URL =~ ^git@github\.com ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${DEVELOP_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${DEVELOP_BRANCH}:${DEVELOP_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $DEVELOP_BRANCH from $ORIGIN"
else
die "gh is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
Expand All @@ -53,7 +58,11 @@ elif [[ $ORIGIN_URL =~ ^https://github\.com ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${DEVELOP_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${DEVELOP_BRANCH}:${DEVELOP_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $DEVELOP_BRANCH from $ORIGIN"
else
die "gh is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
Expand All @@ -75,7 +84,11 @@ elif [[ $ORIGIN_URL =~ ^git@bitbucket\.org ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${DEVELOP_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${DEVELOP_BRANCH}:${DEVELOP_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $DEVELOP_BRANCH from $ORIGIN"
elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
repo=$(echo $ORIGIN_URL | sed -e 's/https:\/\/.*bitbucket\.org\///' -e 's/\.git$//')
Expand All @@ -94,7 +107,11 @@ elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${DEVELOP_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${DEVELOP_BRANCH}:${DEVELOP_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $DEVELOP_BRANCH from $ORIGIN"
elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
if command -v glab &> /dev/null; then
Expand All @@ -104,7 +121,11 @@ elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${DEVELOP_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${DEVELOP_BRANCH}:${DEVELOP_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $DEVELOP_BRANCH from $ORIGIN"
else
die "glab is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
Expand Down
31 changes: 26 additions & 5 deletions hooks/common/pre-flow-hotfix-finish
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ VERSION=$1
ORIGIN=$2
BRANCH=$3
ORIGIN_URL=$(git config remote.${ORIGIN}.url)
CURRENT_BRANCH=$(git branch --show-current)

# Find the folder location through potential symlinks
if [[ -z $HOOKS_DIR ]]; then
Expand All @@ -40,7 +41,11 @@ if [[ $ORIGIN_URL =~ ^git@github\.com ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
else
die "gh is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
Expand All @@ -53,7 +58,11 @@ elif [[ $ORIGIN_URL =~ ^https://github\.com ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
else
die "gh is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
Expand All @@ -75,7 +84,11 @@ elif [[ $ORIGIN_URL =~ ^git@bitbucket\.org ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
repo=$(echo $ORIGIN_URL | sed -e 's/https:\/\/.*bitbucket\.org\///' -e 's/\.git$//')
Expand All @@ -94,7 +107,11 @@ elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
if command -v glab &> /dev/null; then
Expand All @@ -104,7 +121,11 @@ elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
else
die "glab is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
Expand Down
31 changes: 26 additions & 5 deletions hooks/common/pre-flow-release-finish
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ VERSION=$1
ORIGIN=$2
BRANCH=$3
ORIGIN_URL=$(git config remote.${ORIGIN}.url)
CURRENT_BRANCH=$(git branch --show-current)

# Find the folder location through potential symlinks
if [[ -z $HOOKS_DIR ]]; then
Expand All @@ -40,7 +41,11 @@ if [[ $ORIGIN_URL =~ ^git@github\.com ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
else
die "gh is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
Expand All @@ -53,7 +58,11 @@ elif [[ $ORIGIN_URL =~ ^https://github\.com ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
else
die "gh is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
Expand All @@ -75,7 +84,11 @@ elif [[ $ORIGIN_URL =~ ^git@bitbucket\.org ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
repo=$(echo $ORIGIN_URL | sed -e 's/https:\/\/.*bitbucket\.org\///' -e 's/\.git$//')
Expand All @@ -94,7 +107,11 @@ elif [[ $ORIGIN_URL =~ ^https://.*bitbucket\.org ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
if command -v glab &> /dev/null; then
Expand All @@ -104,7 +121,11 @@ elif [[ $ORIGIN_URL =~ ^git@gitlab\.com ]]; then
die "There is a Pull Request that is not yet merged, please wait (Status: $PR_STATE)"
fi
verbose "Fetching ${MASTER_BRANCH} from $ORIGIN"
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
git pull
else
git fetch $ORIGIN ${MASTER_BRANCH}:${MASTER_BRANCH}
fi
die_on_error "Failed to fetch $MASTER_BRANCH from $ORIGIN"
else
die "glab is not available, so I cannot check pull request states on $ORIGIN ($ORIGIN_URL)"
Expand Down

0 comments on commit fd92a47

Please sign in to comment.