Commit 2226b75
fix: Skip redundant git config writes in SignIn when already correct
Context:
On every `git fetch`, git calls `credential approve` after successful
authentication, which invokes GCM's StoreCredentialAsync. For OAuth
flows against Azure Repos, this calls SignIn(orgName, userName) to
record the user-to-org binding in git config.
In the common single-user steady state — global binding already set
to the authenticated user, no local override — SignIn was still
issuing `git config --global credential.azrepos:org/<org>.username`
and `git config --local --unset credential.azrepos:org/<org>.username`
on every invocation, even though neither write was needed.
Justification:
The else branch of SignIn that handles "global absent or matches"
called Bind(global) + Unbind(local) unconditionally, without first
checking whether the state was already correct. The fix adds minimal
guards: skip Bind(global) if global is already set to the signing-in
user, skip Unbind(local) if local is already absent. This eliminates
the round-trips to git in the steady state without changing the
outcome in any other case.
The same pattern applies to the B|A case (different user holds the
global binding, local is already set to the signing-in user): that
branch also skipped the write check, so it is guarded here too.
Implementation:
Modified SignIn to skip writes when already in the desired state:
A | - -> A | - no writes (previously Set(global)+Unset(local))
A | A -> A | - only Unset(local), Set(global) skipped
A | B -> A | - only Unset(local), Set(global) skipped
B | A -> B | A no writes (already correct, was also correct)
Added four tests to AzureReposBindingManagerTests using the new
SetCallCount/UnsetCallCount counters to assert the precise number
of config writes for each case.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 944726b commit 2226b75
File tree
2 files changed
+102
-3
lines changed2 files changed
+102
-3
lines changedLines changed: 87 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
628 | 628 | | |
629 | 629 | | |
630 | 630 | | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
631 | 718 | | |
632 | 719 | | |
633 | 720 | | |
| |||
Lines changed: 15 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | | - | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
287 | 292 | | |
288 | 293 | | |
289 | 294 | | |
290 | | - | |
291 | | - | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
292 | 304 | | |
293 | 305 | | |
294 | 306 | | |
| |||
0 commit comments