Pergunta

Given a number of branches, I'd like a file hierarchy that I could browse in my IDE that would show the files and folders that are associated with the branch.

There are probably some tricks and gotchas that I have to figure out, for example, is it possible to show files that have been edited within a branch, but to exclude merges of other branches?

Root Directory Structure (based on branches')

[branch]

[branch2]

[branch3]

`--[all] (symlinks to all files in one bucket)

`--[PATH\SYMLINK] (directory path + symlink)

`--[PATH\SYMLINK]

Notes:

Git: How do I list only local branches?

git for-each-ref --format='%(refname:short)' refs/heads/

Script in progress

#!/bin/bash
BRANCHDIR='/path/to/where/symlinks/go'
MASTER='master'
CODEDIR='/path/to/sourcecode'
OLDPATH=`pwd`
BRANCHDIRS=`git for-each-ref --format='%(refname:short)' refs/heads/ | xargs echo`

for i in $BRANCHDIRS;
do
BRANCHFILES=`git diff --name-only  $i $MASTER`
mkdir -p $BRANCHDIR/$i $BRANCHDIR/$i/all
for j in $BRANCHFILES;
do
mkdir -p $BRANCHDIR/$i/$(dirname $j)
ln -s $CODEDIR/$j $(basename $j) -t $BRANCHDIR/$i/$(dirname $j)

ln -s $CODEDIR/$j $(basename $j) -t $BRANCHDIR/$i/all/$(basename $j)
done
done
cd $OLDPATH
Foi útil?

Solução

You should use git-new-workdir, it is available with most git distributions - see link.

The git-new-workdir script will create a fully functional symlinked repo, where you can choose to work on a single branch. Repeat N times for N branches.

It is really advisable to use the script manually at first, but if you want to get going for an existing repo, you can automate along the lines of:

SYM_TREE_DIR=/tmp/my_git_branches
REPO=/path/to/my/repo/to/clone

mkdir -p $SYM_TREE_DIR

cd $REPO
git for-each-ref --format="%(refname)" refs/heads | \
while read entry
do
        # extract just the leaf branch name for simplicity
        # (remove the first 11 characters that correspond to "refs/heads/")
        BRANCH=${entry:11}

        # attempt to clone the repo into the SYM_TREE_DIR
        if ../git-new-workdir . $SYM_TREE_DIR/$BRANCH $BRANCH  &> /dev/null
        then
          echo Successfully created linked repo $BRANCH at $SYM_TREE_DIR/$BRANCH
        else
          echo Failed to create linked repo $BRANCH at $SYM_TREE_DIR/$BRANCH
        fi
done
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top