[linearize] Ignore input commit ref

api.git.checkout uses the input commit's ref unless a ref is specified.
Following the transition from master to main this is now sometimes
'refs/heads/main' rather than master. This caused the recipe to fail to
fetch the linearized repo for builds triggered by Dart SDK commits.

Bug: b/198416551
Change-Id: I4ac04b261a0f9ed68dcc29a115fa975cb92f27d5
Reviewed-on: https://dart-review.googlesource.com/c/recipes/+/213002
Auto-Submit: Alexander Thomas <athom@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
diff --git a/README.recipes.md b/README.recipes.md
index 937e51a..96b56bf 100644
--- a/README.recipes.md
+++ b/README.recipes.md
@@ -252,7 +252,7 @@
 
 PYTHON_VERSION_COMPATIBILITY: PY2
 
-&mdash; **def [RunSteps](/recipes/dart/linearize.py#24)(api):**
+&mdash; **def [RunSteps](/recipes/dart/linearize.py#25)(api):**
 ### *recipes* / [dart/neo](/recipes/dart/neo.py)
 
 [DEPS](/recipes/dart/neo.py#23): [bisect\_build](#recipe_modules-bisect_build), [dart](#recipe_modules-dart), [depot\_tools/gitiles][depot_tools/recipe_modules/gitiles], [depot\_tools/osx\_sdk][depot_tools/recipe_modules/osx_sdk], [depot\_tools/tryserver][depot_tools/recipe_modules/tryserver], [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step]
diff --git a/recipes/dart/linearize.py b/recipes/dart/linearize.py
index 105cf2b..12478d8 100644
--- a/recipes/dart/linearize.py
+++ b/recipes/dart/linearize.py
@@ -19,6 +19,7 @@
 
 
 COMMITS_JSON = 'commits.json'
+LINEARIZED_REPO_REF = 'refs/heads/master'
 
 
 def RunSteps(api):
@@ -37,7 +38,11 @@
   author = '%s <%s>' % (commit_author['name'], commit_author['email'])
   author_date = commit_author['time']
 
-  api.git.checkout(repo, dir_path=api.path['cleanup'], use_git_cache=True)
+  api.git.checkout(
+      repo,
+      dir_path=api.path['cleanup'],
+      ref=LINEARIZED_REPO_REF,
+      use_git_cache=True)
   with api.context(cwd=api.path['checkout']):
     json_path = api.path['checkout'].join(COMMITS_JSON)
     commits = {}
@@ -56,7 +61,7 @@
     api.git('add', json_path)
     api.git('commit', '--author=%s' % author, '--date=%s' % author_date,
         '-m', message)
-    api.git('push', repo, 'HEAD:refs/heads/master')
+    api.git('push', repo, 'HEAD:%s' % LINEARIZED_REPO_REF)
 
 
 def GenTests(api):
@@ -65,7 +70,7 @@
       api.properties.generic(
           repo='https://dart.googlesource.com/a/linearized_history.git'),
       api.buildbucket.ci_build(
-          git_ref='refs/heads/master',
+          git_ref='refs/heads/main',
           git_repo='https://dart.googlesource.com/a/repo.git',
           revision='deadbeef'),
       api.step_data(