LoginSignup
0
1

More than 5 years have passed since last update.

Travis CIでfatal: ambiguous argument 'origin/master'

Posted at

Travis CIでgit diffのような現在ブランチと別のブランチを比較して差分のみを扱うようなコマンドを書いた場合に次のようなエラーとなる場合があります。

# 変更されたファイルのみを扱う
> git diff --name-only --diff-filter=ACMR origin/develop | echo

fatal: ambiguous argument 'origin/develop': unknown revision or path not in the working tree.

Use '--' to separate paths from revisions, like this:

'git <command> [<revision>...] -- [<file>...]'

ローカルでは起きなくて、Travis CIのみで起きるのはそもそもTravis CIはデフォルトでリポジトリを
shallow cloneしているからです。

$ git clone --depth=50 --branch=2015-09-29JavaScript https://github.com/jser/jser.github.io.git jser/jser.github.io

という感じで、--depthを付けて一部だけcloneしています。

そのため、Travis CIでcloneした直後は、--branch=で指定したブランチのみで、masterなどが存在しないようになっています。

なのでgit diff --name-only --diff-filter=ACMR origin/developというように、現在ブランチとorigin/developを比較しようとするとそんなブランチがないと言われます。

修正方法

一部しかcloneしてないので、全部fetchするようにすれば問題なくなるはずです。

なので、.travis.ymlgit fetch --unshallowで全部fetchするようにしておけば問題なくなります。(その代わり全部ダウンロードするので遅くはなります)

before_install:
- git fetch --unshallow

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1