Skip to content

git: Persist system-wide config#7632

Merged
z-Fng merged 9 commits intoScoopInstaller:masterfrom
ChuckieChen945:ChuckieChen945-patch-1
Mar 5, 2026
Merged

git: Persist system-wide config#7632
z-Fng merged 9 commits intoScoopInstaller:masterfrom
ChuckieChen945:ChuckieChen945-patch-1

Conversation

@ChuckieChen945
Copy link
Contributor

@ChuckieChen945 ChuckieChen945 commented Feb 13, 2026

Fixes #7631. This adds 'etc/gitconfig' to the persist field to ensure user configurations are preserved during updates.

Closes #7631

  • Use conventional PR title: <manifest-name[@version]|chore>: <general summary of the pull request>
  • I have read the Contributing Guide

Summary by CodeRabbit

  • New Features
    • Git configuration is now automatically saved before uninstallation and restored during installation, preserving user git settings across updates.
    • The process creates required directories and checks for existing configurations to ensure a safe restore.

Fixes ScoopInstaller#7631. This adds 'etc/gitconfig' to the persist field to ensure user configurations are preserved during updates.
@github-actions
Copy link
Contributor

All changes look good.

Wait for review from human collaborators.

git

  • Lint
  • Description
  • License
  • Hashes
  • Checkver
  • Autoupdate
  • Autoupdate Hash Extraction

Check the full log for details.

@z-Fng z-Fng changed the title git@2.53.0: Add missing persist field git: Persist system-level config Mar 3, 2026
@z-Fng
Copy link
Member

z-Fng commented Mar 3, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

Adds pre_install and pre_uninstall lifecycle hooks to the git manifest to restore a persisted system gitconfig (updating versioned path references) during install and to persist the current gitconfig before uninstall, with file existence checks and directory creation as needed.

Changes

Cohort / File(s) Summary
Git Configuration Lifecycle Hooks
bucket/git.json
Adds pre_install and pre_uninstall hook arrays that restore a persisted etc/gitconfig (with path updates) during installation and back up the active etc/gitconfig to a persisted location before uninstallation; includes file presence checks, copy operations, and directory creation logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description references issue #7631 and confirms the contributor followed repository conventions, though it lacks detail about the technical implementation of the persist mechanism.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'git: Persist system-wide config' accurately summarizes the main change—adding persistence for system-level Git configuration across updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
bucket/git.json (1)

37-37: Regex replacement may be overly broad.

The pattern (?<=git/)[\\d.]+(?=/) matches any digit-dot sequence between git/ and /, which could unintentionally modify version-like strings in other contexts within the config (e.g., commented examples, URLs, or user-defined paths).

Consider whether a more specific pattern anchored to known path structures would be safer, or verify this is acceptable for the typical contents of etc/gitconfig.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bucket/git.json` at line 37, The replacement regex "(?<=git/)[\\d.]+(?=/)" is
too generic and may alter unrelated version-like strings; update the PowerShell
one-liner (the string containing Get-Content ... -replace ...) to restrict
matching to actual Git URL/path lines by anchoring or adding surrounding
context—e.g., only apply the replace to lines that contain the Git remote or
"url =" prefix or require a semantic version pattern (like x.y.z) with explicit
separators—so adjust the regex or pre-filter the file content to target known
path structures before calling -replace.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bucket/git.json`:
- Around line 29-39: The Get-Content/Set-Content sequence in the pre_install
script risks corrupting non-ASCII text because Get-Content uses the system
default encoding while Set-Content writes with -Encoding utf8 (which on
PowerShell 5.1 produces a BOM). Update the restore block to read and write with
the same explicit encoding: pass -Encoding utf8NoBOM (or a chosen consistent
encoding) to both Get-Content and Set-Content so non-ASCII characters are
preserved and no BOM is introduced; locate the commands referencing Get-Content
and Set-Content in the pre_install script and make the encoding arguments
consistent.

---

Nitpick comments:
In `@bucket/git.json`:
- Line 37: The replacement regex "(?<=git/)[\\d.]+(?=/)" is too generic and may
alter unrelated version-like strings; update the PowerShell one-liner (the
string containing Get-Content ... -replace ...) to restrict matching to actual
Git URL/path lines by anchoring or adding surrounding context—e.g., only apply
the replace to lines that contain the Git remote or "url =" prefix or require a
semantic version pattern (like x.y.z) with explicit separators—so adjust the
regex or pre-filter the file content to target known path structures before
calling -replace.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4686693 and 33d8176.

📒 Files selected for processing (1)
  • bucket/git.json

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
bucket/git.json (1)

35-35: Prefer -LiteralPath for file copies built from variables.

Use -LiteralPath on Line 35 and Line 85 to avoid wildcard interpretation surprises in path strings.

Proposed fix
-        "    Copy-Item -Path $config_path_persisted -Destination $config_path -Force",
+        "    Copy-Item -LiteralPath $config_path_persisted -Destination $config_path -Force",
...
-        "    Copy-Item -Path $config_path -Destination $config_path_persisted -Force",
+        "    Copy-Item -LiteralPath $config_path -Destination $config_path_persisted -Force",

Also applies to: 85-85

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bucket/git.json` at line 35, Replace the Copy-Item invocations that use the
-Path parameter with -LiteralPath to avoid wildcard interpretation for
variable-built paths: update the string containing "Copy-Item -Path
$config_path_persisted -Destination $config_path -Force" (line with that exact
Copy-Item call) and the other Copy-Item occurrence around line 85 to use
-LiteralPath instead of -Path, keeping the same -Destination and -Force flags.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bucket/git.json`:
- Line 37: The current PowerShell replace command is too broad — it replaces any
"git/<digits>/" anywhere; narrow the regex to match only Scoop Git install-paths
by changing the lookbehind to the install path prefix (e.g. use
'(?<=scoop/apps/git/)[\\d.]+' with the same trailing (?=/) ) in the command that
uses Get-Content -Path $config_path -Encoding UTF8 and Set-Content -Path
$config_path -Encoding UTF8 so the replacement of $version only targets
scoop/apps/git/<version>/ entries.

---

Nitpick comments:
In `@bucket/git.json`:
- Line 35: Replace the Copy-Item invocations that use the -Path parameter with
-LiteralPath to avoid wildcard interpretation for variable-built paths: update
the string containing "Copy-Item -Path $config_path_persisted -Destination
$config_path -Force" (line with that exact Copy-Item call) and the other
Copy-Item occurrence around line 85 to use -LiteralPath instead of -Path,
keeping the same -Destination and -Force flags.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33d8176 and bd7c068.

📒 Files selected for processing (1)
  • bucket/git.json

@z-Fng
Copy link
Member

z-Fng commented Mar 3, 2026

cc @SorYoshino Could you please take a look and give it a quick test? Just want to be sure nothing slipped through the cracks.

@SorYoshino
Copy link
Contributor

Could you please take a look and give it a quick test? Just want to be sure nothing slipped through the cracks.

Apologies for the delayed response. I have been overwhelmed with work recently, both physically and mentally.

The related script contains some unnecessary logic and appears somewhat verbose. However, testing results indicate that it functions correctly.

The test results are as follows:
┏[ D:\Software\Scoop\Local\buckets\Unofficial][ master ≡  1]
└─> scoop install "D:\Software\Scoop\Global\apps\Git\_2.53.0.old\git.json"
Installing 'git' (2.51.2) [64bit] from 'D:\Software\Scoop\Global\apps\Git\_2.53.0.old\git.json'
Loading PortableGit-2.51.2-64-bit.7z.exe from cache.
Checking hash of PortableGit-2.51.2-64-bit.7z.exe... OK.
Extracting PortableGit-2.51.2-64-bit.7z.exe... Done.
Running pre_install script... Done.
Linking D:\Software\Scoop\Local\apps\git\current => D:\Software\Scoop\Local\apps\git\2.51.2
Creating shim for 'sh'.
Creating shim for 'git'.
Creating shim for 'git-bash'.
Making D:\Software\Scoop\Local\shims\git-bash.exe a GUI binary.
Creating shim for 'gpg'.
Creating shim for 'gpg-agent'.
Creating shim for 'gpgconf'.
Creating shim for 'gpg-connect-agent'.
Creating shim for 'pinentry'.
Making D:\Software\Scoop\Local\shims\pinentry.exe a GUI binary.
Creating shortcut for Git\Git Bash (git-bash.exe)
Creating shortcut for Git\Git CMD (git-cmd.exe)
Creating shortcut for Git\Git GUI (git-gui.exe)
Adding D:\Software\Scoop\Local\apps\git\current\cmd to your path.
Setting user environment variable: GIT_INSTALL_ROOT = D:\Software\Scoop\Local\apps\git\current
Running post_install script... Done.
'git' (2.51.2) was installed successfully!
Notes
-----
To register file associations, please execute the following command:
reg import "D:\Software\Scoop\Local\apps\git\current\install-associations.reg"

To register the context menu entry, please execute the following command:
reg import "D:\Software\Scoop\Local\apps\git\current\install-context.reg"

To set Git Credential Manager Core for portable Git, please execute the following command:
git config --global credential.helper manager
-----

┏[ D:\Software\Scoop\Local\buckets\Unofficial][ master ≡  1]
└─> Get-Content -Path "$(scoop prefix git)\etc\gitconfig" -Encoding utf8 -Tail 2
[credential]
        helper = helper-selector

┏[ D:\Software\Scoop\Local\buckets\Unofficial][ master ≡  1]
└─> git push
Everything up-to-date

┏[ D:\Software\Scoop\Local\buckets\Unofficial][ master ≡  1]
└─> Get-Content -Path "$(scoop prefix git)\etc\gitconfig" -Encoding utf8 -Tail 2
[credential]
        helper = !\"D:/Software/Scoop/Local/apps/git/2.51.2/mingw64/bin/git-credential-manager.exe\"

┏[ D:\Software\Scoop\Local\buckets\Unofficial][ master ≡  1]
└─> scoop update git
git: 2.51.2 -> 2.53.0
Updating one outdated app:
Updating 'git' (2.51.2 -> 2.53.0)
Downloading new version
Loading PortableGit-2.53.0-64-bit.7z.exe from cache.
Checking hash of PortableGit-2.53.0-64-bit.7z.exe... OK.
Running pre_uninstall script... INFO  Saving system-level config to D:\Software\Scoop\Local\persist\git\etc\gitconfig...
Done.
Uninstalling 'git' (2.51.2)
Running uninstaller script... Done.
Removing shim 'sh.shim'.
Removing shim 'sh.exe'.
Removing shim 'git.shim'.
Removing shim 'git.exe'.
Removing shim 'git-bash.shim'.
Removing shim 'git-bash.exe'.
Removing shim 'gpg.shim'.
Removing shim 'gpg.exe'.
Removing shim 'gpg-agent.shim'.
Removing shim 'gpg-agent.exe'.
Removing shim 'gpgconf.shim'.
Removing shim 'gpgconf.exe'.
Removing shim 'gpg-connect-agent.shim'.
Removing shim 'gpg-connect-agent.exe'.
Removing shim 'pinentry.shim'.
Removing shim 'pinentry.exe'.
Unlinking D:\Software\Scoop\Local\apps\git\current
Removing D:\Software\Scoop\Local\apps\git\current\cmd from your path.
Removing user environment variable: GIT_INSTALL_ROOT
Installing 'git' (2.53.0) [64bit] from 'D:\Software\Scoop\Global\apps\Git\_2.53.0.old\git.json'
Loading PortableGit-2.53.0-64-bit.7z.exe from cache.
Extracting PortableGit-2.53.0-64-bit.7z.exe... Done.
Running pre_install script... INFO  Restoring system-level config from D:\Software\Scoop\Local\persist\git\etc\gitconfig...
INFO  Adjusting paths in D:\Software\Scoop\Local\apps\git\2.53.0\etc\gitconfig...
Done.
Linking D:\Software\Scoop\Local\apps\git\current => D:\Software\Scoop\Local\apps\git\2.53.0
Creating shim for 'sh'.
Creating shim for 'git'.
Creating shim for 'git-bash'.
Making D:\Software\Scoop\Local\shims\git-bash.exe a GUI binary.
Creating shim for 'gpg'.
Creating shim for 'gpg-agent'.
Creating shim for 'gpgconf'.
Creating shim for 'gpg-connect-agent'.
Creating shim for 'pinentry'.
Making D:\Software\Scoop\Local\shims\pinentry.exe a GUI binary.
Creating shortcut for Git\Git Bash (git-bash.exe)
Creating shortcut for Git\Git CMD (git-cmd.exe)
Creating shortcut for Git\Git GUI (git-gui.exe)
Adding D:\Software\Scoop\Local\apps\git\current\cmd to your path.
Setting user environment variable: GIT_INSTALL_ROOT = D:\Software\Scoop\Local\apps\git\current
Running post_install script... Done.
'git' (2.53.0) was installed successfully!
Notes
-----
To register file associations, please execute the following command:
reg import "D:\Software\Scoop\Local\apps\git\current\install-associations.reg"

To register the context menu entry, please execute the following command:
reg import "D:\Software\Scoop\Local\apps\git\current\install-context.reg"

To set Git Credential Manager Core for portable Git, please execute the following command:
git config --global credential.helper manager
-----

┏[ D:\Software\Scoop\Local\buckets\Unofficial][ master ≡  1]
└─> Get-Content -Path "$(scoop prefix git)\etc\gitconfig" -Encoding utf8 -Tail 2
[credential]
        helper = !\"D:/Software/Scoop/Local/apps/git/2.53.0/mingw64/bin/git-credential-manager.exe\"

Incidentally, regardless of whether git config --global credential.helper manager was previously used, earlier versions of the manifest would trigger a prompt window when running git push after an update. Should the related content in the notes field be removed?

@z-Fng z-Fng changed the title git: Persist system-level config git: Persist system-wide config Mar 5, 2026
@z-Fng
Copy link
Member

z-Fng commented Mar 5, 2026

Thanks a lot for the help with testing!

Apologies for the delayed response. I have been overwhelmed with work recently, both physically and mentally.

No worries at all! Don't feel pressured to reply right away -- just focus on taking care of yourself first. Hope things get easier soon. Thank you so much for testing.

Incidentally, regardless of whether git config --global credential.helper manager was previously used, earlier versions of the manifest would trigger a prompt window when running git push after an update. Should the related content in the notes field be removed?

Switching from --global to --system should resolve the issue.

git config --system credential.helper manager

@ScoopInstaller ScoopInstaller deleted a comment from github-actions bot Mar 5, 2026
@z-Fng
Copy link
Member

z-Fng commented Mar 5, 2026

/verify

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

All changes look good.

Wait for review from human collaborators.

git

  • Lint
  • Description
  • License
  • Hashes
  • Checkver
  • Autoupdate
  • Autoupdate Hash Extraction

Check the full log for details.

Copy link
Member

@z-Fng z-Fng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@z-Fng z-Fng merged commit 15feaf8 into ScoopInstaller:master Mar 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: git: System-level Git configuration was not persisted

3 participants