Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git update-index --index-info missing 1 variant #43

Closed
driusan opened this issue Jul 15, 2018 · 5 comments
Closed

git update-index --index-info missing 1 variant #43

driusan opened this issue Jul 15, 2018 · 5 comments
Labels
beginner friendly bug hacktoberfest a beginner friendly issue for anyone trying to get a free t-shirt

Comments

@driusan
Copy link
Owner

driusan commented Jul 15, 2018

Of the 3 variants of --index-info listed in git-update-index(1) only the one used by the t0000-basic.sh test suite is implemented.

It should be fairly to add support for the other two variants by basing them on the one which is implemented in UpdateIndexFromReader and adding new test cases.

@driusan
Copy link
Owner Author

driusan commented Jul 22, 2018

One variant had to be added in #68

@driusan driusan changed the title git update-index --index-info missing 2 variants git update-index --index-info missing 1 variants Jul 22, 2018
@driusan driusan changed the title git update-index --index-info missing 1 variants git update-index --index-info missing 1 variant Jul 22, 2018
@driusan driusan added the hacktoberfest a beginner friendly issue for anyone trying to get a free t-shirt label Oct 13, 2018
@guidopola
Copy link
Contributor

I'm trying to implement this, is there a way to test the git command?

This is the code i have so far.

func UpdateIndexFromReader(c *Client, opts UpdateIndexOptions, r io.Reader) (*Index, error) {
	idx := NewIndex()
	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		line := strings.TrimSpace(scanner.Text())
		if line == "" {
			continue
		}
		tab := strings.Split(line, "\t")
		if len(tab) != 2 {
			return nil, fmt.Errorf("Invalid line in index-info: %v", line)
		}
		path := tab[1]
		spaces := strings.Split(tab[0], " ")
		switch len(spaces) {
		case 2:
			// mode SP sha1 TAB path
			mode, err := ModeFromString(spaces[0])
			if err != nil {
				return nil, err
			}
			sha1, err := Sha1FromString(spaces[1])
			if err != nil {
				return nil, err
			}
			if err := idx.AddStage(c, IndexPath(path), mode, sha1, Stage0, 0, 0, UpdateIndexOptions{Add: true}); err != nil {
				return nil, err
			}
		case 3:
.....

@driusan
Copy link
Owner Author

driusan commented Oct 23, 2018

I'm not sure what you mean by "test". Do you want to write an automated test that runs with go test or do you just want to see if your output is right after running the command in any given git repo?

To see the status of the index in the current git dirgit ls-files --stage should be sufficient to show the details that are managed by git update-index --index-info.. it prints "mode sha1 stage\tpath" for each file in the index. To do automated testing, idx.Objects is a slice of git.IndexEntry pointers which get serialized to the index when dgit does something that requires saving the index.

@guidopola
Copy link
Contributor

Sorry if i didn't explain me very well. My english is very bad.
What i meant was to check the output after running the command because i found the official-git/run-tests.sh script but i have no idea how to use it.
(It would be nice to have a small guide in the readme file on how to use it)

@driusan
Copy link
Owner Author

driusan commented Oct 24, 2018

There's the wiki page that @sirnewton01 wrote at https://github.com/driusan/dgit/wiki/Verify-dgit-using-official-git-tests, but the easiest way to check that there's no regressions is to send a PR. All the known passing tests are run by Travis automatically and a green checkmark means they passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner friendly bug hacktoberfest a beginner friendly issue for anyone trying to get a free t-shirt
Projects
None yet
Development

No branches or pull requests

2 participants