This module provides git repository operations for pushing encrypted files to GitHub, maintaining version control while preserving existing remote data.
fmt: String formatting and printingtime: Time package for commit timestampsgithub.com/go-git/go-billy/v5/memfs: In-memory filesystemgithub.com/go-git/go-git/v5: Git operations librarygithub.com/go-git/go-git/v5/config: Git configurationgithub.com/go-git/go-git/v5/plumbing: Git plumbing operationsgithub.com/go-git/go-git/v5/plumbing/object: Git object typesgithub.com/go-git/go-git/v5/plumbing/transport/ssh: SSH transport for gitgithub.com/go-git/go-git/v5/storage/memory: In-memory git storagegolang.org/x/crypto/ssh: SSH cryptography utilities
func PushFiles(repoURL string, rawPrivateKey []byte, files map[string][]byte, commitMsg string) errorPerforms stateless append/update operations to a git repository while preserving existing remote files. This function handles incremental updates without downloading the entire repository history.
Parameters:
repoURL: The git repository URL (e.g., "git@github.com:username/.zephyrus.git")rawPrivateKey: The raw SSH private key bytes for authenticationfiles: A map of file paths to their content to push- Key: File path in the repository
- Value: File content as bytes
commitMsg: The commit message to use
Return:
error: Returns an error if clone, file write, commit, or push operations fail
Process:
- SSH Authentication: Sets up SSH authentication using the provided private key
- Clone Repository: Clones the repository with shallow depth (Depth=1) to minimize bandwidth
- Create/Update Files: Writes files to the in-memory filesystem
- New files are created
- Existing files are overwritten with new content
- Stage Files: Stages all modified files for commit
- Check for Changes: Verifies that changes exist before committing
- Commit: Creates a commit with the specified message and Zephyrus author information
- Push: Pushes the commit to the remote master branch using SSH
Error Handling:
- Returns error if cloning fails
- Returns error if file creation fails
- Returns error if staging fails
- Returns error if commit fails
- Returns error if push fails
- Returns nil if no changes were made (clean status)
Notes:
- Uses shallow clone (Depth=1) for performance
- Ignores SSH host key verification (insecure but necessary for automation)
- Commits are attributed to "Zephyrus" user
- File paths can include subdirectories (e.g., ".config/index")
- Existing files on remote are not downloaded; only new/modified files are uploaded
Example Usage:
files := map[string][]byte{
"storage_id_1": encryptedFileData1,
".config/index": indexData,
}
err := PushFiles(
"git@github.com:myusername/.zephyrus.git",
privateKeyBytes,
files,
"Nexus: Uploaded new files",
)
if err != nil {
log.Fatal(err)
}