1

I am trying to write a check to make sure that a submodule actually points to a commit that is in the direct history of the master branch in that submodule (not a branch that is pending for merge on the master branch).

I tried parsing the git log output using:

    git log --format=format:%H --first-parent master | grep COMMITID

but I feel like git offers a better solution that this one, something that would rely on a more standard feature from git (not pipe'ing to grep).

For example, the super project includes the following submodule:

     A---B---C topic
     /
D---E---F---G master

If the superproject points directly to topic, then an error would be reported because next time the super project updates the submodule to master, the topic would be lost.

On the contrary:

     A---B---C topic
     /        \
D---E---F---G---H master

If super project points to master it would not report an error.

Nice to have would be to be able to check that topic is actually merged but this is currently optional because I am not even sure that I would have the commit id of topic before merge available when running the script.

Louis Caron
  • 1,043
  • 1
  • 11
  • 17
  • Actually, it is a partial duplicate because in this case, even if it is merged, I would have liked to see that it is pointing to the commit before merge. – Louis Caron May 17 '19 at 14:09
  • If the `--first-parent` constraint is omitted you can use `git merge-base --is-ancestor`. With the first parent constraint, `git rev-list ... | grep` is probably your best bet. – torek May 17 '19 at 15:42

1 Answers1

1

git branch has --contains in which branches are listed whihc contain the commit:

For example:

git branch master --contains 93730c0d57635784c67f71e56cba1548588c90d4

for more details use

git branch --help
Murtaza Hussain
  • 3,851
  • 24
  • 30
  • This actually would return no error as long as the branch is merged, even if the submodule points to the branch. If feel that there could be some cases where it does not cover the check (if there are two merge in parallel). – Louis Caron May 17 '19 at 14:13