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

Add sideband support for push #573

Merged
merged 1 commit into from
Sep 1, 2017
Merged

Conversation

orirawlings
Copy link
Contributor

Fixes #528

An example of using the code to push to a local repository that always fails in a pre-receive hook (but pre-receive hook outputs some ascii art first):

$ go run main.go . local +refs/tags/initial-not-annotated:refs/heads/pushed
                                                                                 
                                                                                 
NNNNNNNN        NNNNNNNN                                                         
N:::::::N       N::::::N                                                         
N::::::::N      N::::::N                                                         
N:::::::::N     N::::::N                                                         
N::::::::::N    N::::::N   ooooooooooo   ppppp   ppppppppp       eeeeeeeeeeee    
N:::::::::::N   N::::::N oo:::::::::::oo p::::ppp:::::::::p    ee::::::::::::ee  
N:::::::N::::N  N::::::No:::::::::::::::op:::::::::::::::::p  e::::::eeeee:::::ee
N::::::N N::::N N::::::No:::::ooooo:::::opp::::::ppppp::::::pe::::::e     e:::::e
N::::::N  N::::N:::::::No::::o     o::::o p:::::p     p:::::pe:::::::eeeee::::::e
N::::::N   N:::::::::::No::::o     o::::o p:::::p     p:::::pe:::::::::::::::::e 
N::::::N    N::::::::::No::::o     o::::o p:::::p     p:::::pe::::::eeeeeeeeeee  
N::::::N     N:::::::::No::::o     o::::o p:::::p    p::::::pe:::::::e           
N::::::N      N::::::::No:::::ooooo:::::o p:::::ppppp:::::::pe::::::::e          
N::::::N       N:::::::No:::::::::::::::o p::::::::::::::::p  e::::::::eeeeeeee  
N::::::N        N::::::N oo:::::::::::oo  p::::::::::::::pp    ee:::::::::::::e  
NNNNNNNN         NNNNNNN   ooooooooooo    p::::::pppppppp        eeeeeeeeeeeeee  
                                          p:::::p                                
                                          p:::::p                                
                                         p:::::::p                               
                                         p:::::::p                               
                                         p:::::::p                               
                                         ppppppppp                               
                                                                                 
error: command error on refs/heads/pushed: pre-receive hook declined
exit status 1

Here is another example that prints the sideband data sent by github when trying to force push to a protected branch:

$ go run main.go . github +refs/tags/initial-not-annotated:refs/heads/pushed
error: GH006: Protected branch update failed for refs/heads/pushed.
error: Cannot force-push to a protected branch
error: command error on refs/heads/pushed: protected branch hook declined
exit status 1

The main.go program I used for these examples can be found below:

package main

import (
	"os"

	"gopkg.in/src-d/go-git.v4"
	. "gopkg.in/src-d/go-git.v4/_examples"
	"gopkg.in/src-d/go-git.v4/config"
)

// Example of a push with non-default options and progress reporting
func main() {
	CheckArgs("<repository-path>", "<remote>", "<refspec> [<refspec> ...]")
	path := os.Args[1]
	remote := os.Args[2]

	var refSpecs []config.RefSpec
	for _, s := range os.Args[3:] {
		refSpecs = append(refSpecs, config.RefSpec(s))
	}

	r, err := git.PlainOpen(path)
	CheckIfError(err)

	err = r.Push(&git.PushOptions{
		RemoteName: remote,
		RefSpecs:   refSpecs,
		Progress:   os.Stdout,
	})
	CheckIfError(err)
}

@codecov
Copy link

codecov bot commented Sep 1, 2017

Codecov Report

Merging #573 into master will decrease coverage by 0.64%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #573      +/-   ##
==========================================
- Coverage   78.01%   77.36%   -0.65%     
==========================================
  Files         129      129              
  Lines        9855     9874      +19     
==========================================
- Hits         7688     7639      -49     
- Misses       1328     1405      +77     
+ Partials      839      830       -9
Impacted Files Coverage Δ
plumbing/protocol/packp/updreq.go 80% <ø> (ø) ⬆️
options.go 84.48% <ø> (ø) ⬆️
plumbing/transport/http/receive_pack.go 70% <12.5%> (-10.96%) ⬇️
remote.go 74.25% <84.61%> (+0.21%) ⬆️
plumbing/transport/ssh/common.go 20.54% <0%> (-45.21%) ⬇️
plumbing/transport/ssh/auth_method.go 31.57% <0%> (-22.81%) ⬇️

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 3ca3702...76efca1. Read the comment docs.

@mcuadros
Copy link
Contributor

mcuadros commented Sep 1, 2017

Great! Can you cover it with some test? I know it hard but will be very nice.

@orirawlings orirawlings force-pushed the pushSideband branch 2 times, most recently from 7777d5a to ec03793 Compare September 1, 2017 14:16
@orirawlings
Copy link
Contributor Author

@mcuadros I've gone ahead and added a test. It relies on some platform specific pre-receive hooks (unlike git-upload-pack, git-receive-pack doesn't send sideband data by default).

@mcuadros mcuadros merged commit c20028f into src-d:master Sep 1, 2017
@orirawlings orirawlings deleted the pushSideband branch September 1, 2017 22:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants