From 85e409e69a1c5286e3bf49b9f002402f09ee5276 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 24 Apr 2024 16:17:17 +0000 Subject: [PATCH] git cl: fix a bug that may output stale upstream branch git cl upstream will run `git branch --set-upstream-to xxx` command which modifies the git config. However, it doesn't invalidate config cache. I think an ideal fix would be the git scm exposes method to invalidate cache and the caller of git command needs to explicitly invalidate the cache right after git command invocation. However, I decide to take a "clever" approach here because this seems to be the only place in git cl that requires explicit cache eviction. It may not be worth to expose the existence of cache just for this reason. The "clever" approach swaps the order of subseqent config modification and config reading. The config modification will always invalidate the cache. Therefore, It will ensure we are always reading up-to-date upstream branch name from the fresh config cahce. Bug: 40942309 Change-Id: I3786fd37799092ce269c7c4d3945c51d077335cb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5479950 Reviewed-by: Josip Sokcevic Commit-Queue: Yiwei Zhang --- git_cl.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/git_cl.py b/git_cl.py index 2f7570bc5..274767c25 100755 --- a/git_cl.py +++ b/git_cl.py @@ -5822,11 +5822,10 @@ def CMDupstream(parser, args): # One arg means set upstream branch. branch = cl.GetBranch() RunGit(['branch', '--set-upstream-to', args[0], branch]) - cl = Changelist() - print('Upstream branch set to %s' % (cl.GetUpstreamBranch(), )) - # Clear configured merge-base, if there is one. git_common.remove_merge_base(branch) + cl = Changelist() + print('Upstream branch set to %s' % (cl.GetUpstreamBranch(), )) else: print(cl.GetUpstreamBranch()) return 0