Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
fail-fast: false
matrix:
git-version:
- 2.32.0 # oldest supported version
- 2.30.0 # oldest supported version
- 2.38.2 # first version that supports the rebase.updateRefs config
- 2.44.0
- latest # We rely on github to have the latest version installed on their VMs
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func NewApp(config config.AppConfigurer, test integrationTypes.IntegrationTest,
return app, nil
}

const minGitVersionStr = "2.32.0"
const minGitVersionStr = "2.30.0"

func minGitVersionErrorMessage(tr *i18n.TranslationSet) string {
return fmt.Sprintf(tr.MinGitVersionError, minGitVersionStr)
Expand Down
16 changes: 13 additions & 3 deletions pkg/commands/git_commands/repo_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type RepoPaths struct {
isBareRepo bool
}

var gitPathFormatVersion = GitVersion{2, 31, 0, ""}

// Path to the current worktree. If we're in the main worktree, this will
// be the same as RepoPath()
func (self *RepoPaths) WorktreePath() string {
Expand Down Expand Up @@ -77,14 +79,15 @@ func GetRepoPaths(
if err != nil {
return nil, err
}
return GetRepoPathsForDir(cwd, cmd)
return GetRepoPathsForDir(cwd, cmd, version)
}

func GetRepoPathsForDir(
dir string,
cmd oscommands.ICmdObjBuilder,
version *GitVersion,
) (*RepoPaths, error) {
gitDirOutput, err := callGitRevParseWithDir(cmd, dir, "--show-toplevel", "--absolute-git-dir", "--git-common-dir", "--is-bare-repository", "--show-superproject-working-tree")
gitDirOutput, err := callGitRevParseWithDir(cmd, version, dir, "--show-toplevel", "--absolute-git-dir", "--git-common-dir", "--is-bare-repository", "--show-superproject-working-tree")
if err != nil {
return nil, err
}
Expand All @@ -93,6 +96,12 @@ func GetRepoPathsForDir(
worktreePath := gitDirResults[0]
worktreeGitDirPath := gitDirResults[1]
repoGitDirPath := gitDirResults[2]
if version.IsOlderThanVersion(&gitPathFormatVersion) {
repoGitDirPath, err = filepath.Abs(repoGitDirPath)
if err != nil {
return nil, err
}
}
isBareRepo := gitDirResults[3] == "true"

// If we're in a submodule, --show-superproject-working-tree will return
Expand Down Expand Up @@ -122,10 +131,11 @@ func GetRepoPathsForDir(

func callGitRevParseWithDir(
cmd oscommands.ICmdObjBuilder,
version *GitVersion,
dir string,
gitRevArgs ...string,
) (string, error) {
gitRevParse := NewGitCmd("rev-parse").Arg("--path-format=absolute").Arg(gitRevArgs...)
gitRevParse := NewGitCmd("rev-parse").ArgIf(version.IsAtLeastVersion(&gitPathFormatVersion), "--path-format=absolute").Arg(gitRevArgs...)
if dir != "" {
gitRevParse.Dir(dir)
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/commands/git_commands/repo_paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,22 @@ func TestGetRepoPaths(t *testing.T) {
runner := oscommands.NewFakeRunner(t)
cmd := oscommands.NewDummyCmdObjBuilder(runner)

version, err := GetGitVersion(oscommands.NewDummyOSCommand())
if err != nil {
t.Fatal(err)
}

getRevParseArgs := func() []string {
return []string{"rev-parse", "--path-format=absolute"}
args := []string{"rev-parse"}
if version.IsAtLeast(2, 31, 0) {
args = append(args, "--path-format=absolute")
}
return args
}
// prepare the filesystem for the scenario
s.BeforeFunc(runner, getRevParseArgs)

repoPaths, err := GetRepoPathsForDir("", cmd)
repoPaths, err := GetRepoPathsForDir("", cmd, version)

// check the error and the paths
if s.Err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/git_commands/worktree_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (self *WorktreeLoader) GetWorktrees() ([]*models.Worktree, error) {
if worktree.IsPathMissing {
return
}
gitDir, err := callGitRevParseWithDir(self.cmd, worktree.Path, "--absolute-git-dir")
gitDir, err := callGitRevParseWithDir(self.cmd, self.version, worktree.Path, "--absolute-git-dir")
if err != nil {
self.Log.Warnf("Could not find git dir for worktree %s: %v", worktree.Path, err)
return
Expand Down
6 changes: 5 additions & 1 deletion pkg/commands/git_commands/worktree_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ branch refs/heads/mybranch-worktree
}

getRevParseArgs := func() []string {
return []string{"rev-parse", "--path-format=absolute"}
args := []string{"rev-parse"}
if version.IsAtLeast(2, 31, 0) {
args = append(args, "--path-format=absolute")
}
return args
}

s.before(runner, fs, getRevParseArgs)
Expand Down
28 changes: 15 additions & 13 deletions pkg/integration/tests/commit/create_amend_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ var CreateAmendCommit = NewIntegrationTest(NewIntegrationTestArgs{
Contains("commit 01"),
)

t.Views().Commits().
Press(keys.Commits.SquashAboveCommits).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Apply fixup commits")).
Select(Contains("Above the selected commit")).
Confirm()
}).
Lines(
Contains("commit 03"),
Contains("commit 02 amended").IsSelected(),
Contains("commit 01"),
)
if t.Git().Version().IsAtLeast(2, 32, 0) { // Support for auto-squashing "amend!" commits was added in git 2.32.0
t.Views().Commits().
Press(keys.Commits.SquashAboveCommits).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Apply fixup commits")).
Select(Contains("Above the selected commit")).
Confirm()
}).
Lines(
Contains("commit 03"),
Contains("commit 02 amended").IsSelected(),
Contains("commit 01"),
)
}
},
})