-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from danny-molnar/dm-feat-core-logic
Feat: Implement core logic
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ | |
|
||
# Go workspace file | ||
go.work | ||
|
||
# Executable files | ||
gitorchk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/danny-molnar/gitorchk | ||
|
||
go 1.22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
// Verify Git repository | ||
if _, err := exec.Command("git", "rev-parse").Output(); err != nil { | ||
fmt.Println("Error: Not inside a Git repository.") | ||
return | ||
} | ||
|
||
// Fetch latest remote information | ||
fmt.Println("Fetching latest information from remote...") | ||
if _, err := exec.Command("git", "fetch").Output(); err != nil { | ||
fmt.Println("Error: Unable to fetch latest information from remote.") | ||
return | ||
} | ||
|
||
// Determine branch status | ||
output, err := exec.Command("git", "rev-list", "--left-right", "--count", "main...origin/main").Output() | ||
if err != nil { | ||
fmt.Println("Error: Unable to determine branch status.") | ||
return | ||
} | ||
|
||
// Parse output | ||
counts := strings.Fields(string(output)) | ||
if len(counts) != 2 { | ||
fmt.Println("Error: Unable to process comparison results.") | ||
} | ||
|
||
// Prompt for action | ||
if counts[1] != "0" { | ||
fmt.Printf("Your local 'main' branch iis behind by %s commits.\n", counts[1]) | ||
fmt.Println("Consider rebasig your work with the latest 'main' branch using 'git rebase' or merging updates using 'git merge'.") | ||
} else { | ||
fmt.Println("Your local 'main' branch is up-to-date with 'origin/main'.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"os/exec" | ||
"testing" | ||
) | ||
|
||
func CheckIfGitRepo() (bool, error) { | ||
cmd := exec.Command("git", "rev-parse", "--is-inside-work-tree") | ||
err := cmd.Run() | ||
if err != nil { | ||
return false, err | ||
} | ||
return true, nil | ||
} | ||
|
||
func TestCheckIfGitRepo(t *testing.T) { | ||
_, err := CheckIfGitRepo() | ||
if err != nil { | ||
t.Errorf("Error: %v", err) | ||
} | ||
} |