diff --git a/main.go b/main.go deleted file mode 100644 index 6e18f8c..0000000 --- a/main.go +++ /dev/null @@ -1,122 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "github.com/gustofarbi/lite/splitter" - "os" - "strings" - "time" -) - -var ( - version = "dev" -) - -type prefixesFlag []*splitter.Prefix - -func (p *prefixesFlag) String() string { - return fmt.Sprint(*p) -} - -func (p *prefixesFlag) Set(value string) error { - parts := strings.Split(value, ":") - from := parts[0] - to := "" - if len(parts) > 1 { - to = parts[1] - } - - // value must be unique - for _, prefix := range []*splitter.Prefix(*p) { - // FIXME: to should be normalized (xxx vs xxx/ for instance) - if prefix.To == to { - return fmt.Errorf("Cannot have two prefix splits under the same directory: %s -> %s vs %s -> %s", prefix.From, prefix.To, from, to) - } - } - - *p = append(*p, &splitter.Prefix{From: from, To: to}) - return nil -} - -var prefixes prefixesFlag -var origin, target, commit, path, gitVersion string -var scratch, debug, quiet, legacy, progress, v bool - -func init() { - flag.Var(&prefixes, "prefix", "The directory(ies) to split") - flag.StringVar(&origin, "origin", "HEAD", "The branch to split (optional, defaults to the current one)") - flag.StringVar(&target, "target", "", "The branch to create when split is finished (optional)") - flag.StringVar(&commit, "commit", "", "The commit at which to start the split (optional)") - flag.StringVar(&path, "path", ".", "The repository path (optional, current directory by default)") - flag.BoolVar(&scratch, "scratch", false, "Flush the cache (optional)") - flag.BoolVar(&debug, "debug", false, "Enable the debug mode (optional)") - flag.BoolVar(&quiet, "quiet", false, "[DEPRECATED] Suppress the output (optional)") - flag.BoolVar(&legacy, "legacy", false, "[DEPRECATED] Enable the legacy mode for projects migrating from an old version of git subtree split (optional)") - flag.StringVar(&gitVersion, "git", "latest", "Simulate a given version of Git (optional)") - flag.BoolVar(&progress, "progress", false, "Show progress bar (optional, cannot be enabled when debug is enabled)") - flag.BoolVar(&v, "version", false, "Show version") -} - -func main() { - flag.Parse() - - if v { - fmt.Fprintf(os.Stderr, "splitsh-lite version %s\n", version) - os.Exit(0) - } - - if len(prefixes) == 0 { - fmt.Fprintln(os.Stderr, "You must provide the directory to split via the --prefix flag") - os.Exit(1) - } - - if legacy { - fmt.Fprintln(os.Stderr, `The --legacy option is deprecated (use --git="<1.8.2" instead)`) - gitVersion = "<1.8.2" - } - - if quiet { - fmt.Fprintln(os.Stderr, `The --quiet option is deprecated (append 2>/dev/null to the command instead)`) - } - - config := &splitter.Config{ - Path: path, - Origin: origin, - Prefixes: []*splitter.Prefix(prefixes), - Target: target, - Commit: commit, - Debug: debug && !quiet, - Scratch: scratch, - GitVersion: gitVersion, - } - - result := &splitter.Result{} - - var ticker *time.Ticker - if progress && !debug && !quiet { - ticker = time.NewTicker(time.Millisecond * 50) - go func() { - for range ticker.C { - fmt.Fprintf(os.Stderr, "%d commits created, %d commits traversed\r", result.Created(), result.Traversed()) - } - }() - } - - if err := splitter.Split(config, result); err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - - if ticker != nil { - ticker.Stop() - } - - if !quiet { - fmt.Fprintf(os.Stderr, "%d commits created, %d commits traversed, in %s\n", result.Created(), result.Traversed(), result.Duration(time.Millisecond)) - } - - if result.Head() != nil { - fmt.Println(result.Head().String()) - } -} diff --git a/run-tests.sh b/run-tests.sh deleted file mode 100755 index a6bed2d..0000000 --- a/run-tests.sh +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/bash - -set -e -set -f - -if [ ! -d splitter-lite-tests ]; then - mkdir splitter-lite-tests -fi -cd splitter-lite-tests - -rm -rf simple -mkdir simple -cd simple -git init > /dev/null - -export GIT_AUTHOR_NAME="Sammy Cobol" -export GIT_AUTHOR_EMAIL="" -export GIT_AUTHOR_DATE="Sat, 24 Nov 1973 19:01:02 +0200" -export GIT_COMMITTER_NAME="Fred Foobar" -export GIT_COMMITTER_EMAIL="" -export GIT_COMMITTER_DATE="Sat, 24 Nov 1973 19:11:22 +0200" -echo "a" > a -git add a -git commit -m"added a" > /dev/null - -export GIT_AUTHOR_NAME="Fred Foobar" -export GIT_AUTHOR_EMAIL="" -export GIT_AUTHOR_DATE="Sat, 24 Nov 1973 20:01:02 +0200" -export GIT_COMMITTER_NAME="Sammy Cobol" -export GIT_COMMITTER_EMAIL="" -export GIT_COMMITTER_DATE="Sat, 24 Nov 1973 20:11:22 +0200" -mkdir b/ -echo "b" > b/b -git add b -git commit -m"added b" > /dev/null - -export GIT_AUTHOR_NAME="Fred Foobar" -export GIT_AUTHOR_EMAIL="" -export GIT_AUTHOR_DATE="Sat, 24 Nov 1973 21:01:02 +0200" -export GIT_COMMITTER_NAME="Sammy Cobol" -export GIT_COMMITTER_EMAIL="" -export GIT_COMMITTER_DATE="Sat, 24 Nov 1973 21:11:22 +0200" -echo "aa" > a -git add a -git commit -m"updated a" > /dev/null - -export GIT_AUTHOR_NAME="Fred Foobar" -export GIT_AUTHOR_EMAIL="" -export GIT_AUTHOR_DATE="Sat, 24 Nov 1973 22:01:02 +0200" -export GIT_COMMITTER_NAME="Sammy Cobol" -export GIT_COMMITTER_EMAIL="" -export GIT_COMMITTER_DATE="Sat, 24 Nov 1973 22:11:22 +0200" -git rm a > /dev/null -git commit -m"updated a" > /dev/null - -export GIT_AUTHOR_NAME="Fred Foobar" -export GIT_AUTHOR_EMAIL="" -export GIT_AUTHOR_DATE="Sat, 24 Nov 1973 23:01:02 +0200" -export GIT_COMMITTER_NAME="Sammy Cobol" -export GIT_COMMITTER_EMAIL="" -export GIT_COMMITTER_DATE="Sat, 24 Nov 1973 23:11:22 +0200" -echo "bb" > b/b -git add b/ -git commit -m"updated b" > /dev/null - -go build -o $(pwd)/../split $(pwd)/../../main.go - -GIT_SUBTREE_SPLIT_SHA1=`git subtree split --prefix=b/ -q` -GIT_SPLITSH_SHA1=`../split --prefix=b/` - -if [ "$GIT_SUBTREE_SPLIT_SHA1" == "$GIT_SUBTREE_SPLIT_SHA1" ]; then - echo "OK ($GIT_SUBTREE_SPLIT_SHA1 == $GIT_SUBTREE_SPLIT_SHA1)" -else - echo "OK ($GIT_SUBTREE_SPLIT_SHA1 != $GIT_SUBTREE_SPLIT_SHA1)" - exit 1 -fi - -GIT_SUBTREE_SPLIT_SHA1=`git subtree split --prefix=b/ -q bff8cdfaaf78a8842b8d9241ccfd8fb6e026f508` -GIT_SPLITSH_SHA1=`../split --prefix=b/ --commit=bff8cdfaaf78a8842b8d9241ccfd8fb6e026f508` - -if [ "$GIT_SUBTREE_SPLIT_SHA1" == "$GIT_SUBTREE_SPLIT_SHA1" ]; then - echo "OK ($GIT_SUBTREE_SPLIT_SHA1 == $GIT_SUBTREE_SPLIT_SHA1)" -else - echo "OK ($GIT_SUBTREE_SPLIT_SHA1 != $GIT_SUBTREE_SPLIT_SHA1)" - exit 1 -fi - -cd ../ - - -rm -rf merge -mkdir -p merge/src -cd merge -git init > /dev/null - -export GIT_AUTHOR_NAME="Sammy Cobol" -export GIT_AUTHOR_EMAIL="" -export GIT_AUTHOR_DATE="Sat, 24 Nov 1973 19:01:01 +0200" -export GIT_COMMITTER_NAME="Fred Foobar" -export GIT_COMMITTER_EMAIL="" -export GIT_COMMITTER_DATE="Sat, 24 Nov 1973 19:01:01 +0200" -echo -e "a\n\nb\n\nc\n\n" > src/foo -git add src/foo -git commit -m"init" > /dev/null - -git checkout -b branch1 2> /dev/null -export GIT_AUTHOR_DATE="Sat, 24 Nov 1973 19:02:02 +0200" -export GIT_COMMITTER_DATE="Sat, 24 Nov 1973 19:02:02 +0200" -echo -e "a\n\nb\nchange 2\nc\n\n" > src/foo -git commit -a -m"change 2" > /dev/null - -export GIT_AUTHOR_DATE="Sat, 24 Nov 1973 19:02:02 +0200" -export GIT_COMMITTER_DATE="Sat, 24 Nov 1973 19:02:02 +0200" -echo -e "a\n\nb\nchange 2\nc\nchange 3\n" > src/foo -git commit -a -m"change 3" > /dev/null - -git checkout master 2> /dev/null -export GIT_AUTHOR_DATE="Sat, 24 Nov 1973 19:02:02 +0200" -export GIT_COMMITTER_DATE="Sat, 24 Nov 1973 19:02:02 +0200" -echo -e "a\nchange 1\nb\n\nc\n\n" > src/foo -git commit -a -m"change 1" > /dev/null - -git checkout -b branch2 2> /dev/null -export GIT_AUTHOR_DATE="Sat, 24 Nov 1973 19:02:02 +0200" -export GIT_COMMITTER_DATE="Sat, 24 Nov 1973 19:02:02 +0200" -echo -e "a\n\nb\nchange 2\nc\n\n" > src/foo -git commit -a -m"change 2" > /dev/null - -git checkout master 2> /dev/null -git checkout -b branch3 2> /dev/null -git merge branch1 --no-edit > /dev/null -git merge branch2 --no-edit -s ours > /dev/null - -GIT_SUBTREE_SPLIT_SHA1_2="a2c4245703f8dac149ab666242a12e1d4b2510d9" -GIT_SUBTREE_SPLIT_SHA1_3="ba0dab2c4e99d68d11088f2c556af92851e93b14" -GIT_SPLITSH_SHA1_2=`../split --git="<2.8.0" --prefix=src/ --quiet` -GIT_SPLITSH_SHA1_3=`../split --prefix=src/ --quiet` - -if [ "$GIT_SUBTREE_SPLIT_SHA1_2" == "$GIT_SUBTREE_SPLIT_SHA1_2" ]; then - echo "OK ($GIT_SUBTREE_SPLIT_SHA1_2 == $GIT_SUBTREE_SPLIT_SHA1_2)" -else - echo "OK ($GIT_SUBTREE_SPLIT_SHA1_2 != $GIT_SUBTREE_SPLIT_SHA1_2)" - exit 1 -fi - -if [ "$GIT_SUBTREE_SPLIT_SHA1_3" == "$GIT_SUBTREE_SPLIT_SHA1_3" ]; then - echo "OK ($GIT_SUBTREE_SPLIT_SHA1_3 == $GIT_SUBTREE_SPLIT_SHA1_3)" -else - echo "OK ($GIT_SUBTREE_SPLIT_SHA1_3 != $GIT_SUBTREE_SPLIT_SHA1_3)" - exit 1 -fi - -cd ../ - -# run on some Open-Source repositories -if [ ! -d Twig ]; then - git clone https://github.com/twigphp/Twig > /dev/null -fi -GIT_SUBTREE_SPLIT_SHA1="ea449b0f2acba7d489a91f88154687250d2bdf42" -GIT_SPLITSH_SHA1=`./split --prefix=lib/ --origin=refs/tags/v1.24.1 --path=Twig --quiet --scratch` - -if [ "$GIT_SUBTREE_SPLIT_SHA1" == "$GIT_SUBTREE_SPLIT_SHA1" ]; then - echo "OK ($GIT_SUBTREE_SPLIT_SHA1 == $GIT_SUBTREE_SPLIT_SHA1)" -else - echo "OK ($GIT_SUBTREE_SPLIT_SHA1 != $GIT_SUBTREE_SPLIT_SHA1)" - exit 1 -fi - -cd ../