mirror of
https://github.com/yarlson/lnk.git
synced 2025-08-31 18:01:41 +02:00
feat: set 'main' as default branch instead of 'master'
This commit is contained in:
@@ -42,7 +42,7 @@ sudo mv lnk /usr/local/bin/
|
|||||||
lnk init
|
lnk init
|
||||||
```
|
```
|
||||||
|
|
||||||
This creates `$XDG_CONFIG_HOME/lnk` (or `~/.config/lnk`) and initializes a Git repository.
|
This creates `$XDG_CONFIG_HOME/lnk` (or `~/.config/lnk`) and initializes a Git repository with `main` as the default branch.
|
||||||
|
|
||||||
### Initialize with remote
|
### Initialize with remote
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ lnk init --remote https://github.com/user/dotfiles.git
|
|||||||
lnk init -r git@github.com:user/dotfiles.git
|
lnk init -r git@github.com:user/dotfiles.git
|
||||||
```
|
```
|
||||||
|
|
||||||
This initializes the repository and adds the specified URL as the `origin` remote, allowing you to sync your dotfiles with a Git hosting service.
|
This initializes the repository with `main` as the default branch and adds the specified URL as the `origin` remote, allowing you to sync your dotfiles with a Git hosting service.
|
||||||
|
|
||||||
### Add a file
|
### Add a file
|
||||||
|
|
||||||
|
@@ -22,12 +22,28 @@ func New(repoPath string) *Git {
|
|||||||
|
|
||||||
// Init initializes a new Git repository
|
// Init initializes a new Git repository
|
||||||
func (g *Git) Init() error {
|
func (g *Git) Init() error {
|
||||||
cmd := exec.Command("git", "init")
|
// Try using git init -b main first (Git 2.28+)
|
||||||
|
cmd := exec.Command("git", "init", "-b", "main")
|
||||||
cmd.Dir = g.repoPath
|
cmd.Dir = g.repoPath
|
||||||
|
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("git init failed: %w\nOutput: %s", err, string(output))
|
// Fallback to regular init + branch rename for older Git versions
|
||||||
|
cmd = exec.Command("git", "init")
|
||||||
|
cmd.Dir = g.repoPath
|
||||||
|
|
||||||
|
output, err = cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("git init failed: %w\nOutput: %s", err, string(output))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the default branch to main
|
||||||
|
cmd = exec.Command("git", "symbolic-ref", "HEAD", "refs/heads/main")
|
||||||
|
cmd.Dir = g.repoPath
|
||||||
|
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return fmt.Errorf("failed to set default branch to main: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@@ -65,6 +65,13 @@ func (suite *LnkIntegrationTestSuite) TestInit() {
|
|||||||
// Verify it's a non-bare repo
|
// Verify it's a non-bare repo
|
||||||
configPath := filepath.Join(gitDir, "config")
|
configPath := filepath.Join(gitDir, "config")
|
||||||
suite.FileExists(configPath)
|
suite.FileExists(configPath)
|
||||||
|
|
||||||
|
// Verify the default branch is set to 'main'
|
||||||
|
cmd := exec.Command("git", "symbolic-ref", "HEAD")
|
||||||
|
cmd.Dir = lnkDir
|
||||||
|
output, err := cmd.Output()
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
suite.Equal("refs/heads/main", strings.TrimSpace(string(output)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *LnkIntegrationTestSuite) TestAddFile() {
|
func (suite *LnkIntegrationTestSuite) TestAddFile() {
|
||||||
|
Reference in New Issue
Block a user