1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

repo コマンドの manifestファイルにほぼローカルファイルを指定する

Last updated at Posted at 2020-10-25

repo コマンドの manifestファイルにほぼローカルファイルを指定する

背景

Google が Android の開発用に作成した repo というツールがあります。

repo init -u リモートURL -b ブランチ名 [-m manifestファイルのファイル名]

ローカルにあるマニフェストファイルを指定したい場合でも、-u オプションは必須なので省略することができません。
通常は別途マニフェストファイルを管理するためのリポジトリを用意する必要があり、面倒です。

-u オプションを省略すると以下のようなエラーなります。

$ repo init -m default.xml
Downloading Repo source from https://gerrit.googlesource.com/git-repo
fatal: manifest url (-u) is required.

ネットで検索すると local_manifest.xml というファイル名にすればいい、とか情報があったのですが、うまくいきませんでした。

https://stackoverflow.com/questions/15926159/repo-using-local-manifest-does-not-work の情報をもとに回避策を思いついたので共有します。
上記の方法自体では、別にリポジトリを作らないといけないので面倒なので、それを改善しています。

解決方法

大前提

正確にいうと、ローカルファイルとは言えないのですが、マニフェストファイルの管理用に別のリポジトリを用意しないというように解釈です。

  • manifestファイル以外の必要なファイルがあり、それを git で管理している。(or する予定である)
  • manifestファイルの管理を、既存のリポジトリにコミットして、相乗りする。

具体的な方法

repo init -m default.xml -u $(git rev-parse --show-toplevel) -b $(git rev-parse HEAD)
repo sync -j4

注意

上記の repo コマンドを実行する前に default.xml をコミットしておく必要があります。
これは実際は、manifestファイルとしてローカルファイルを指定しているわけではないからです。

解説

  1. プロジェクト全体を管理する git リポジトリを作ります。
  2. manifestファイルに加えて、必要なファイルを登録します。
  3. repo はそのリポジトリをローカルに clone したリポジトリの中で実行する。
  4. repo init で -m には、自分が今いるリポジトリの絶対パスを指定します。
  5. repo init で -b には、自分が今いるリポジトリのブランチ名を指定します。

git rev-parse --show-toplevel を git リポジトリの中で実行すると、git リポジトリの最上位ディレクトリを絶対パスで返します。
git rev-parse HEAD を git リポジトリの中で実行すると、現在のコミットハッシュを返します。

ポイントは、-m にリモートのリポジトリを指定するのではなく、ローカルのリポジトリを指定することです。

参考URL

repo の manifest ファイル関連のリンク

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?