Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

add support for .git as file, fixes #348 #363

Merged
merged 1 commit into from
Apr 27, 2017
Merged

add support for .git as file, fixes #348 #363

merged 1 commit into from
Apr 27, 2017

Conversation

smola
Copy link
Collaborator

@smola smola commented Apr 26, 2017

No description provided.

@smola
Copy link
Collaborator Author

smola commented Apr 26, 2017

Given current billy assumptions, this only supports relative paths in the .git file. Are absolute paths actually used in practice? Can we add an error when the path is not relative? Otherwise, we probably need significative changes.

@codecov
Copy link

codecov bot commented Apr 26, 2017

Codecov Report

Merging #363 into master will decrease coverage by 0.65%.
The diff coverage is 68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #363      +/-   ##
==========================================
- Coverage   77.28%   76.62%   -0.66%     
==========================================
  Files         122      122              
  Lines        8518     8483      -35     
==========================================
- Hits         6583     6500      -83     
- Misses       1198     1267      +69     
+ Partials      737      716      -21
Impacted Files Coverage Δ
repository.go 71.93% <68%> (-0.34%) ⬇️
plumbing/transport/ssh/common.go 0% <0%> (-56.15%) ⬇️
plumbing/transport/ssh/auth_method.go 33.33% <0%> (-24.77%) ⬇️
worktree_status.go 66.66% <0%> (-0.94%) ⬇️
worktree_linux.go 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64cd72d...4060f60. Read the comment docs.

repository.go Outdated
if !os.IsNotExist(err) {
return nil, err
}

dot = fs
} else {
wt = fs
dot = fs.Dir(".git")
if fi.IsDir() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a very nested logic, consider move this to a function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

repository.go Outdated
return nil, err
}

fmt.Println("BASE", dot.Base())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

repository.go Outdated
@@ -196,15 +199,25 @@ func PlainOpen(path string) (*Repository, error) {
var wt, dot billy.Filesystem

fs := osfs.New(path)
if _, err := fs.Stat(".git"); err != nil {
fi, err := fs.Stat(".git")
if err != nil {
Copy link
Contributor

@alcortesm alcortesm Apr 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logic here is correct, but we can improve its readability by hiding the low-level details: add a switch with few functions, like isWorkingDirectory, isSubModule, isBare... that reveal our intentions to the reader, hiding the details, that are sometimes unkown to the reader and much more difficult to get right.

This will also fix @mcuadros comment as a bonus.

This will also reveal pretty simply what is supported and what is not, from the very beginning, instead of trying to go over the inverted logic checks and details.

I would also move all this logic to a new function that gets a path and returns the filesystem of the git repository it is referencing, whether it is a submodule, a bare or a working directory, something like resolveRepoPath.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separating it into such functions would require doing redundant stats operations, or passing quite different arguments to each function. Could you review the new version and check if it's more readable now?

@alcortesm
Copy link
Contributor

Are absolute paths actually used in practice? Can we add an error when the path is not relative?

The git submodule add command allows absolute paths, but the documentation does not mention if absolute paths are allowed in the .git file.

To learn if absolute paths are common I propose to run a query in our database over all our cloned repos.

@smola smola changed the title [WIP] add support for .git as file, fixes #348 add support for .git as file, fixes #348 Apr 27, 2017
@smola
Copy link
Collaborator Author

smola commented Apr 27, 2017

@alcortesm Finally, it does support both absolute and relative paths, I did not realized that we're not working with arbitrary billy filesystems here, only OS.

@mcuadros mcuadros merged commit bc6b1c4 into src-d:master Apr 27, 2017
@smola smola deleted the dotgit-file branch May 10, 2018 16:07
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants