scripting for stgit

22 views
Skip to first unread message

nago

unread,
Aug 16, 2019, 10:18:47 AM8/16/19
to StGit (Stacked Git)
Hi, is there a "nice" way to tell if a directory I am in has an initialized stacked git instance or not?

Purpose: to augment other high-level management tools to be aware if it is in a stgit context or not "automatically", and then "do the right thing."

My best attempt so far, trying to leverage the existing error checking in stgit:

```
#!/usr/bin/env python3                                                                                                                            

try:
    import stgit.lib.stack
    USE_STGIT = True
except ModuleNotFoundError:
    USE_STGIT = False

def has_stgit_branch():
    if not USE_STGIT:
        return False

    try:
        repo = stgit.lib.stack.StackRepository.default()
        stack = repo.get_stack()
    except stgit.exception.StgException:
        return False

    return True

if __name__ == '__main__':
    print("stgit? {}".format(has_stgit_branch()))
```

Peter Grayson

unread,
Aug 19, 2019, 6:31:10 PM8/19/19
to StGit (Stacked Git)
In a shell script, you might do something like:

#/bin/sh

current
=$(git branch --show-current)
git show
-ref "$(current).stgit"

This only tells you whether the current branch is initialized, but not whether *any* branch is initialized, but it could be extended to answer that as well.

Cheers,
Pete
Reply all
Reply to author
Forward
0 new messages