Skip to content

Commit 8e561db

Browse files
committed
Reset master, checkout head locally
There was a problem where adding new subtree splits for paths that did not exist when master was originally checked out were not able to be created. Splits were created correctly based on the commitish ( origin/master, etc. ) but if the path did not exist in the working directory prior to `git subtree` being called the subtree command would fail.
1 parent b25d1be commit 8e561db

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

git-subsplit.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,18 @@ subsplit_publish()
216216
fi
217217

218218
say " - syncing branch '${HEAD}'"
219+
git checkout master >/dev/null 2>&1
219220
git branch -D "$LOCAL_BRANCH" >/dev/null 2>&1
221+
git branch -D "${LOCAL_BRANCH}-checkout" >/dev/null 2>&1
222+
git checkout -b "${LOCAL_BRANCH}-checkout" "origin/${HEAD}" >/dev/null 2>&1
220223
git subtree split -q --prefix="$SUBPATH" --branch="$LOCAL_BRANCH" "origin/${HEAD}" >/dev/null
221224

222225
if [ -n "$VERBOSE" ];
223226
then
227+
echo "${DEBUG} git checkout master >/dev/null 2>&1"
224228
echo "${DEBUG} git branch -D \"$LOCAL_BRANCH\" >/dev/null 2>&1"
229+
echo "${DEBUG} git branch -D \"${LOCAL_BRANCH}-checkout\" >/dev/null 2>&1"
230+
echo "${DEBUG} git checkout -b \"${LOCAL_BRANCH}-checkout\" \"origin/${HEAD}\" >/dev/null 2>&1"
225231
echo "${DEBUG} git subtree split -q --prefix=\"$SUBPATH\" --branch=\"$LOCAL_BRANCH\" \"origin/${HEAD}\" >/dev/null"
226232
fi
227233

@@ -323,11 +329,15 @@ subsplit_update()
323329

324330
git fetch -q origin
325331
git fetch -q -t origin
332+
git checkout master
333+
git reset --hard origin/master
326334

327335
if [ -n "$VERBOSE" ];
328336
then
329337
echo "${DEBUG} git fetch -q origin"
330338
echo "${DEBUG} git fetch -q -t origin"
339+
echo "${DEBUG} git checkout master"
340+
echo "${DEBUG} git reset --hard origin/master"
331341
fi
332342

333343
popd >/dev/null

0 commit comments

Comments
 (0)