Change default fetch recent to include remote refs from current remote
Previously only local branches were included by default. However this way is more useful in practice; otherwise when you needed to checkout or pull new commits from the remote you were forced to fetch on demand; fetch --recent wouldn't pick them up without including the remote branches. While you *can* create / update local branches without checking out manually (e.g. git reset to manually fast-forward) to make fetch --recent then pickup the changes from local branches, it's too cumbersome. Including remote refs by default makes more sense for most people, respecting the idea that you do this as an optimistic fetch to save time at checkout/pull. However, limit the operation to the current remote only (which makes sense anyway).
This commit is contained in:
parent
fc720906b3
commit
7519896f98
@ -123,7 +123,7 @@ func fetchRecent(alreadyFetchedRefs []*git.Ref, include, exclude []string) {
|
||||
if fetchconf.FetchRecentRefsDays > 0 {
|
||||
Print("Fetching recent branches within %v days", fetchconf.FetchRecentRefsDays)
|
||||
refsSince := time.Now().AddDate(0, 0, -fetchconf.FetchRecentRefsDays)
|
||||
refs, err := git.RecentBranches(refsSince, fetchconf.FetchRecentRefsIncludeRemotes, "")
|
||||
refs, err := git.RecentBranches(refsSince, fetchconf.FetchRecentRefsIncludeRemotes, lfs.Config.CurrentRemote)
|
||||
if err != nil {
|
||||
Panic(err, "Could not scan for recent refs")
|
||||
}
|
||||
|
@ -49,9 +49,12 @@ lfs option can be scoped inside the configuration for a remote.
|
||||
|
||||
* `lfs.fetchrecentremoterefs`
|
||||
|
||||
If true, fetches remote refs as well as local refs in the recent window. This
|
||||
is useful to fetch objects for remote branches you might want to check out
|
||||
later, but means more refs are downloaded. The default is false.
|
||||
If true, fetches remote refs (for the remote you're fetching) as well as local
|
||||
refs in the recent window. This is useful to fetch objects for remote branches
|
||||
you might want to check out later. The default is true; if you set this to
|
||||
false, fetching for those branches will only occur when you either check them
|
||||
out (losing the advantage of fetch --recent), or create a tracking local
|
||||
branch separately then fetch again.
|
||||
|
||||
* `lfs.fetchrecentcommitsdays`
|
||||
|
||||
|
@ -85,9 +85,12 @@ What changes are considered 'recent' is based on a number of gitconfig options:
|
||||
The default is 7 days.
|
||||
|
||||
* `lfs.fetchrecentremoterefs`
|
||||
If true, includes remote branches as well as local refs in the recent window. This
|
||||
is useful to fetch objects for remote branches you might want to check out
|
||||
later, but means more refs are downloaded. The default is false.
|
||||
If true, fetches remote refs (for the remote you're fetching) as well as local
|
||||
refs in the recent window. This is useful to fetch objects for remote branches
|
||||
you might want to check out later. The default is true; if you set this to
|
||||
false, fetching for those branches will only occur when you either check them
|
||||
out (losing the advantage of fetch --recent), or create a tracking local
|
||||
branch separately then fetch again.
|
||||
|
||||
* `lfs.fetchrecentcommitsdays`
|
||||
In addition to fetching at branches, also fetches changes made within N
|
||||
|
@ -24,7 +24,7 @@ type FetchPruneConfig struct {
|
||||
// The number of days prior to current date for which (local) refs other than HEAD
|
||||
// will be fetched with --recent (default 7, 0 = only fetch HEAD)
|
||||
FetchRecentRefsDays int
|
||||
// Makes the FetchRecentRefsDays option apply to all remote refs as well (default false)
|
||||
// Makes the FetchRecentRefsDays option apply to remote refs from fetch source as well (default true)
|
||||
FetchRecentRefsIncludeRemotes bool
|
||||
// number of days prior to latest commit on a ref that we'll fetch previous
|
||||
// LFS changes too (default 0 = only fetch at ref)
|
||||
@ -221,7 +221,7 @@ func (c *Configuration) FetchPruneConfig() *FetchPruneConfig {
|
||||
if c.fetchPruneConfig == nil {
|
||||
c.fetchPruneConfig = &FetchPruneConfig{
|
||||
FetchRecentRefsDays: 7,
|
||||
FetchRecentRefsIncludeRemotes: false,
|
||||
FetchRecentRefsIncludeRemotes: true,
|
||||
FetchRecentCommitsDays: 0,
|
||||
PruneOffsetDays: 3,
|
||||
}
|
||||
@ -233,13 +233,13 @@ func (c *Configuration) FetchPruneConfig() *FetchPruneConfig {
|
||||
}
|
||||
if v, ok := c.GitConfig("lfs.fetchrecentremoterefs"); ok {
|
||||
|
||||
if v == "true" || v == "" {
|
||||
c.fetchPruneConfig.FetchRecentRefsIncludeRemotes = true
|
||||
if v == "false" {
|
||||
c.fetchPruneConfig.FetchRecentRefsIncludeRemotes = false
|
||||
}
|
||||
|
||||
// Any numeric value except 0 is considered true
|
||||
if n, err := strconv.Atoi(v); err == nil && n != 0 {
|
||||
c.fetchPruneConfig.FetchRecentRefsIncludeRemotes = true
|
||||
if n, err := strconv.Atoi(v); err == nil && n == 0 {
|
||||
c.fetchPruneConfig.FetchRecentRefsIncludeRemotes = false
|
||||
}
|
||||
}
|
||||
if v, ok := c.GitConfig("lfs.fetchrecentcommitsdays"); ok {
|
||||
|
@ -398,14 +398,14 @@ func TestFetchPruneConfigDefault(t *testing.T) {
|
||||
assert.Equal(t, 7, fp.FetchRecentRefsDays)
|
||||
assert.Equal(t, 0, fp.FetchRecentCommitsDays)
|
||||
assert.Equal(t, 3, fp.PruneOffsetDays)
|
||||
assert.Equal(t, false, fp.FetchRecentRefsIncludeRemotes)
|
||||
assert.Equal(t, true, fp.FetchRecentRefsIncludeRemotes)
|
||||
|
||||
}
|
||||
func TestFetchPruneConfigCustom(t *testing.T) {
|
||||
config := &Configuration{
|
||||
gitConfig: map[string]string{
|
||||
"lfs.fetchrecentrefsdays": "12",
|
||||
"lfs.fetchrecentremoterefs": "true",
|
||||
"lfs.fetchrecentremoterefs": "false",
|
||||
"lfs.fetchrecentcommitsdays": "9",
|
||||
"lfs.pruneoffsetdays": "30",
|
||||
},
|
||||
@ -415,6 +415,6 @@ func TestFetchPruneConfigCustom(t *testing.T) {
|
||||
assert.Equal(t, 12, fp.FetchRecentRefsDays)
|
||||
assert.Equal(t, 9, fp.FetchRecentCommitsDays)
|
||||
assert.Equal(t, 30, fp.PruneOffsetDays)
|
||||
assert.Equal(t, true, fp.FetchRecentRefsIncludeRemotes)
|
||||
assert.Equal(t, false, fp.FetchRecentRefsIncludeRemotes)
|
||||
|
||||
}
|
||||
|
@ -186,8 +186,8 @@ begin_test "fetch-recent"
|
||||
}
|
||||
]" | lfstest-testutils addcommits
|
||||
|
||||
git lfs push origin master
|
||||
git lfs push origin other_branch
|
||||
git push origin master
|
||||
git push origin other_branch
|
||||
assert_server_object "$reponame" "$oid0"
|
||||
assert_server_object "$reponame" "$oid1"
|
||||
assert_server_object "$reponame" "$oid2"
|
||||
|
Loading…
Reference in New Issue
Block a user