Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe53823

Browse files
committed
Have init script treat master unambiguously as a branch
Because users may have an old version of git without "git switch",init-tests-after-clone.sh should continue to use "git checkout" toattempt to switch to master. But without "--", this suffers fromthe problem that it's ambiguous if master is a branch (so checkoutbehaves like switch) or a path (so checkout behaves like restore).There are two cases where this ambiguity can be a problem. The mostcommon is on a fork with no master branch but also, fortunately, nofile or directory named "master". Then the problem is just theerror message (printed just before the script proceeds to redothe checkout with -b): error: pathspec 'master' did not match any file(s) known to gitThe real cause of the error is the branch being absent, as happenswhen a fork copies only the main branch and the upstream remote isnot also set up. Adding the "--" improves the error message: fatal: invalid reference: masterHowever, it is possible, though unlikely, for a file or directorycalled "master" to exist. In that case, if there is also no masterbranch, git discards unstaged changes made to the file or (muchworse!) everywhere in that directory, potentially losing work.This commit adds "--" to the right of "master" so git neverregards it as a path. This is not needed with -b, which is alwaysfollowed by a symbolic name, so I have not added it there.(Note that the command is still imperfect because, for example, inrare cases there could be a master *tag*--and no master branch--inwhich case, as before, HEAD would be detached there and the scriptwould attempt to continue.)
1 parente973f52 commitbe53823

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎init-tests-after-clone.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if [[ -z "$TRAVIS" ]]; then
1010
fi
1111

1212
git tag __testing_point__
13-
git checkout master|| git checkout -b master
13+
git checkout master--|| git checkout -b master
1414
git reset --hard HEAD~1
1515
git reset --hard HEAD~1
1616
git reset --hard HEAD~1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp