This repository was archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 534
Submodules init and update #270
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
498dbf7
storage: git.Storer move to storage.Storer and module handling
mcuadros b3b6e51
submodule init implementation
mcuadros b18d649
plumbing/object: allow TreeIter return SubModule entries
mcuadros c551c29
submodule init implementation
mcuadros 940a16c
format/index: sort the Entries before encode
mcuadros f8b5557
config: adding Config.Core.Worktree
mcuadros 65351f8
Repository.Init now handles non-standard .git location
mcuadros 7e990a8
submodule init and update implementation
mcuadros 09110d8
config: added Config.Submodules
mcuadros d6a6dec
submodule update implementation
mcuadros ed288b3
documentation and API improvements
mcuadros 790fbda
rebase master
mcuadros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"errors" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"srcd.works/go-git.v4/config" | ||
"srcd.works/go-git.v4/internal/revision" | ||
|
@@ -57,9 +58,75 @@ func Init(s storage.Storer, worktree billy.Filesystem) (*Repository, error) { | |
|
||
if worktree == nil { | ||
r.setIsBare(true) | ||
return r, nil | ||
} | ||
|
||
return r, nil | ||
return r, setWorktreeAndStoragePaths(r, worktree) | ||
} | ||
|
||
func setWorktreeAndStoragePaths(r *Repository, worktree billy.Filesystem) error { | ||
type fsBased interface { | ||
Filesystem() billy.Filesystem | ||
} | ||
|
||
// .git file is only created if the storage is file based and the file | ||
// system is osfs.OS | ||
fs, isFSBased := r.Storer.(fsBased) | ||
if !isFSBased { | ||
return nil | ||
} | ||
|
||
_, isOS := fs.Filesystem().(*osfs.OS) | ||
if !isOS { | ||
return nil | ||
} | ||
|
||
if err := createDotGitFile(worktree, fs.Filesystem()); err != nil { | ||
return err | ||
} | ||
|
||
return setConfigWorktree(r, worktree, fs.Filesystem()) | ||
} | ||
|
||
func createDotGitFile(worktree, storage billy.Filesystem) error { | ||
path, err := filepath.Rel(worktree.Base(), storage.Base()) | ||
if err != nil { | ||
path = storage.Base() | ||
} | ||
|
||
if path == ".git" { | ||
// not needed, since the folder is the default place | ||
return nil | ||
} | ||
|
||
f, err := worktree.Create(".git") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer f.Close() | ||
_, err = fmt.Fprintf(f, "gitdir: %s\n", path) | ||
return err | ||
} | ||
|
||
func setConfigWorktree(r *Repository, worktree, storage billy.Filesystem) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capitalize |
||
path, err := filepath.Rel(storage.Base(), worktree.Base()) | ||
if err != nil { | ||
path = worktree.Base() | ||
} | ||
|
||
if path == ".." { | ||
// not needed, since the folder is the default place | ||
return nil | ||
} | ||
|
||
cfg, err := r.Storer.Config() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cfg.Core.Worktree = path | ||
return r.Storer.SetConfig(cfg) | ||
} | ||
|
||
// Open opens a git repository using the given Storer and worktree filesystem, | ||
|
@@ -280,7 +347,6 @@ func (r *Repository) clone(o *CloneOptions) error { | |
} | ||
|
||
if err := r.updateWorktree(); err != nil { | ||
fmt.Println("q", err) | ||
return err | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize
tree
in the function name.