Browse Source

Track origin/lkgr when using --lkgr flag in new-branch

Passing --lkgr tracks the local "lkgr" branch which may not exist.
"origin/lkgr" is a better default since that should exist for projects
that have a lkgr.

Bug: 366394191
Change-Id: I2a0ce1a4d8540ce2e3ca06ef892e288c9892cf0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5876340
Auto-Submit: Gavin Mak <gavinmak@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Gavin Mak 11 months ago
parent
commit
bba50600f8
2 changed files with 16 additions and 11 deletions
  1. 1 1
      git_new_branch.py
  2. 15 10
      tests/git_rebase_update_test.py

+ 1 - 1
git_new_branch.py

@@ -77,7 +77,7 @@ def main(args):
                    ' and new branch becomes current branch\'s upstream.')
     g.add_argument('--lkgr',
                    action='store_const',
-                   const='lkgr',
+                   const='origin/lkgr',
                    dest='upstream',
                    help='set basis ref for new branch to lkgr.')
 

+ 15 - 10
tests/git_rebase_update_test.py

@@ -325,17 +325,21 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
         self.assertIn('  branch_K', output)
 
     def testTrackTag(self):
-        self.origin.git('tag', 'lkgr', self.origin['M'])
-        self.repo.git('tag', 'lkgr', self.repo['D'])
+        self.origin.git('tag', 'tag-to-track', self.origin['M'])
+        self.repo.git('tag', 'tag-to-track', self.repo['D'])
 
         self.repo.git('config', 'branch.branch_G.remote', '.')
-        self.repo.git('config', 'branch.branch_G.merge', 'refs/tags/lkgr')
+        self.repo.git('config', 'branch.branch_G.merge',
+                      'refs/tags/tag-to-track')
 
         self.assertIn(
             'fatal: \'foo bar\' is not a valid branch name',
-            self.repo.capture_stdio(self.nb.main, ['--lkgr', 'foo bar'])[1])
+            self.repo.capture_stdio(
+                self.nb.main,
+                ['--upstream', 'tags/tag-to-track', 'foo bar'])[1])
 
-        self.repo.run(self.nb.main, ['--lkgr', 'foobar'])
+        self.repo.run(self.nb.main,
+                      ['--upstream', 'tags/tag-to-track', 'foobar'])
 
         with self.repo.open('foobar', 'w') as f:
             f.write('this is the foobar file')
@@ -361,7 +365,8 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
         self.assertIn('Rebasing: branch_L', output)
         self.assertIn('Rebasing: foobar', output)
         self.assertEqual(
-            self.repo.git('rev-parse', 'lkgr').stdout.strip(), self.origin['M'])
+            self.repo.git('rev-parse', 'tags/tag-to-track').stdout.strip(),
+            self.origin['M'])
 
         self.assertSchema("""
     A B C D E F G M N O
@@ -373,7 +378,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
         self.assertIn('fatal: invalid reference', err)
 
         output, _ = self.repo.capture_stdio(self.rp.main, ['tag_F'])
-        self.assertIn('to track tag_F [tag] (was lkgr [tag])', output)
+        self.assertIn('to track tag_F [tag] (was tag-to-track [tag])', output)
 
         self.assertSchema("""
     A B C D E F G M N O
@@ -381,8 +386,8 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
               F foobar1 foobar2
     """)
 
-        output, _ = self.repo.capture_stdio(self.rp.main, ['--lkgr'])
-        self.assertIn('to track lkgr [tag] (was tag_F [tag])', output)
+        output, _ = self.repo.capture_stdio(self.rp.main, ['tag-to-track'])
+        self.assertIn('to track tag-to-track [tag] (was tag_F [tag])', output)
 
         self.assertSchema("""
     A B C D E F G M N O
@@ -391,7 +396,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
     """)
 
         output, _ = self.repo.capture_stdio(self.rp.main, ['--root'])
-        self.assertIn('to track origin/main (was lkgr [tag])', output)
+        self.assertIn('to track origin/main (was tag-to-track [tag])', output)
 
         self.assertSchema("""
     A B C D E F G M N O foobar1 foobar2