Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6d2eaaf
if err is not equal to nil | the 'install-windows-auto-commit.ps1' fi…
noneandundefined May 12, 2025
1495288
the 'auto-commit.upx' file has been changed | added variables: versio…
noneandundefined May 12, 2025
b712d36
the 'auto-commit.upx' file has been changed | the 'auto-commit' file …
noneandundefined May 12, 2025
3c65f79
if err is not equal to nil | the 'install-windows-auto-commit.ps1' fi…
noneandundefined May 13, 2025
7379d0f
the 'auto-commit' file has been changed
noneandundefined May 13, 2025
3a4a0cc
if err is not equal to nil | added variables: versionFile, data | add…
noneandundefined May 13, 2025
3e2c808
added function DownloadBinAutoCommit | if err is not equal to nil; if…
noneandundefined May 13, 2025
264ee24
added variables: binaryURL, destPath | err := DownloadBinAutoCommit(b…
noneandundefined May 13, 2025
b17dfe9
the 'auto-commit' file has been changed | if err is not equal to nil
noneandundefined May 13, 2025
973c779
changed the 'auto-update' branch
noneandundefined May 13, 2025
d808195
added variables: size, downloaded, buffer | added condition logic: si…
noneandundefined May 13, 2025
25661e8
changed value in variable buffer | if n is greater than 0; if nw is g…
noneandundefined May 13, 2025
39c58f4
added variables: progress, hashes | if ew is not equal to nil
noneandundefined May 13, 2025
0902379
if n is not equal to nw; if errRead is not equal to nl; if errRead is…
noneandundefined May 13, 2025
44c5ed9
the 'install-linux-auto-commit.sh' file has been changed | added func…
noneandundefined May 13, 2025
0b82ac0
the 'install-linux-auto-commit.sh' file has been changed
noneandundefined May 13, 2025
aca8f53
build 'binary file' for release/push bin/auto-commit
noneandundefined May 13, 2025
5aa9154
renamed function Update -> AutoCommitUpdate
noneandundefined May 13, 2025
fff9ccd
build 'binary file' for release/push bin/auto-commit
noneandundefined May 13, 2025
0849de1
the '.gitignore' file has been changed | the 'auto-commit' file has b…
noneandundefined May 13, 2025
53e44a6
the 'pre-push' file has been changed
noneandundefined May 13, 2025
61ef758
Merge pull request #37 from thefuture-industries/auto-update
noneandundefined May 13, 2025
639ba9a
the 'README.md' file has been changed
noneandundefined May 13, 2025
f9d2cba
the 'README.md' file has been changed | the 'bin.yml' file has been c…
noneandundefined May 13, 2025
cee02d1
the 'README.md' file has been changed
noneandundefined May 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/workflows/bin.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ jobs:
fetch-depth: 0
tags: true

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23.0'

- name: Build auto-commit binary
run: go build -o ./bin/auto-commit .

- name: Set up Git
run: |
git config user.name "github-actions"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ Debug/
Release/
*.exe
bindir/
bin/
3 changes: 1 addition & 2 deletions .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ cd "$REPO_ROOT"
make fmt
make lint
make check
make buildrelease

git add .
git commit -m "build 'binary file' for release/push bin/auto-commit"
# git commit -m "build 'binary file' for release/push bin/auto-commit"

echo "[+] Success pre-push!"
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ git auto
git push
```

- 2 Option
- 2 Commands

```bash
git auto -w OR git auto --watch - Comit observer, you don't have to think and write more `git auto` -w (--watch) will figure it out when to make a comit and commit it yourself!
git auto -w - Comit observer, you dont have to think and write more `git auto` -w (--watch) will figure it out when to make a comit and commit it yourself!
git auto -v - Viewing the current version of auto-commit
git auto -u - Upgrade to the new auto-commit version
```
Binary file removed bin/auto-commit
Binary file not shown.
9 changes: 7 additions & 2 deletions define.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import "time"
const (
MAX_LINE_LENGTH uint16 = 1024
MAX_COMMIT_LENGTH uint16 = 300
MAX_COMMIT_LENGTH_WATCHER uint16 = 60
COMMIT_TIME time.Duration = 17 * time.Second
MAX_COMMIT_LENGTH_WATCHER uint16 = 45
COMMIT_TIME time.Duration = 15 * time.Second

GITHUB_API_REPO_URL string = "https://api.github.com/repos/thefuture-industries/git-auto-commit"
VERSION_FILE string = "auto-commit.version.txt"
BINARY_AUTO_COMMIT string = "auto-commit"
GITHUB_REPO_URL string = "https://github.com/thefuture-industries/git-auto-commit"
)
74 changes: 74 additions & 0 deletions files.go
Original file line number Diff line number Diff line change
@@ -1 +1,75 @@
package main

import (
"fmt"
"io"
"net/http"
"os"
"strings"
)

func DownloadBinAutoCommit(url, destPath string) error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

out, err := os.Create(destPath)
if err != nil {
return err
}
defer out.Close()

if errProgress := DownloadProgress(resp, out); errProgress != nil {
return errProgress
}

_, err = io.Copy(out, resp.Body)
return err
}

func DownloadProgress(resp *http.Response, file *os.File) error {
size := resp.ContentLength
if size <= 0 {
_, err := io.Copy(file, resp.Body)
return err
}

const progressBarWidth = 70
var downloaded int64 = 0
buffer := make([]byte, 32*1024)

for {
n, errRead := resp.Body.Read(buffer)
if n > 0 {
nw, ew := file.Write(buffer[0:n])
if nw > 0 {
downloaded += int64(nw)
progress := float64(downloaded) * 100 / float64(size)
hashes := int(progress * progressBarWidth)

fmt.Printf("\r[%-*s] %3.0f%%", progressBarWidth, strings.Repeat("#", hashes), progress*100)
}

if ew != nil {
return ew
}

if n != nw {
return io.ErrShortWrite
}
}

if errRead != nil {
if errRead == io.EOF {
break
}

return errRead
}
}

fmt.Println()
return nil
}
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func main() {
}

WatchCommit(path)
} else if len(os.Args) > 1 && (os.Args[1] == "-v" || os.Args[1] == "--version") {
GetVersion()
} else if len(os.Args) > 1 && (os.Args[1] == "-u" || os.Args[1] == "--update") {
AutoCommitUpdate()
} else {
AutoCommit()
}
Expand Down
10 changes: 8 additions & 2 deletions scripts/install-linux-auto-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ BINARY_NAME="auto-commit"
HOOKS_DIR=".git/hooks"
HOOK_PATH="$HOOKS_DIR/$BINARY_NAME"

URL="https://github.com/thefuture-industries/git-auto-commit/blob/main/bin/auto-commit?raw=true"
VERSION_URL="https://api.github.com/repos/thefuture-industries/git-auto-commit/releases/latest"
TAG=$(curl -s "$VERSION_URL" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')

URL="https://github.com/thefuture-industries/git-auto-commit/releases/download/$TAG/auto-commit"
VERSION_FILE="$HOOKS_DIR/auto-commit.version.txt"

if [ ! -d .git ]; then
echo "[!] There is no .git. Run it in the root of the Git repository."
Expand All @@ -39,7 +43,9 @@ if [[ "$answer" == "Y" || "$answer" == "y" ]]; then

git config --local alias.auto '!./.git/hooks/auto-commit'

echo -e "\e[32mSuccessful installation and settings alias for auto-commit.\e[0m"
echo "$TAG" > "$VERSION_FILE"

echo -e "\e[32mSuccessful installation version $TAG and settings alias for auto-commit.\e[0m"
echo ""
echo -e "\e[33mMore detailed: https://github.com/thefuture-industries/git-auto-commit\e[0m"
echo -e "\e[33mNow you can run: git auto\e[0m"
Expand Down
9 changes: 7 additions & 2 deletions scripts/install-windows-auto-commit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Set-Location $gitRoot

$HookName = "auto-commit"

$Url = "https://github.com/thefuture-industries/git-auto-commit/blob/main/bin/auto-commit?raw=true"
$versionUrl = "https://api.github.com/repos/thefuture-industries/git-auto-commit/releases/latest"
$tag = (Invoke-RestMethod -Uri $versionUrl -UseBasicParsing).tag_name
$Url = "https://github.com/thefuture-industries/git-auto-commit/releases/download/$tag/auto-commit"

if (-not (Test-Path ".git/hooks")) {
Write-Error "The current directory is not a Git repository."
Expand All @@ -39,7 +41,10 @@ try {

git config --local alias.auto '!./.git/hooks/auto-commit'

Write-Host "Successful installation and settings alias for auto-commit." -ForegroundColor Green
$versionFile = Join-Path -Path ".git/hooks" -ChildPath "auto-commit.version.txt"
Set-Content -Path $versionFile -Value $tag

Write-Host "Successful installation version $tag and settings alias for auto-commit." -ForegroundColor Green

Write-Host ""
Write-Host "More detailed: https://github.com/thefuture-industries/git-auto-commit"
Expand Down
69 changes: 69 additions & 0 deletions update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package main

import (
"fmt"
"net/http"
"os"
"path/filepath"
"strings"
)

func AutoCommitUpdate() {
root, err := GetGitRoot()
if err != nil {
ErrorLogger(err)
return
}

versionFile := filepath.Join(root, ".git", "hooks", VERSION_FILE)

version, err := os.ReadFile(versionFile)
if err != nil {
ErrorLogger(fmt.Errorf("unknown version for auto-commit, please re-install: %w", err))
return
}

resp, err := http.Get(GITHUB_REPO_URL + "/releases/latest")
if err != nil {
ErrorLogger(fmt.Errorf("could not check latest version: %w", err))
return
}
defer resp.Body.Close()

var data struct {
TagName string `json:"tag_name"`
}
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
ErrorLogger(fmt.Errorf("could not parse version info: %w", err))
return
}

if strings.TrimSpace(string(version)) == strings.TrimSpace(data.TagName) {
fmt.Printf("\033[92myou have the latest version installed %s\033[0m\n", strings.TrimSpace(data.TagName))
return
}

fmt.Printf("updating to version %s...\n", strings.TrimSpace(data.TagName))

binaryURL := GITHUB_REPO_URL + "/releases/download/" + strings.TrimSpace(data.TagName) + "/" + BINARY_AUTO_COMMIT
destPath := filepath.Join(root, ".git", "hooks", "auto-commit")

if err := DownloadBinAutoCommit(binaryURL, destPath); err != nil {
ErrorLogger(fmt.Errorf("failed to download new binary: %w", err))
return
}

err = os.Chmod(destPath, 0755)
if err != nil {
ErrorLogger(fmt.Errorf("failed to set executable permission: %w", err))
return
}

err = os.WriteFile(versionFile, []byte(strings.TrimSpace(data.TagName)), 0644)
if err != nil {
ErrorLogger(fmt.Errorf("failed to update version file: %w", err))
return
}

fmt.Println("successful upgrade to version ", strings.TrimSpace(data.TagName))
}
47 changes: 47 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"fmt"
"net/http"
"os"
"path/filepath"
"strings"
)

func GetVersion() {
root, err := GetGitRoot()
if err != nil {
ErrorLogger(fmt.Errorf("could not get git root: %w", err))
return
}

versionFile := filepath.Join(root, ".git", "hooks", VERSION_FILE)

version, err := os.ReadFile(versionFile)
if err != nil {
ErrorLogger(fmt.Errorf("unknown version for auto-commit, please re-install: %w", err))
return
}

fmt.Println("[git auto-commit] current version:", string(version))

resp, err := http.Get(GITHUB_API_REPO_URL + "/releases/latest")
if err != nil {
ErrorLogger(fmt.Errorf("could not check latest version: %w", err))
return
}
defer resp.Body.Close()

var data struct {
TagName string `json:"tag_name"`
}
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
ErrorLogger(fmt.Errorf("could not parse version info: %w", err))
return
}

if strings.TrimSpace(string(version)) != strings.TrimSpace(data.TagName) {
fmt.Printf("\033[94ma new version is available: %s\033[0m\n", strings.TrimSpace(data.TagName))
fmt.Printf("\033[92mplease update! 'git auto -u'\033[0m\n")
}
}