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:
Steve Streeting 2015-09-01 12:06:30 +01:00
parent fc720906b3
commit 7519896f98
6 changed files with 24 additions and 18 deletions

@ -123,7 +123,7 @@ func fetchRecent(alreadyFetchedRefs []*git.Ref, include, exclude []string) {
if fetchconf.FetchRecentRefsDays > 0 { if fetchconf.FetchRecentRefsDays > 0 {
Print("Fetching recent branches within %v days", fetchconf.FetchRecentRefsDays) Print("Fetching recent branches within %v days", fetchconf.FetchRecentRefsDays)
refsSince := time.Now().AddDate(0, 0, -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 { if err != nil {
Panic(err, "Could not scan for recent refs") 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` * `lfs.fetchrecentremoterefs`
If true, fetches remote refs as well as local refs in the recent window. This If true, fetches remote refs (for the remote you're fetching) as well as local
is useful to fetch objects for remote branches you might want to check out refs in the recent window. This is useful to fetch objects for remote branches
later, but means more refs are downloaded. The default is false. 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` * `lfs.fetchrecentcommitsdays`

@ -85,9 +85,12 @@ What changes are considered 'recent' is based on a number of gitconfig options:
The default is 7 days. The default is 7 days.
* `lfs.fetchrecentremoterefs` * `lfs.fetchrecentremoterefs`
If true, includes remote branches as well as local refs in the recent window. This If true, fetches remote refs (for the remote you're fetching) as well as local
is useful to fetch objects for remote branches you might want to check out refs in the recent window. This is useful to fetch objects for remote branches
later, but means more refs are downloaded. The default is false. 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` * `lfs.fetchrecentcommitsdays`
In addition to fetching at branches, also fetches changes made within N 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 // 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) // will be fetched with --recent (default 7, 0 = only fetch HEAD)
FetchRecentRefsDays int 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 FetchRecentRefsIncludeRemotes bool
// number of days prior to latest commit on a ref that we'll fetch previous // number of days prior to latest commit on a ref that we'll fetch previous
// LFS changes too (default 0 = only fetch at ref) // LFS changes too (default 0 = only fetch at ref)
@ -221,7 +221,7 @@ func (c *Configuration) FetchPruneConfig() *FetchPruneConfig {
if c.fetchPruneConfig == nil { if c.fetchPruneConfig == nil {
c.fetchPruneConfig = &FetchPruneConfig{ c.fetchPruneConfig = &FetchPruneConfig{
FetchRecentRefsDays: 7, FetchRecentRefsDays: 7,
FetchRecentRefsIncludeRemotes: false, FetchRecentRefsIncludeRemotes: true,
FetchRecentCommitsDays: 0, FetchRecentCommitsDays: 0,
PruneOffsetDays: 3, PruneOffsetDays: 3,
} }
@ -233,13 +233,13 @@ func (c *Configuration) FetchPruneConfig() *FetchPruneConfig {
} }
if v, ok := c.GitConfig("lfs.fetchrecentremoterefs"); ok { if v, ok := c.GitConfig("lfs.fetchrecentremoterefs"); ok {
if v == "true" || v == "" { if v == "false" {
c.fetchPruneConfig.FetchRecentRefsIncludeRemotes = true c.fetchPruneConfig.FetchRecentRefsIncludeRemotes = false
} }
// Any numeric value except 0 is considered true // Any numeric value except 0 is considered true
if n, err := strconv.Atoi(v); err == nil && n != 0 { if n, err := strconv.Atoi(v); err == nil && n == 0 {
c.fetchPruneConfig.FetchRecentRefsIncludeRemotes = true c.fetchPruneConfig.FetchRecentRefsIncludeRemotes = false
} }
} }
if v, ok := c.GitConfig("lfs.fetchrecentcommitsdays"); ok { 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, 7, fp.FetchRecentRefsDays)
assert.Equal(t, 0, fp.FetchRecentCommitsDays) assert.Equal(t, 0, fp.FetchRecentCommitsDays)
assert.Equal(t, 3, fp.PruneOffsetDays) assert.Equal(t, 3, fp.PruneOffsetDays)
assert.Equal(t, false, fp.FetchRecentRefsIncludeRemotes) assert.Equal(t, true, fp.FetchRecentRefsIncludeRemotes)
} }
func TestFetchPruneConfigCustom(t *testing.T) { func TestFetchPruneConfigCustom(t *testing.T) {
config := &Configuration{ config := &Configuration{
gitConfig: map[string]string{ gitConfig: map[string]string{
"lfs.fetchrecentrefsdays": "12", "lfs.fetchrecentrefsdays": "12",
"lfs.fetchrecentremoterefs": "true", "lfs.fetchrecentremoterefs": "false",
"lfs.fetchrecentcommitsdays": "9", "lfs.fetchrecentcommitsdays": "9",
"lfs.pruneoffsetdays": "30", "lfs.pruneoffsetdays": "30",
}, },
@ -415,6 +415,6 @@ func TestFetchPruneConfigCustom(t *testing.T) {
assert.Equal(t, 12, fp.FetchRecentRefsDays) assert.Equal(t, 12, fp.FetchRecentRefsDays)
assert.Equal(t, 9, fp.FetchRecentCommitsDays) assert.Equal(t, 9, fp.FetchRecentCommitsDays)
assert.Equal(t, 30, fp.PruneOffsetDays) 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 ]" | lfstest-testutils addcommits
git lfs push origin master git push origin master
git lfs push origin other_branch git push origin other_branch
assert_server_object "$reponame" "$oid0" assert_server_object "$reponame" "$oid0"
assert_server_object "$reponame" "$oid1" assert_server_object "$reponame" "$oid1"
assert_server_object "$reponame" "$oid2" assert_server_object "$reponame" "$oid2"