Skip to content

Commit 84c679d

Browse files
committed
build: do git reset --hard only if git pull --ff-only fails
1 parent 483d3c6 commit 84c679d

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

scripts/clone-pull-build-run.sh

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,41 @@ command -v cmake >/dev/null || { echo REQUIRED: install cmake && exit 1; }
9393
command -v ninja >/dev/null || { echo REQUIRED: install ninja && exit 1; }
9494
command -v ccache >/dev/null || { echo REQUIRED: install ccache && exit 1; }
9595

96+
logx() { log "repo ${repo:-none} - $@"; set -x; }
97+
9698
# clone_checkout_pull sets the variable build_reason=... to trigger the build
9799
clone_checkout_pull() {
98-
local repo=$1
99-
local branch=$2
100-
local tag=$3
100+
repo=$1
101+
branch=$2
102+
tag=$3
103+
101104
build_reason=clone
102105
[ -d "${repo#*/}" ] && build_reason= ||
103-
( log "repo $repo - clone"; pwd; set -x; git clone https://github.com/"$repo" )
106+
( pwd; logx clone; git clone https://github.com/"$repo" )
107+
104108
cd "${repo#*/}"
105-
( log "repo $repo - fetch"; pwd; set -x; git fetch --prune --tags --all )
106-
( log "repo $repo - discard local changes"; set -x; git reset --hard )
109+
pwd
110+
111+
( logx fetch; git fetch --all --prune --tags )
112+
107113
if [[ -n "$tag" ]]
108114
then
109115
build_reason="tag: $tag"
110-
( log "repo $repo - checkout $tag"; set -x; git checkout "$tag" )
116+
( logx "checkout $tag"; git checkout "$tag" )
111117
else
112-
( log "repo $repo - switch $branch"; set -x; git switch -C "$branch" origin/"$branch" )
113-
local remote="$(git rev-parse "@{upstream}")"
114-
local local="$( git rev-parse HEAD)"
115-
if [[ "$remote" != "$local" ]]
118+
( logx "switch $branch"; git switch -C "$branch" origin/"$branch" )
119+
120+
local="$( git rev-parse HEAD)"
121+
remote="$(git rev-parse "@{upstream}")"
122+
if [[ "$local" != "$remote" ]]
116123
then
117124
build_reason="new commit: $(git log -1 --pretty=format:%f)"
118-
log "repo $repo - $build_reason";
119-
( set -x ; git pull --ff-only )
125+
( logx "$build_reason"; git pull --ff-only ) ||
126+
( logx "discard local changes"; git reset --hard )
120127
fi
121128
fi
122-
( set -x ; git status --short )
129+
130+
( set -x; git status --short )
123131
}
124132

125133
# CPU flags used to build llama.cpp and goinfer

0 commit comments

Comments
 (0)