Skip to content

Commit c739357

Browse files
committed
Remove git version specific code for versions we no longer support
1 parent 93c5849 commit c739357

File tree

9 files changed

+27
-53
lines changed

9 files changed

+27
-53
lines changed

pkg/commands/git_commands/commit_loader.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ func (self *CommitLoader) extractCommitFromLine(hashPool *utils.StringPool, line
249249
}
250250

251251
func (self *CommitLoader) getHydratedRebasingCommits(hashPool *utils.StringPool, addConflictingCommit bool) ([]*models.Commit, error) {
252-
todoFileHasShortHashes := self.version.IsOlderThan(2, 25, 2)
253-
return self.getHydratedTodoCommits(hashPool, self.getRebasingCommits(hashPool, addConflictingCommit), todoFileHasShortHashes)
252+
return self.getHydratedTodoCommits(hashPool, self.getRebasingCommits(hashPool, addConflictingCommit), false)
254253
}
255254

256255
func (self *CommitLoader) getHydratedSequencerCommits(hashPool *utils.StringPool, workingTreeState models.WorkingTreeState) ([]*models.Commit, error) {

pkg/commands/git_commands/rebase.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (self *RebaseCommands) PrepareInteractiveRebaseCommand(opts PrepareInteract
218218
Arg("--interactive").
219219
Arg("--autostash").
220220
Arg("--keep-empty").
221-
ArgIf(opts.keepCommitsThatBecomeEmpty && self.version.IsAtLeast(2, 26, 0), "--empty=keep").
221+
ArgIf(opts.keepCommitsThatBecomeEmpty, "--empty=keep").
222222
Arg("--no-autosquash").
223223
Arg("--rebase-merges").
224224
ArgIf(opts.onto != "", "--onto", opts.onto).

pkg/commands/git_commands/repo_paths.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ type RepoPaths struct {
2121
isBareRepo bool
2222
}
2323

24-
var gitPathFormatVersion = GitVersion{2, 31, 0, ""}
25-
2624
// Path to the current worktree. If we're in the main worktree, this will
2725
// be the same as RepoPath()
2826
func (self *RepoPaths) WorktreePath() string {
@@ -79,15 +77,14 @@ func GetRepoPaths(
7977
if err != nil {
8078
return nil, err
8179
}
82-
return GetRepoPathsForDir(cwd, cmd, version)
80+
return GetRepoPathsForDir(cwd, cmd)
8381
}
8482

8583
func GetRepoPathsForDir(
8684
dir string,
8785
cmd oscommands.ICmdObjBuilder,
88-
version *GitVersion,
8986
) (*RepoPaths, error) {
90-
gitDirOutput, err := callGitRevParseWithDir(cmd, version, dir, "--show-toplevel", "--absolute-git-dir", "--git-common-dir", "--is-bare-repository", "--show-superproject-working-tree")
87+
gitDirOutput, err := callGitRevParseWithDir(cmd, dir, "--show-toplevel", "--absolute-git-dir", "--git-common-dir", "--is-bare-repository", "--show-superproject-working-tree")
9188
if err != nil {
9289
return nil, err
9390
}
@@ -96,12 +93,6 @@ func GetRepoPathsForDir(
9693
worktreePath := gitDirResults[0]
9794
worktreeGitDirPath := gitDirResults[1]
9895
repoGitDirPath := gitDirResults[2]
99-
if version.IsOlderThanVersion(&gitPathFormatVersion) {
100-
repoGitDirPath, err = filepath.Abs(repoGitDirPath)
101-
if err != nil {
102-
return nil, err
103-
}
104-
}
10596
isBareRepo := gitDirResults[3] == "true"
10697

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

132123
func callGitRevParseWithDir(
133124
cmd oscommands.ICmdObjBuilder,
134-
version *GitVersion,
135125
dir string,
136126
gitRevArgs ...string,
137127
) (string, error) {
138-
gitRevParse := NewGitCmd("rev-parse").ArgIf(version.IsAtLeastVersion(&gitPathFormatVersion), "--path-format=absolute").Arg(gitRevArgs...)
128+
gitRevParse := NewGitCmd("rev-parse").Arg("--path-format=absolute").Arg(gitRevArgs...)
139129
if dir != "" {
140130
gitRevParse.Dir(dir)
141131
}

pkg/commands/git_commands/repo_paths_test.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,13 @@ func TestGetRepoPaths(t *testing.T) {
194194
runner := oscommands.NewFakeRunner(t)
195195
cmd := oscommands.NewDummyCmdObjBuilder(runner)
196196

197-
version, err := GetGitVersion(oscommands.NewDummyOSCommand())
198-
if err != nil {
199-
t.Fatal(err)
200-
}
201-
202197
getRevParseArgs := func() []string {
203-
args := []string{"rev-parse"}
204-
if version.IsAtLeast(2, 31, 0) {
205-
args = append(args, "--path-format=absolute")
206-
}
207-
return args
198+
return []string{"rev-parse", "--path-format=absolute"}
208199
}
209200
// prepare the filesystem for the scenario
210201
s.BeforeFunc(runner, getRevParseArgs)
211202

212-
repoPaths, err := GetRepoPathsForDir("", cmd, version)
203+
repoPaths, err := GetRepoPathsForDir("", cmd)
213204

214205
// check the error and the paths
215206
if s.Err != nil {

pkg/commands/git_commands/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (self *SyncCommands) fetchCommandBuilder(fetchAll bool) *GitCommandBuilder
5959
ArgIf(fetchAll, "--all").
6060
// avoid writing to .git/FETCH_HEAD; this allows running a pull
6161
// concurrently without getting errors
62-
ArgIf(self.version.IsAtLeast(2, 29, 0), "--no-write-fetch-head")
62+
Arg("--no-write-fetch-head")
6363
}
6464

6565
func (self *SyncCommands) FetchCmdObj(task gocui.Task) *oscommands.CmdObj {

pkg/commands/git_commands/sync_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func TestSyncFetch(t *testing.T) {
119119
test: func(cmdObj *oscommands.CmdObj) {
120120
assert.True(t, cmdObj.ShouldLog())
121121
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.PROMPT)
122-
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch"})
122+
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--no-write-fetch-head"})
123123
},
124124
},
125125
{
@@ -128,7 +128,7 @@ func TestSyncFetch(t *testing.T) {
128128
test: func(cmdObj *oscommands.CmdObj) {
129129
assert.True(t, cmdObj.ShouldLog())
130130
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.PROMPT)
131-
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--all"})
131+
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--all", "--no-write-fetch-head"})
132132
},
133133
},
134134
}
@@ -157,7 +157,7 @@ func TestSyncFetchBackground(t *testing.T) {
157157
test: func(cmdObj *oscommands.CmdObj) {
158158
assert.False(t, cmdObj.ShouldLog())
159159
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.FAIL)
160-
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch"})
160+
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--no-write-fetch-head"})
161161
},
162162
},
163163
{
@@ -166,7 +166,7 @@ func TestSyncFetchBackground(t *testing.T) {
166166
test: func(cmdObj *oscommands.CmdObj) {
167167
assert.False(t, cmdObj.ShouldLog())
168168
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.FAIL)
169-
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--all"})
169+
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--all", "--no-write-fetch-head"})
170170
},
171171
},
172172
}

pkg/commands/git_commands/worktree_loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (self *WorktreeLoader) GetWorktrees() ([]*models.Worktree, error) {
8282
if worktree.IsPathMissing {
8383
return
8484
}
85-
gitDir, err := callGitRevParseWithDir(self.cmd, self.version, worktree.Path, "--absolute-git-dir")
85+
gitDir, err := callGitRevParseWithDir(self.cmd, worktree.Path, "--absolute-git-dir")
8686
if err != nil {
8787
self.Log.Warnf("Could not find git dir for worktree %s: %v", worktree.Path, err)
8888
return

pkg/commands/git_commands/worktree_loader_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@ branch refs/heads/mybranch-worktree
190190
}
191191

192192
getRevParseArgs := func() []string {
193-
args := []string{"rev-parse"}
194-
if version.IsAtLeast(2, 31, 0) {
195-
args = append(args, "--path-format=absolute")
196-
}
197-
return args
193+
return []string{"rev-parse", "--path-format=absolute"}
198194
}
199195

200196
s.before(runner, fs, getRevParseArgs)

pkg/integration/tests/commit/create_amend_commit.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,18 @@ var CreateAmendCommit = NewIntegrationTest(NewIntegrationTestArgs{
4141
Contains("commit 01"),
4242
)
4343

44-
if t.Git().Version().IsAtLeast(2, 32, 0) { // Support for auto-squashing "amend!" commits was added in git 2.32.0
45-
t.Views().Commits().
46-
Press(keys.Commits.SquashAboveCommits).
47-
Tap(func() {
48-
t.ExpectPopup().Menu().
49-
Title(Equals("Apply fixup commits")).
50-
Select(Contains("Above the selected commit")).
51-
Confirm()
52-
}).
53-
Lines(
54-
Contains("commit 03"),
55-
Contains("commit 02 amended").IsSelected(),
56-
Contains("commit 01"),
57-
)
58-
}
44+
t.Views().Commits().
45+
Press(keys.Commits.SquashAboveCommits).
46+
Tap(func() {
47+
t.ExpectPopup().Menu().
48+
Title(Equals("Apply fixup commits")).
49+
Select(Contains("Above the selected commit")).
50+
Confirm()
51+
}).
52+
Lines(
53+
Contains("commit 03"),
54+
Contains("commit 02 amended").IsSelected(),
55+
Contains("commit 01"),
56+
)
5957
},
6058
})

0 commit comments

Comments
 (0)